UNPKG

ilib

Version:

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

1 lines 3.96 kB
var ilib=require("./ilib.js");var Utils=require("./Utils.js");var Locale=require("./Locale.js");var LocaleInfo=function(t,n){var e=true,i=undefined;this.info=LocaleInfo.defaultInfo;switch(typeof t){case"string":this.locale=new Locale(t);break;default:case"undefined":this.locale=new Locale;break;case"object":this.locale=t;break}if(n){if(typeof n.sync!=="undefined"){e=n.sync==true}if(typeof n.loadParams!=="undefined"){i=n.loadParams}}if(!LocaleInfo.cache){LocaleInfo.cache={}}Utils.loadData({object:LocaleInfo,locale:this.locale,name:"localeinfo.json",sync:e,loadParams:i,callback:ilib.bind(this,function(t){if(!t){t=LocaleInfo.defaultInfo;var e=this.locale.getSpec().replace(/-/g,"_");LocaleInfo.cache[e]=t}this.info=t;if(n&&typeof n.onLoad==="function"){n.onLoad(this)}})})};LocaleInfo.defaultInfo=ilib.data.localeinfo;LocaleInfo.defaultInfo=LocaleInfo.defaultInfo||{scripts:["Latn"],timezone:"Etc/UTC",units:"metric",calendar:"gregorian",clock:"24",currency:"USD",firstDayOfWeek:1,meridiems:"gregorian",numfmt:{currencyFormats:{common:"{s}{n}",commonNegative:"{s}-{n}",iso:"{s}{n}",isoNegative:"{s}-{n}"},script:"Latn",decimalChar:",",groupChar:".",prigroupSize:3,secgroupSize:0,pctFmt:"{n}%",negativepctFmt:"-{n}%",pctChar:"%",roundingMode:"halfdown",exponential:"e",digits:""}};LocaleInfo.prototype={getLanguageName:function(){return this.info["language.name"]},getRegionName:function(){return this.info["region.name"]},getClock:function(){return this.info.clock},getLocale:function(){return this.locale},getUnits:function(){return this.info.units},getUnitFormat:function(){return this.info.unitfmt},getCalendar:function(){return this.info.calendar},getFirstDayOfWeek:function(){return this.info.firstDayOfWeek},getWeekEndStart:function(){return this.info.weekendStart},getWeekEndEnd:function(){return this.info.weekendEnd},getTimeZone:function(){return this.info.timezone},getDecimalSeparator:function(){return this.info.numfmt.decimalChar},getNativeDecimalSeparator:function(){return this.info.native_numfmt&&this.info.native_numfmt.decimalChar||this.info.numfmt.decimalChar},getGroupingSeparator:function(){return this.info.numfmt.groupChar},getNativeGroupingSeparator:function(){return this.info.native_numfmt&&this.info.native_numfmt.groupChar||this.info.numfmt.groupChar},getPrimaryGroupingDigits:function(){return typeof this.info.numfmt.prigroupSize!=="undefined"&&this.info.numfmt.prigroupSize||0},getSecondaryGroupingDigits:function(){return this.info.numfmt.secgroupSize||0},getPercentageFormat:function(){return this.info.numfmt.pctFmt},getNegativePercentageFormat:function(){return this.info.numfmt.negativepctFmt},getPercentageSymbol:function(){return this.info.numfmt.pctChar||"%"},getExponential:function(){return this.info.numfmt.exponential},getNativeExponential:function(){return this.info.native_numfmt&&this.info.native_numfmt.exponential||this.info.numfmt.exponential},getNativePercentageSymbol:function(){return this.info.native_numfmt&&this.info.native_numfmt.pctChar||this.info.numfmt.pctChar||"%"},getNegativeNumberFormat:function(){return this.info.numfmt.negativenumFmt},getCurrencyFormats:function(){return this.info.numfmt.currencyFormats},getCurrency:function(){return this.info.currency},getDigitsStyle:function(){if(this.info.numfmt.useNative){return"native"}if(typeof this.info.native_numfmt!=="undefined"){return"optional"}return"western"},getDigits:function(){return this.info.numfmt.digits},getNativeDigits:function(){return this.info.numfmt.useNative&&this.info.numfmt.digits||this.info.native_numfmt&&this.info.native_numfmt.digits},getRoundingMode:function(){return this.info.numfmt.roundingMode},getDefaultScript:function(){return this.info.scripts?this.info.scripts[0]:"Latn"},getScript:function(){return this.locale.getScript()||this.getDefaultScript()},getAllScripts:function(){return this.info.scripts||["Latn"]},getMeridiemsStyle:function(){return this.info.meridiems||"gregorian"}};module.exports=LocaleInfo;