i18next / ng-i18next

translation for AngularJS using i18next
https://github.com/i18next/ng-i18next
MIT License
161 stars 54 forks source link

Can't translate when controller is on html element #26

Closed Soviut closed 10 years ago

Soviut commented 10 years ago

I've got a controller called SiteCtrl that sits on the <html> element that handles a few site-wide things.

I wanted populate the <title> tag with translated text. However using the directive creates an html element and the filter is visible as raw `{{ }} text. So, reluctantly, I decided to create a scope variable in my SiteCtrl that stores the pagetitle.

$scope.pagetitle = $i18next('ui.pagetitle');

However, this only outputs ui.pagetitle. From my experience with i18next, this means it's translating, but not finding the key. When I put this same line into another controller further down in the DOM, it works fine.

I'm guessing there's something special about the html element. Is there any way i can get this translation to work?

Soviut commented 10 years ago

I've solved the problem using the i18nextLanguageChange event:

$rootScope.$on('i18nextLanguageChange', function () {
    $scope.pagetitle = $i18next('ui.pagetitle');
});

Was I facing a race condition or was there something else preventing the translation from working?

bugwelle commented 10 years ago

Oh, I don't know. But I'm glad to see that you've solved the problem. :+1:

bugwelle commented 10 years ago

I'll close this issue now. If there are problems or question left, please comment on this issue :)

Regards, Andre