Angularjs改变语言ui-grid选项

cri*_*nqr 4 javascript angularjs angular-ui-grid

我正在使用角度ui-grid而不是ng-grid.如何将英语语言更改为网格选项的西班牙语.

cri*_*nqr 10

我找到的解决方案是在控制器或配置文件中更改服务i18nService的默认语言.如下:

在控制器上设置默认语言

var app = angular.module('moduleName');
app.controller('testController', ['i18nService', function(i18nService){
    //es is the language prefix you want
    i18nService.setCurrentLang('es');
}]);
Run Code Online (Sandbox Code Playgroud)

在配置文件中设置默认语言

var app = angular.module('moduleName');
app.config(function($provide){
    $provide.decorator('GridOptions',['$delegate', 'i18nService', function($delegate, i18nService){
        var gridOptions;
        gridOptions = angular.copy($delegate);
        gridOptions.initialize = function(options) {
            var initOptions;
            initOptions = $delegate.initialize(options);
            return initOptions;
        };
        //es is the language prefix you want
        i18nService.setCurrentLang('es');
        return gridOptions;
    }]);
});
Run Code Online (Sandbox Code Playgroud)