UNPKG

ilib

Version:

iLib is a cross-engine library of internationalization (i18n) classes written in pure JS

1 lines 7.47 kB
var ilib=ilib||{};function parseLocale(str){var parts,dot;return str&&("C"===(str=-1<(dot=str.indexOf("."))?str.substring(0,dot):str)?"en-US":(dot=[],0<(parts=str.replace(/_/g,"-").split(/-/g)).length&&(2!==parts[0].length&&3!==parts[0].length||(dot.push(parts[0].toLowerCase()),1<parts.length&&(4===parts[1].length?dot.push(parts[1][0].toUpperCase()+parts[1].substring(1).toLowerCase()):2!==parts[1].length&&3!=parts[1].length||dot.push(parts[1].toUpperCase()),2<parts.length)&&(2!==parts[2].length&&3!=parts[2].length||dot.push(parts[2].toUpperCase())))),dot.join("-")))}ilib._ver=function(){return"14.21.2"},ilib.getVersion=function(){if(ilib._dyncode)try{return require("../package.json").version}catch(e){}return ilib._ver()||"14.0"},ilib.getCLDRVersion=function(){return"46.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||void 0!==global.process.iotjs)?ilib._platform="nodejs":"undefined"!=typeof Qt?(ilib._platform="qt",ilib._cacheMerged=!0):"undefined"!=typeof PalmSystem||"undefined"!=typeof webOSSystem?ilib._platform="undefined"!=typeof window?"webos-webapp":"webos":"undefined"!=typeof window?ilib._platform="browser":ilib._platform="unknown"}return ilib._platform},ilib._getBrowser=function(){if("browser"===ilib._getPlatform()&&navigator&&navigator.userAgent){if(-1<navigator.userAgent.indexOf("Firefox"))return"firefox";if(-1<navigator.userAgent.search(/Opera|OPR/))return"opera";if(-1<navigator.userAgent.indexOf("Chrome"))return"chrome";if(-1<navigator.userAgent.indexOf(" .NET"))return"ie";if(-1<navigator.userAgent.indexOf("Safari"))return"safari";if(-1<navigator.userAgent.indexOf("Edge"))return"Edge";if(-1<navigator.userAgent.search(/iPad|iPhone|iPod/))return"iOS"}return"unknown"},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){}},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(){var lang;if("string"!=typeof ilib.locale){switch(ilib._getPlatform()){case"browser":void 0!==navigator.language&&(ilib.locale=parseLocale(navigator.language)),ilib.locale||(lang=void 0!==navigator.browserLanguage?navigator.browserLanguage:void 0!==navigator.userLanguage?navigator.userLanguage:void 0!==navigator.systemLanguage?navigator.systemLanguage:void 0,ilib.locale=void 0!==lang&&lang?parseLocale(lang):void 0);break;case"webos-webapp":case"webos":void 0!==PalmSystem.locales&&void 0!==PalmSystem.locales.UI&&0<PalmSystem.locales.UI.length?ilib.locale=parseLocale(PalmSystem.locales.UI):void 0!==PalmSystem.locale?ilib.locale=parseLocale(PalmSystem.locale):void 0!==webOSSystem.locale?ilib.locale=parseLocale(webOSSystem.locale):ilib.locale=void 0;break;case"rhino":"undefined"!=typeof environment&&environment.user&&"string"==typeof environment.user.language&&0<environment.user.language.length&&(l=[environment.user.language],"string"==typeof environment.user.country&&0<environment.user.country.length&&l.push(environment.user.country),ilib.locale=l.join("-"));break;case"trireme":lang=process.env.LANG||process.env.LANGUAGE||process.env.LC_ALL,ilib.locale=parseLocale(lang);break;case"nodejs":lang=global.process.env.LANG||global.process.env.LC_ALL,ilib.locale=parseLocale(lang);break;case"qt":var l=Qt.locale();ilib.locale=parseLocale(l.name||"en-US")}ilib.locale="string"==typeof ilib.locale&&ilib.locale.length&&"C"!==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){var ro;if("undefined"!=typeof Intl&&void 0!==Intl.DateTimeFormat)return ro=(new Intl.DateTimeFormat).resolvedOptions(),ilib.tz=ro&&ro.timeZone,ilib.tz;switch(ilib._getPlatform()){case"browser":navigator.timezone&&0<navigator.timezone.length&&(ilib.tz=navigator.timezone);break;case"webos-webapp":case"webos":(PalmSystem.timezone&&0<PalmSystem.timezone.length||webOSSystem.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){var args;return scope&&method&&"function"==typeof method?(args=cloneArray(arguments,2),"function"==typeof method.bind?method.bind.apply(method,[scope].concat(args)):function(){var nargs=cloneArray(arguments);return method.apply(scope,args.concat(nargs))}):void 0;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._cacheMerged=!1,ilib._loadtime=(new Date).getTime();