123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- (function () {
- //** */辨别移动终端类型
- var Terminal = {
- platform: function () {
- var u = navigator.userAgent,
- app = navigator.appVersion;
- return {
- //IE内核
- windows: u.indexOf('Windows') > -1,
- //opera内核
- presto: u.indexOf('Presto') > -1,
- //苹果、谷歌内核
- webKit: u.indexOf('AppleWebKit') > -1,
- //火狐内核
- gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1,
- //是否为移动终端
- mobile: !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/),
- //ios终端
- ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
- //android终端或者uc浏览器
- android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1,
- //是否iPad
- iPad: u.indexOf('iPad') > -1,
- //是否为iPhone或者QQHD浏览器
- iPhone: u.indexOf('iPhone') > -1,
- //是否为mac系统
- Mac: u.indexOf('Macintosh') > -1,
- //是否web应该程序,没有头部与底部
- webApp: u.indexOf('Safari') == -1
- };
- }(),
- // 辨别移动终端的语言:zh-cn、en-us、ko-kr、ja-jp...
- language: (navigator.browserLanguage || navigator.language).toLowerCase(),
- init: function () {
- var sysName;
- var lagName;
- if (Terminal.platform.android) {
- sysName = "android";
- } else if (Terminal.platform.iPhone) {
- sysName = "iPhone";
- } else if (Terminal.platform.iPad) {
- sysName = "iPad";
- } else if (Terminal.platform.windows) {
- sysName = "windows";
- } else if (Terminal.platform.Mac) {
- sysName = "Mac";
- } else if (Terminal.platform.gecko) {
- sysName = "fireFox";
- } else if (Terminal.platform.mobile) {
- sysName = "mobile";
- } else {
- sysName = "unknown";
- }
- switch (Terminal.language) {
- case 'en':
- lagName = "en";
- break;
- default:
- lagName = "zh_CN";
- }
- return {
- sysName:sysName,
- lagName:lagName
- }
- }
- }
- if(!localStorage.getItem("lag")){
- localStorage.setItem("lag", Terminal.init().lagName);
- }
-
- var plgLanguage = {
- debug: false,
- ns: ['translation','message'],
- lng:localStorage.getItem("lag"),
- fallbackLng:"zh_CN",
- defaultNS:'translation',
- backend: {
- loadPath: '/ops/javascripts/language/{{lng}}/{{ns}}.json',
- crossDomain: false
- },
- missingInterpolationHandler:function(text, value){
- // console.log(text)
- // console.log(value)
- },
- parseMissingKeyHandler:function(key){
- // console.log(key)
- if(key.indexOf(".") ==-1){
- return key;
- }
- var nk = key.substr(key.lastIndexOf(".")+1);
- if(i18next.exists(nk)){
- return i18next.t(nk);
- }
- return nk;
- }
- }
-
- jqueryI18next.init(i18next, $);
- i18next
- .use(i18nextXHRBackend)
- .use(i18nextBrowserLanguageDetector)
- .init(plgLanguage,function () {
- console.log(i18next);
- //updateContent()
- });
- function updateContent() {
- $(function () {
- //版本号version
- $('[name="plg-version"]').append("-v");
- $(document).localize();
- })
- }
- i18next.on('languageChanged', function () {
- //Object.getOwnPropertyNames(vipspa).length > 0 && vipspa.reset()
- updateContent();
- //console.log(i18next.getFixedT(i18next.language)("提示"))
- });
- })()
|