ilib
Version:
iLib is a cross-engine library of internationalization (i18n) classes written in pure JS
1 lines • 6.71 kB
JavaScript
var ilib=ilib||{};ilib._ver=function(){return"14.0.0"},ilib.getVersion=function(){if(ilib._dyncode)try{return require("../package.json").version}catch(e){}return ilib._ver()||"14.0"},ilib.data={norm:{ccc:{},nfd:{},nfc:{},nfkd:{},nfkc:{}},zoneinfo:{"Etc/UTC":{o:"0:0",f:"UTC"},local:{f:"local"}},charmaps:{},ctype:null,ctype_c:null,ctype_l:null,ctype_m:null,ctype_p:null,ctype_z:null,scriptToRange:null,dateformats:null,timezones:[],cache:{}},"undefined"!=typeof module&&(module.exports=ilib,module.exports.ilib=ilib),ilib.setAsPseudoLocale=function(localename){localename&&ilib.pseudoLocales.push(localename)},ilib.clearPseudoLocales=function(){ilib.pseudoLocales=["zxx-XX","zxx-Cyrl-XX","zxx-Hans-XX","zxx-Hebr-XX"]},ilib.clearPseudoLocales(),ilib._getPlatform=function(){if(!ilib._platform){try{if(void 0!==java.lang.Object)return ilib._platform="undefined"!=typeof process?"trireme":"rhino",ilib._platform}catch(e){}"undefined"!=typeof global&&global.process&&global.process.versions&&global.process.versions.node&&"undefined"!=typeof module?ilib._platform="nodejs":"undefined"!=typeof Qt?ilib._platform="qt":"undefined"!=typeof window?ilib._platform="undefined"!=typeof PalmSystem?"webos":"browser":ilib._platform="unknown"}return ilib._platform},ilib._getBrowser=function(){var browser=void 0;return"browser"===ilib._getPlatform()&&navigator&&navigator.userAgent&&(-1<navigator.userAgent.indexOf("Firefox")&&(browser="firefox"),-1<navigator.userAgent.search(/Opera|OPR/)&&(browser="opera"),-1<navigator.userAgent.indexOf("Chrome")&&(browser="chrome"),-1<navigator.userAgent.indexOf(" .NET")&&(browser="ie"),-1<navigator.userAgent.indexOf("Safari")&&(browser="safari"),-1<navigator.userAgent.indexOf("Edge")&&(browser="Edge"),-1<navigator.userAgent.search(/iPad|iPhone|iPod/)&&(browser="iOS")),browser},ilib._top=function(){if(void 0===this.top)switch(this.top=null,ilib._getPlatform()){case"rhino":this.top=function(){return"object"==typeof global?global:this}();break;case"nodejs":case"trireme":this.top="undefined"!=typeof global?global:this;break;default:this.top=window}return this.top||void 0},ilib._global=function(name){var top=this._top();try{return top[name]}catch(e){return}},ilib._isGlobal=function(name){return void 0!==ilib._global(name)},ilib.clearCache=function(){ilib.data.cache={}},ilib.setLocale=function(spec){"string"!=typeof spec&&spec||(ilib.locale=spec)},ilib.getLocale=function(){if("string"!=typeof ilib.locale){switch(ilib._getPlatform()){case"browser":void 0!==navigator.language&&(ilib.locale=navigator.language.substring(0,3)+navigator.language.substring(3,5).toUpperCase()),ilib.locale||void 0!==(lang=void 0!==navigator.browserLanguage?navigator.browserLanguage:void 0!==navigator.userLanguage?navigator.userLanguage:void 0!==navigator.systemLanguage?navigator.systemLanguage:void 0)&&lang&&(ilib.locale=lang.substring(0,3)+lang.substring(3,5).toUpperCase());break;case"webos":void 0!==PalmSystem.locales&&void 0!==PalmSystem.locales.UI&&0<PalmSystem.locales.UI.length?ilib.locale=PalmSystem.locales.UI:void 0!==PalmSystem.locale&&(ilib.locale=PalmSystem.locale);break;case"rhino":"undefined"!=typeof environment&&environment.user&&"string"==typeof environment.user.language&&0<environment.user.language.length&&(ilib.locale=environment.user.language,"string"==typeof environment.user.country&&0<environment.user.country.length&&(ilib.locale+="-"+environment.user.country));break;case"trireme":(lang=process.env.LANG||process.env.LANGUAGE||process.env.LC_ALL)&&void 0!==lang&&(ilib.locale=lang.substring(0,2).toLowerCase()+"-"+lang.substring(3,5).toUpperCase());break;case"nodejs":(lang=global.process.env.LANG||global.process.env.LC_ALL)&&void 0!==lang&&(ilib.locale=lang.substring(0,2).toLowerCase()+"-"+lang.substring(3,5).toUpperCase());break;case"qt":var locobj=Qt.locale(),lang=locobj.name&&locobj.name.replace("_","-")||"en-US"}ilib.locale="string"==typeof ilib.locale&&ilib.locale?ilib.locale:"en-US","en"===ilib.locale&&(ilib.locale="en-US")}return ilib.locale},ilib.setTimeZone=function(tz){ilib.tz=tz||ilib.tz},ilib.getTimeZone=function(){if(void 0===ilib.tz){if("undefined"!=typeof Intl&&void 0!==Intl.DateTimeFormat){var ro=(new Intl.DateTimeFormat).resolvedOptions();ilib.tz=ro&&ro.timeZone}switch(ilib._getPlatform()){case"browser":navigator.timezone&&0<navigator.timezone.length&&(ilib.tz=navigator.timezone);break;case"webos":PalmSystem.timezone&&0<PalmSystem.timezone.length&&(ilib.tz=PalmSystem.timezone);break;case"rhino":void 0!==environment.user.timezone&&0<environment.user.timezone.length&&(ilib.tz=environment.user.timezone);break;case"nodejs":global.process.env&&void 0!==global.process.env.TZ&&(ilib.tz=global.process.env.TZ)}ilib.tz=ilib.tz||"local"}return ilib.tz},ilib.Loader=function(){},ilib.Loader.prototype.loadFiles=function(paths,sync,params,callback){},ilib.Loader.prototype.listAvailableFiles=function(){},ilib.Loader.prototype.isAvailable=function(path){},ilib.setLoaderCallback=function(loader){return("object"==typeof loader&&"function"==typeof loader.loadFiles||"function"==typeof loader||void 0===loader)&&(ilib._load=loader,!0)},ilib.getLoader=function(){return ilib._load},ilib.isArray=function(object){return"object"==typeof object&&"[object Array]"===Object.prototype.toString.call(object)},ilib.extend=function(object1,object2){var prop=void 0;if(object2)for(prop in object2)prop&&void 0!==object2[prop]&&"function"!=typeof object2[prop]&&(ilib.isArray(object1[prop])&&ilib.isArray(object2[prop])?object1[prop]=object1[prop].concat(object2[prop]):"object"==typeof object1[prop]&&"object"==typeof object2[prop]?"ilib"!==prop&&(object1[prop]=ilib.extend(object1[prop],object2[prop])):object1[prop]=object2[prop]);return object1},ilib.extend2=function(object1,object2){var prop=void 0;if(object2)for(prop in object2)prop&&void 0!==object2[prop]&&(ilib.isArray(object1[prop])&&ilib.isArray(object2[prop])?object1[prop]=object1[prop].concat(object2[prop]):"object"==typeof object1[prop]&&"object"==typeof object2[prop]?"ilib"!==prop&&(object1[prop]=ilib.extend2(object1[prop],object2[prop])):object1[prop]=object2[prop]);return object1},ilib.bind=function(scope,method){if(scope&&method&&"function"==typeof method){var args=cloneArray(arguments,2);return"function"==typeof method.bind?method.bind.apply(method,[scope].concat(args)):function(){var nargs=cloneArray(arguments);return method.apply(scope,args.concat(nargs))}}function cloneArray(inArrayLike,inOffset){for(var arr=[],i=inOffset||0,l=inArrayLike.length;i<l;i++)arr.push(inArrayLike[i]);return arr}},ilib._dyncode=!1,ilib.isDynCode=function(){return ilib._dyncode},ilib._dyndata=!1,ilib.isDynData=function(){return ilib._dyndata},ilib._loadtime=(new Date).getTime();