I'm trying to make simple multi-language website. I have a small controller just to be able to change current language in root scope:
app.controller('Ctrl', function($scope, $rootScope) { $rootScope.currentLang = 'en_US'; $scope.switchLang = function(){ if($rootScope.currentLang ==='en_US'){ $rootScope.currentLang = 'cs_CS'; } else { $rootScope.currentLang = 'en_US'; } } }); And I want to store my data in filter:
app.filter('ci18n', function($rootScope){ return function(id_text){ var translations = { 'en_US' : { 'GREETING' : 'Hi' }, 'cs_CS' : { 'GREETING' : 'Cau' } }; return translations[$rootScope.currentLang][id_text]; }; }); Problem is that my website does't change with rootScope change. I need an idea how to solve it better or how to trigger filter again to change my texts.
Here is how I use the filter
<p>greet: {{'GREETING' | ci18n}}</p>
$scope.$apply();?