配置
1.安装依赖
2.在html中加载JS
3.注入依赖
angular
.module('core')
.config(translateProvider);
translateProvider.$inject = ['$translateProvider'];
function translateProvider($translateProvider) {
$translateProvider.useStaticFilesLoader({
prefix: '/api/base/web/language/',
suffix: ''
});
var preferLanguage = 'en';
$translateProvider.preferredLanguage(preferLanguage);
$translateProvider.useStorage('translateStorage');
}
4.定义translateStorage
angular
.module('core')
.factory('translateStorage', translateStorage);
translateStorage.$inject = ['$window'];
var langKey;
function translateStorage($window) {
return {
put: function (name, value) {
// store `value` under `name` somehow
langKey = value;
$window.localStorage.setItem(name, value);
},
get: function (name) {
// request value of `name` somehow
if (!langKey) {
langKey = $window.localStorage.getItem(name);
}
return langKey;
}
};
}
使用
两种使用方式:
{{ 'dashboard_personality_chart_title' | translate }}
);<h2 translate="dashboard_personality_chart_title"></h2>
)