var myApp = angular.module('myApp', [ 'pascalprecht.translate']);
myApp.config(['$translateProvider', function ( $translateProvider) {
// 从cookie里获取 lang function getCookie(name){ var strcookie = document.cookie;//获取cookie字符串 var arrcookie = strcookie.split("; ");//分割 for ( var i = 0; i < arrcookie.length; i++) { var arr = arrcookie[i].split("="); if (arr[0] == name){ return arr[1]; } } return ""; }
var lang = getCookie('language'); $translateProvider.useStaticFilesLoader({ prefix: '/i18n/', suffix: '.json' }); // 加载本地多语言配置文件 $translateProvider.useStaticFilesLoader({ prefix: './i18n/', suffix: '.json' });
$translateProvider.preferredLanguage(lang);
创建过滤器做html内容国际化
1 2 3 4 5 6 7
.filter('translate', ['$translate', function ($translate) { return function (key) { if (key) { return $translate.instant(key); } } }])