Search code examples
angularjsinternationalizationangular-translate

I can't translate the title in navigation menu in my fuse theme Angularjs app


Here is the a part of code in my navigation menu:

msNavigationService.saveItem('apps.dashboard', {
        title: 'Dashboard',
        state: 'app.dashboard',
        icon: 'icon-tile-four',
        hidden: function () {
            var dashboardview = true;
            if (localStorage.getItem("DashboardStorage") === '1') { dashboardview = false; }
            else { dashboardview = true; }
            return dashboardview;
        },
        weight: 1

    });

I just want to translate the title Dashboard with angular-translate. All the configuration are okay. And here is the way I have done all the translations in controller: var customers = "Dashboard"; vm.customers = $filter('translate')(customers); So the variable in JSON named Dashboard will be translated, but the translation couldn't be done.


Solution

  • Try something like this

    var translations = {
      CUSTOMERS: 'Customers'
    };
    
    var app = angular.module('myApp', []);
    
    app.config(['$translateProvider', function ($translateProvider) {
      $translateProvider.translations('en', translations);
      $translateProvider.preferredLanguage('en');
    }]);
    
    app.controller('Ctrl', ['$scope', '$translate', function ($scope, $translate) {
       var vm = this;
       vm.customers = $translate.instant('CUSTOMERS');
    }]);