I want to Access enTranslations provided in one JS File as shown Below, But I am not Able to access it

praxnet

As You can see in my HTML I want to take my Data according to my current locale, and I have custom translation file enTranslation, which is given.

PROBLEM :

I am not able to see the values on browser page, when I am using {{ translations[key] }} OR {{ translation.key }}

Please HELP me understand what is needed to be done to make this work.

I have 3 files in js Directory, Given Code Below:

  1. enTranslations.js
  2. prax_controller.js
  3. angular_1.4.2.min.js

My HTML file

<!DOCTYPE html>
<html>
<head>
<script src="js/angular_1.4.2.min.js"></script>
<script src="js/prax_controller.js"></script>
<script src="js/enTranslations.js"></script>
<meta charset="UTF-8">
<title>Prax Local</title>
</head>

<body ng-app="prxApp" ng-controller="prxController">
    <div>
    List
        <ul class="d1" ng-repeat="(key, value) in eventHistories">
            <li class="d1k">
                <!--  {{ translations.key }}: {{ value }}% -->
                {{ translations[key] }}  :  {{ value }}%
            </li>
        </ul>
    </div>
    </body>
</html>

1. enTranslations.js

var translations = {
    "Device Status":'Device Status',
    "Device Temperature":'Device Temperature',
};

2. prax_controller.js

var prxApp = angular.module('prxApp', []);
prxApp.controller('prxController', ['$scope', function($scope) {
$scope.init = function() 
{
    $scope.eventHistories = {
            "Device Status":0,
            "Device Temperature":0,
        };
};

$scope.init();
}]);

3. Angular.min.js

https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.3/angular.min.js

Ehtesham

you can attach the translations on the $rootScope then you will be able to get the object in any template. A rough picture that comes in mind according to your requirement could be this.

put this somewhere in your main angular bootstrapping module's run method or you can put it in resolve method of your first controller.

angular.module('app').config(function () {
})
.run(function ($rootScope, $state, $stateParams, $http) {
    // Get language based on browser settings
    var lang  = navigator.language;

    // fetch translations from server
    $http.get('URL_TO_FETCH_TRANSLATION/' + lang)
    .success(function (data) {
        $rootScope.translations = data;
    });
});

In any of your template.

<li class="d1k" ng-repeat="(key, value) in eventHistories">
        {{ translations[key] }}  :  {{ value }}
</li>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

I have one menu and sub menu's but I am not able to access sub menu but i want to access sub menu for appropriate menu

From Dev

NodeJS - Not being able to access the route I want

From Dev

I want to be able to access data from ci.median

From Dev

In angular using ionic want to make a loginapp in which i am not able to access $stateprovider routing for login page using <ion-nav-view>

From Dev

How am I able to access private data members of a class?

From Dev

I am not able to access Root's home folder in Ubuntu

From Dev

How am I able to access the Firebase variable AcX in my user?

From Dev

Why I am not able to access string individual chars using index

From Dev

I am not able to access Root's home folder in Ubuntu

From Dev

After running node server i am not able to access it

From Dev

Why am I not able to access the result of multiple networking calls?

From Dev

Why am I not able to access CSS properties with JavaScript?

From Dev

Why I am not able to access xamarin elements in code behind in Forms

From Dev

I am able to access /dev/ttyS0 device file in two different processes at same time. Why?

From Dev

I am able to access /dev/ttyS0 device file in two different processes at same time. Why?

From Dev

i want the the text to be shown besides the icon image and not below it

From Dev

I am wondering why I cannot override jquery function onRegionOver. The WAMP index.html file is shown below

From Dev

I want to connect to an access database

From Dev

I want to access the SSH on my college's LAN but right now I am at home so I am not connected to its network

From Dev

I want to access the SSH on my college's LAN but right now I am at home so I am not connected to its network

From Dev

I am not able to get the file path

From Dev

Why am I able to open this file?

From Dev

Why am I not able to access the internet even though IPv4 address has been allotted by ISP?

From Dev

why I am not able to access rails localhost on my mobile or other computer

From Dev

Javascript: Why am I able to access Function.prototype.call without mentioning the prototype?

From Dev

I am not able to access UID in firebase on other HTML pages than login page

From Dev

Why am I not able to access the internet even though IPv4 address has been allotted by ISP?

From Dev

I want my users to only access my php files, if they try to access the folders I want to include my page 404 file

From Dev

I want to create a user in Pagerduty using Node js. But I am not able to do. Can someone help me in this?

Related Related

  1. 1

    I have one menu and sub menu's but I am not able to access sub menu but i want to access sub menu for appropriate menu

  2. 2

    NodeJS - Not being able to access the route I want

  3. 3

    I want to be able to access data from ci.median

  4. 4

    In angular using ionic want to make a loginapp in which i am not able to access $stateprovider routing for login page using <ion-nav-view>

  5. 5

    How am I able to access private data members of a class?

  6. 6

    I am not able to access Root's home folder in Ubuntu

  7. 7

    How am I able to access the Firebase variable AcX in my user?

  8. 8

    Why I am not able to access string individual chars using index

  9. 9

    I am not able to access Root's home folder in Ubuntu

  10. 10

    After running node server i am not able to access it

  11. 11

    Why am I not able to access the result of multiple networking calls?

  12. 12

    Why am I not able to access CSS properties with JavaScript?

  13. 13

    Why I am not able to access xamarin elements in code behind in Forms

  14. 14

    I am able to access /dev/ttyS0 device file in two different processes at same time. Why?

  15. 15

    I am able to access /dev/ttyS0 device file in two different processes at same time. Why?

  16. 16

    i want the the text to be shown besides the icon image and not below it

  17. 17

    I am wondering why I cannot override jquery function onRegionOver. The WAMP index.html file is shown below

  18. 18

    I want to connect to an access database

  19. 19

    I want to access the SSH on my college's LAN but right now I am at home so I am not connected to its network

  20. 20

    I want to access the SSH on my college's LAN but right now I am at home so I am not connected to its network

  21. 21

    I am not able to get the file path

  22. 22

    Why am I able to open this file?

  23. 23

    Why am I not able to access the internet even though IPv4 address has been allotted by ISP?

  24. 24

    why I am not able to access rails localhost on my mobile or other computer

  25. 25

    Javascript: Why am I able to access Function.prototype.call without mentioning the prototype?

  26. 26

    I am not able to access UID in firebase on other HTML pages than login page

  27. 27

    Why am I not able to access the internet even though IPv4 address has been allotted by ISP?

  28. 28

    I want my users to only access my php files, if they try to access the folders I want to include my page 404 file

  29. 29

    I want to create a user in Pagerduty using Node js. But I am not able to do. Can someone help me in this?

HotTag

Archive