skip to Main Content

I´m using angular-translate $translate service to translate the title and meta description tags content dinamically according to the page (for SEO purposes).

I have a function that is called when a select combobox component with the language changes:

$scope.changeLanguage = function (langKey) {
            $scope.langKey = langKey;
            $translate.uses(langKey);
            $rootScope.title = $translate('PAGE_TITLE');

            tmhDynamicLocale.set(langKey).then(function (){
                LocationService.setLangKey($scope.langKey);                     
                $window.moment.lang(langKey);    
            });
        };

All my application content is translated but the title.

My application default language is english. When I change to spanish (for first time) it´s not translating. After that, if I change to english and then to spanish again it works. All next times will work.

2

Answers


  1. Chosen as BEST ANSWER

    I think I have fixed it this way:

    $translate.uses(langKey).then(function() {
         $rootScope.title = $translate('PAGE_TITLE');
    });
    

  2. the translate service returns a promise

    $translate('PAGE_TITLE').then(function(result) {
        $rootScope.title = result
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search