ilib
Version:
iLib is a cross-engine library of internationalization (i18n) classes written in pure JS
1 lines • 6.04 kB
JavaScript
var ilib=ilib||{};ilib._ver=function(){return"11.0.006"};ilib.getVersion=function(){return ilib._ver()||"11.0"};ilib.data={norm:{ccc:{},nfd:{},nfc:{},nfkd:{},nfkc:{}},zoneinfo:{"Etc/UTC":{o:"0:0",f:"UTC"},local:{f:"local"}},ctype:null,ctype_c:null,ctype_l:null,ctype_m:null,ctype_p:null,ctype_z:null,scriptToRange:null,dateformats:null,timezones:[]};if(typeof module!=="undefined"){module.exports=ilib;module.exports.ilib=ilib}ilib.setAsPseudoLocale=function(e){if(e){ilib.pseudoLocales.push(e)}};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(typeof java.lang.Object!=="undefined"){ilib._platform=typeof process!=="undefined"?"trireme":"rhino";return ilib._platform}}catch(e){}if(typeof process!=="undefined"&&typeof module!=="undefined"){ilib._platform="nodejs"}else if(typeof Qt!=="undefined"){ilib._platform="qt"}else if(typeof window!=="undefined"){ilib._platform=typeof PalmSystem!=="undefined"?"webos":"browser"}else{ilib._platform="unknown"}}return ilib._platform};ilib._getBrowser=function(){var e=undefined;if(ilib._getPlatform()==="browser"){if(navigator&&navigator.userAgent){if(navigator.userAgent.indexOf("Firefox")>-1){e="firefox"}if(navigator.userAgent.indexOf("Opera")>-1){e="opera"}if(navigator.userAgent.indexOf("Chrome")>-1){e="chrome"}if(navigator.userAgent.indexOf(" .NET")>-1){e="ie"}if(navigator.userAgent.indexOf("Safari")>-1){e="safari"}}}return e};ilib._isGlobal=function(e){switch(ilib._getPlatform()){case"rhino":var i=function(){return typeof global==="object"?global:this}();return typeof i[e]!=="undefined";case"nodejs":case"trireme":var n=typeof global!=="undefined"?global:this;return n&&typeof n[e]!=="undefined";case"qt":return false;default:try{return window&&typeof window[e]!=="undefined"}catch(t){return false}}};ilib.setLocale=function(e){if(typeof e==="string"||!e){ilib.locale=e}};ilib.getLocale=function(){if(typeof ilib.locale!=="string"){var e=ilib._getPlatform();switch(e){case"browser":ilib.locale=navigator.language.substring(0,3)+navigator.language.substring(3,5).toUpperCase();if(!ilib.locale){var i=typeof navigator.browserLanguage!=="undefined"?navigator.browserLanguage:typeof navigator.userLanguage!=="undefined"?navigator.userLanguage:typeof navigator.systemLanguage!=="undefined"?navigator.systemLanguage:undefined;if(typeof i!=="undefined"&&i){ilib.locale=i.substring(0,3)+i.substring(3,5).toUpperCase()}}break;case"webos":if(typeof PalmSystem.locales!=="undefined"&&typeof PalmSystem.locales.UI!="undefined"&&PalmSystem.locales.UI.length>0){ilib.locale=PalmSystem.locales.UI}else if(typeof PalmSystem.locale!=="undefined"){ilib.locale=PalmSystem.locale}break;case"rhino":if(typeof environment!=="undefined"&&environment.user&&typeof environment.user.language==="string"&&environment.user.language.length>0){ilib.locale=environment.user.language;if(typeof environment.user.country==="string"&&environment.user.country.length>0){ilib.locale+="-"+environment.user.country}}break;case"trireme":var i=process.env.LANG||process.env.LANGUAGE||process.env.LC_ALL;if(i&&typeof i!=="undefined"){ilib.locale=i.substring(0,2).toLowerCase()+"-"+i.substring(3,5).toUpperCase()}break;case"nodejs":var i=process.env.LANG||process.env.LC_ALL;if(i&&typeof i!=="undefined"){ilib.locale=i.substring(0,2).toLowerCase()+"-"+i.substring(3,5).toUpperCase()}break;case"qt":var n=Qt.locale();var i=n.name&&n.name.replace("_","-")||"en-US";break}ilib.locale=typeof ilib.locale==="string"?ilib.locale:"en-US"}return ilib.locale};ilib.setTimeZone=function(e){ilib.tz=e||ilib.tz};ilib.getTimeZone=function(){if(typeof ilib.tz==="undefined"){if(typeof navigator!=="undefined"&&typeof navigator.timezone!=="undefined"){if(navigator.timezone.length>0){ilib.tz=navigator.timezone}}else if(typeof PalmSystem!=="undefined"&&typeof PalmSystem.timezone!=="undefined"){if(PalmSystem.timezone.length>0){ilib.tz=PalmSystem.timezone}}else if(typeof environment!=="undefined"&&typeof environment.user!=="undefined"){if(typeof environment.user.timezone!=="undefined"&&environment.user.timezone.length>0){ilib.tz=environment.user.timezone}}else if(typeof process!=="undefined"&&typeof process.env!=="undefined"){if(process.env.TZ&&typeof process.env.TZ!=="undefined"){ilib.tz=process.env.TZ}}ilib.tz=ilib.tz||"local"}return ilib.tz};ilib.Loader=function(){};ilib.Loader.prototype.loadFiles=function(e,i,n,t){};ilib.Loader.prototype.listAvailableFiles=function(){};ilib.Loader.prototype.isAvailable=function(e){};ilib.setLoaderCallback=function(e){if(typeof e==="object"&&typeof e.loadFiles==="function"||typeof e==="function"||typeof e==="undefined"){ilib._load=e;return true}return false};ilib.getLoader=function(){return ilib._load};ilib.isArray=function(e){var i;if(typeof e==="object"){i=e;return Object.prototype.toString.call(i)==="[object Array]"}return false};ilib.extend=function(e,i){var n=undefined;if(i){for(n in i){if(n&&typeof i[n]!=="undefined"&&typeof i[n]!=="function"){if(ilib.isArray(e[n])&&ilib.isArray(i[n])){e[n]=e[n].concat(i[n])}else if(typeof e[n]==="object"&&typeof i[n]==="object"){if(n!=="ilib"){e[n]=ilib.extend(e[n],i[n])}}else{e[n]=i[n]}}}}return e};ilib.extend2=function(e,i){var n=undefined;if(i){for(n in i){if(n&&typeof i[n]!=="undefined"){if(ilib.isArray(e[n])&&ilib.isArray(i[n])){e[n]=e[n].concat(i[n])}else if(typeof e[n]==="object"&&typeof i[n]==="object"){if(n!=="ilib"){e[n]=ilib.extend2(e[n],i[n])}}else{e[n]=i[n]}}}}return e};ilib.bind=function(e,i){if(!e||!i){return undefined}function n(e,i){var n=[];for(var t=i||0,o=e.length;t<o;t++){n.push(e[t])}return n}if(typeof i==="function"){var t,o=n(arguments,2);if(typeof i.bind==="function"){t=i.bind.apply(i,[e].concat(o))}else{t=function(){var t=n(arguments);return i.apply(e,o.concat(t))}}return t}return undefined};ilib._dyncode=false;ilib.isDynCode=function(){return ilib._dyncode};ilib._dyndata=false;ilib.isDynData=function(){return ilib._dyndata};ilib._loadtime=(new Date).getTime();