Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect when language changes?

I'm using angular-translate to provide dynamic language support for my app. I am also using a calendar component (http://angular-ui.github.io/ui-calendar/) which doesn't play that well with angular (jQuery roots). To be able to translate it at run time I need to detect when language changes.

Basically I need to know when $translate.use() has been called and the language has been changed.

Is there a way to detect when the language changes so that I can trigger the translations for the calendar component?

like image 242
Markus Johansson Avatar asked Jun 13 '14 07:06

Markus Johansson


2 Answers

This is how I solved it:

    $rootScope.$on('$translateChangeSuccess', function(event, current, previous) {
        // Language has changed
    });
like image 179
Markus Johansson Avatar answered Nov 16 '22 12:11

Markus Johansson


Another answer :

$scope.$watch("$parent.currentLanguage", function(newValue, oldValue) {
  // Do whatever you want
});
like image 1
annelhote Avatar answered Nov 16 '22 14:11

annelhote