mg_dev
mg_dev

Reputation: 1403

Auto populate the i18n language in ng-grid - AngularJS

I have an application that uses localization(i18n) - AngularJS.

I have used a simple ng-grid from here-

https://github.com/angular-ui/ng-grid/wiki/Configuration-Options

Code:

$scope.gridOptions = {
data: 'filteredData',
enablePaging: true, 
enableColumnResize: true,
multiSelect: false,
virtualizationThreshold: 20,
enableRowSelection: true,
columnDefs: 'columnDefs1',
i18n: $rootScope.myLangVariable,
};

Problem:
I want to reinitialize the grid on language change and display all the column header + the static data in the selected language.

Things I have tried:
I have applied watch on the language variable and on its change I have called a function which will fire $scope.gridOptions. But this is not working.
All the data on the page is changed (respective of the selected language) except of that ng-grid.

I am sure this issue would have come to many of the developers here. Please help! Let me know you if need more clarification.

Thanks in advance.

Upvotes: 2

Views: 2680

Answers (2)

dpineda
dpineda

Reputation: 2448

for the people who don't need to refresh the language and just want to to using i18nService through the whole app

app.run(['i18nService', function (i18nService) {
  i18nService.setCurrentLang('es');
}]);

Upvotes: 0

ytll21
ytll21

Reputation: 860

You can try the latest ui-grid(ng-grid), then add the blow code:

function ($scope, i18nService) {
    i18nService.setCurrentLang('zh-cn');
}

Upvotes: 2

Related Questions