javascript - why language is not translating in angular js -


(function() {   angular.module("metronicapp").controller("deviceviewcontroller",deviceviewcontroller)    .factory("asyncloader", asyncloader)   .config(config);     //@config   config.$inject = [ '$translateprovider' ];    function config($translateprovider) { //      $translateprovider.translations("ci", language_ci); //      $translateprovider.translations("en", language_en); //      $translateprovider.translations("hi", language_hi); //      $translateprovider.translations("sp", language_sp);       $translateprovider.preferredlanguage('en'); //      $translateprovider.translations('ci', { //          deviceid: '设备id', //          timestamp:'时间戳' //      });        $translateprovider.useloader('asyncloader');    // $translateprovider.uselocalstorage();      var langmap = {       'en_au': 'en',       'en_ca': 'en',       'en_nz': 'en',       'en_ph': 'en',       'en_uk': 'en',       'en_us': 'en',       'ja_jp': 'ja',       'en_hi': 'hi',       'en_ci': 'ci',       'en_ch': 'ci'     };      $translateprovider     .registeravailablelanguagekeys(['en', 'sp', 'hi', 'ci'], langmap)      .determinepreferredlanguage();     /*console.log($translateprovider.     .determinepreferredlanguage());*/                                 //window.navigator.languages[0]   }    // @factory   asyncloader.$inject = [ '$q', '$timeout', '$http' ];   function asyncloader($q, $timeout, $http) {      return function(options) {       var deferred = $q.defer(), translations;        var resturl = "lang"+options.key+".json";       $http.get(         resturl,{cache:false}).success(function(translations) {           deferred.resolve(translations);             //alert(translations);           }).error(function(translations) {             deferred.reject(translations);           });            $timeout(function() {             deferred.resolve(translations);           }, 2000);            return deferred.promise;         };        }    //@controller   deviceviewcontroller.$inject = [ '$translate', '$scope','$rootscope','$state'];    function deviceviewcontroller($translate, $scope,$rootscope,$state) {     $scope.defaultlanguage = true;     $scope.state= $state;             $scope.setlang = function(langkey) {           var key = localstorage.getitem("selected_language");                if (langkey === 'ci') {               alert("selected key form single device view " + langkey);               $rootscope.lang = "ci";               $scope.defaultlanguage = true;               //changelanguagefeedbackpanel(key);                 $translate.use(langkey);               //  alert("language setted");              }               if (langkey === 'en') {               alert("selected key form single device view " + langkey);               $rootscope.lang = "en";               $scope.defaultlanguage = false;               //changelanguagefeedbackpanel(key);               $translate.use(langkey);             }              if (langkey === 'hi') {               alert("selected key form single device view " + langkey);               // alert("lang key "+langkey);               $rootscope.lang = "hi";               $scope.defaultlanguage = false;               $translate.use(langkey);             }           if (langkey === 'sp') {               alert("selected key form single device view " + langkey);               $rootscope.lang = "sp";               $scope.defaultlanguage = false;              $translate.use(langkey);           } //          $translate.use(langkey);       } //      $scope.changelanguage = function(langkey) { // //          if(langkey === 'en') //          { //              $rootscope.lang= "en"; //              $scope.defaultlanguage = true; //              //changelanguagefeedbackpanel(langkey); //          } //          if(langkey === 'sp') //          { //              //alert("clicked spanish"); //              $rootscope.lang= "sp"; //              $scope.defaultlanguage = false; //              //changelanguagefeedbackpanel(langkey); //          } //          if(langkey === 'hi') //          { //              // alert("lang key "+langkey); //              $rootscope.lang= "hi"; //              $scope.defaultlanguage = false; //          } //          if(langkey === 'ci') //          { //              $rootscope.lang= "ci"; //              $scope.defaultlanguage = false; // //          } // //          $translate.use(langkey); //      }; //  //      var key= localstorage.getitem("key"); ////        $scope.setlang= function (key) { // //      if (key === 'ci') { //          alert("selected key single device view " + key); //          $rootscope.lang = "ci"; //          $scope.defaultlanguage = true; //          //changelanguagefeedbackpanel(langkey); //          $translate.use(key); //      } // //      if (key === 'en') { //          alert("selected key single device view " + key); //          $rootscope.lang = "en"; //          $scope.defaultlanguage = true; //          //changelanguagefeedbackpanel(langkey); //          $translate.use(key); //      } //      if (key === 'hi') { //          alert("selected key form single device view " + key); //          // alert("lang key "+langkey); //          $rootscope.lang = "hi"; //          $scope.defaultlanguage = true; //          $translate.use(key); // //      } //      if (key === 'sp') { //          alert("selected key form single device view " + key); //          $rootscope.lang = "sp"; //          $scope.defaultlanguage = true; //          $translate.use(key); //      }        $scope.device_data=[           {"deviceid":"temperature","timestamp":"temperature","paramname":"temperature","paramvalue":"151","paramuom":"off device"},           {"deviceid":"temperature","timestamp":"temperature","paramname":"temperature","paramvalue":"151","paramuom":"off device"},           {"deviceid":"temperature","timestamp":"temperature","paramname":"temperature","paramvalue":"151","paramuom":"off device"}       ];  //    $scope.changelanguage = function(langkey) { // //      if(langkey === 'en') //      { //        $rootscope.lang= "en"; //        $scope.defaultlanguage = true; //          //changelanguagefeedbackpanel(langkey); //        } //        if(langkey === 'sp') //        { //          //alert("clicked spanish"); //          $rootscope.lang= "sp"; //          $scope.defaultlanguage = false; //          //changelanguagefeedbackpanel(langkey); //        } //        if(langkey === 'hi') //        { //          // alert("lang key "+langkey); //           $rootscope.lang= "hi"; //           $scope.defaultlanguage = false; //        } //        if(langkey === 'ci') //        { //          $rootscope.lang= "ci"; //          $scope.defaultlanguage = false; // //        } // //        $translate.use(langkey); //      }; //       $scope.action=function()       {           alert("action clicked successfully");       }        // on click action starts here       $scope.doaction= function () {           // body perform action...            alert("action taken successfully");       } }//controller ended    })(); 

this js file. have written code single page. working fine single page when tried whole theme, not working. not able translate language.

please tell me whrer error?

 <ul class="dropdown-menu dropdown-menu-default">                     <li>                         <a href="">                         <img alt="" src="../assets/global/img/flags/ci.png"><button onclick="setlang('ci')">chinese</button>                             </a>                     </li>                     <li>                         <a href="">                  <img alt="" src="../assets/global/img/flags/us.png"><button onclick="setlang('en')">english</button>                         </a>                     </li>                      <li>                         <a href="">                         <img alt="" src="../assets/global/img/flags/hu.png"><button onclick="setlang('hi')"> hindi </button>                             </a>                     </li>                     <li>                         <a href="">                        <img alt="" src="../assets/global/img/flags/us.png"><button onclick="setlang('sp')">spanish</button>                             </a>                     </li>                 </ul>         </li>              <script type="text/javascript">                function setlang(langkey)               {                   alert("language changed " +langkey);                   localstorage.setitem("selected_language",langkey);                 } 

my work code this.

(function() {     'use strict';      angular         .module('app.translate')         .run(translaterun)       translaterun.$inject = ['$rootscope', '$translate'];     function translaterun($rootscope, $translate){       $rootscope.language = {         listisopen: false,         available: {           'en': 'english',           'es': 'español',           'de': 'deutsch',           'fr': 'français',           'ru': 'Русский',           'ua': 'Українська'         },         init: function () {           var proposedlanguage = $translate.proposedlanguage() || $translate.use();           var preferredlanguage = $translate.preferredlanguage();           $rootscope.language.selected = $rootscope.language.available[ (proposedlanguage || preferredlanguage) ];         },         set: function (localeid) {           $translate.use(localeid);           $rootscope.language.selected = $rootscope.language.available[localeid];           $rootscope.language.listisopen = ! $rootscope.language.listisopen;         }       };       $rootscope.language.init();      } })(); 

html content:

<li class="menumain" is-open="language.listisopen">     <a class="">       <em class="fa-globe fa fa-2x"></em>     </a>  <ul role="menu" class="menumain-sub">     <li ng-repeat="(localeid, langname) in language.available">         <a ng-click="language.set(localeid, $event)" href="#">{{langname}}</a>     </li>  </ul> </li> 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -