UNPKG

vox-core

Version:

Runtime de aplicaciones multiplataforma

338 lines (273 loc) 7.73 kB
var Util= core.VW.Util; var cached={}; var cultureData= require("./cultureDataInfo.js"); var SG= core.System.Globalization; var CultureInfo= module.exports= function(/*string or int*/name, /*bool */userOverride){ if(arguments.length<2){ userOverride=true; } else{ userOverride=!!userOverride; } this.$override= userOverride; this.$data=cultureData.getData(name); this.$m_cultureData= this.$data.m_cultureData; } var culture='en'; /* Static methods */ CultureInfo.getCultureInfo= function(/*string or int*/id){ if(cached[id]){ return cached[id]; } if(typeof id=="number"){ $data=cultureData.getData(id); $m_cultureData= $data.m_cultureData; return CultureInfo.getCultureInfo($m_cultureData.sRealName); } return cached[id]= new CultureInfo(id,false); } CultureInfo.getCultures= function(){ var all=mod.getData("01LCIDs"); var re=[]; for(var id in all){ re.push(CultureInfo.getCultureInfo(id)); } return re; } CultureInfo.getCalendarInstance= function(/*int*/calType){ if(calType==1){ return new SG.GregorianCalendar(); } return CultureInfo.getCalendarInstanceRare(calType); } CultureInfo.getCalendarInstanceRare = function(/*int*/calType){ /* Por ahora no se han implementado los demás calendarios */ return new SG.GregorianCalendar(calType); switch (calType) { case 2: case 9: case 10: case 11: case 12: return new SG.GregorianCalendar(calType); case 3: //return new JapaneseCalendar(); throw new core.System.NotImplementedException(); case 4: //return new TaiwanCalendar(); throw new core.System.NotImplementedException(); case 5: //return new KoreanCalendar(); throw new core.System.NotImplementedException(); case 6: //return new HijriCalendar(); throw new core.System.NotImplementedException(); case 7: //return new ThaiBuddhistCalendar(); throw new core.System.NotImplementedException(); case 8: //return new HebrewCalendar(); throw new core.System.NotImplementedException(); case 14: //return new JapaneseLunisolarCalendar(); throw new core.System.NotImplementedException(); case 15: //return new ChineseLunisolarCalendar(); throw new core.System.NotImplementedException(); case 20: //return new KoreanLunisolarCalendar(); throw new core.System.NotImplementedException(); case 21: //return new TaiwanLunisolarCalendar(); throw new core.System.NotImplementedException(); case 22: //return new PersianCalendar(); throw new core.System.NotImplementedException(); case 23: //return new UmAlQuraCalendar(); throw new core.System.NotImplementedException(); } return new SG.GregorianCalendar(); } /* Static properties*/ CultureInfo.get_currentCulture= function(){ if(this.$default){ return this.$default; } if(!this.$current){ this.$current= CultureInfo.getCultureInfo(culture); // Por defecto } return this.$current; } CultureInfo.get_defaultThreadCurrentCulture= function(){ return this.$default; } CultureInfo.set_defaultThreadCurrentCulture= function(culture){ return this.$default=culture; } /* Instance methods*/ CultureInfo.prototype.toString=function(){ return this.name; } CultureInfo.prototype.$nativeCultureName= function(/*string */name){ var l=this.$data.languages[name]; if(!l){ name= name.split("-"); name=name[0]; l=this.$data.languages[name]; } if(l && l.length>0){ l= l[0].toUpperCase()+l.substring(1); } return l||""; } CultureInfo.prototype.$nativeRegionName= function(/*string */name){ var l=this.$data.territories[name]; if(!l){ name= name.split("-"); name=name[0]; l=this.$data.territories[name]; } return l||""; } CultureInfo.prototype.$nativeCurrencyName= function(/*string */name){ var l=this.$data.currencies[name]; if(!l){ name= name.split("-"); name=name[0]; l=this.$data.currencies[name]; } return l?l.displayName : ""; } /* Propiedades */ CultureInfo.prototype.get_dateTimeFormat= function(){ if(!this.$datetimeformat){ this.$datetimeformat= new SG.DateTimeFormatInfo(this.$m_cultureData, this.calendar); } return this.$datetimeformat; } CultureInfo.prototype.get_calendar= function(){ if(!this.$calendar){ var id=this.$m_cultureData.waCalendars[0]; this.$calendar= CultureInfo.getCalendarInstance(id); } return this.$calendar; } CultureInfo.prototype.get_displayName= function(){ return CultureInfo.currentCulture.$nativeCultureName(this.name); } CultureInfo.prototype.get_englishName= function(){ return this.$m_cultureData.sEnglishDisplayName; } CultureInfo.prototype.get_ietfLanguageTag= function(){ var name; if ((name = this.name) != null) { if (name == "zh-CHT") { return "zh-Hant"; } if (name == "zh-CHS") { return "zh-Hans"; } } return this.name; } CultureInfo.prototype.get_isNeutralCulture= function(){ return this.$m_cultureData.bNeutral; } CultureInfo.prototype.get_isReadOnly= function(){ return false; } CultureInfo.prototype.get_keyboardLayout= function(){ return this.$m_cultureData.iInputLanguageHandle; } CultureInfo.prototype.get_LCID= function(){ return this.$m_cultureData.iLanguage; } CultureInfo.prototype.get_name= function(){ return this.$m_cultureData.sName; } CultureInfo.prototype.get_nativeName= function(){ return this.$m_cultureData.sNativeDisplayName; } CultureInfo.prototype.get_numberFormatInfo= function(){ throw new core.System.NotImplementedException("No implementado todavía"); } CultureInfo.prototype.get_parent= function(){ var parent=this.$m_cultureData.sParent; if(!parent){ return CultureInfo.invariantCulture; } return CultureInfo.getCultureInfo(parent); } CultureInfo.prototype.get_threeLetterISOLanguageName= function(){ return this.$m_cultureData.sISO639Language2; } CultureInfo.prototype.get_twoLetterISOLanguageName= function(){ return this.$m_cultureData.sISO639Language; } CultureInfo.prototype.get_useUserOverride= function(){ return !!this.$override; } Util.createProperties(CultureInfo,CultureInfo.prototype); /** No está completamente probado pero esto debería traer la información Locale del PC **/ CultureInfo.ready= function(f){ return f(); } var lang= process.env.LANG; if(lang){ lang= lang.split(".")[0]; if(lang){ culture=lang.replace("_","-"); } } else{ // En este punto puede ser que el SO sea Windows var win32= require("os").platform()=="win32"; var warning; if(win32){ //var csfromjs= require("csfromjs"); //var type=csfromjs.get("System.Globalization.CultureInfo").staticProperty("CurrentCulture").property("Name"); //var ready,readyi,err; //var funcs=[]; /* CultureInfo.ready= function(f){ if(f){ funcs.push(f); } if(ready){ var l= funcs; l.forEach(function(g){ g(err,{ warning: warning }); }); funcs=[]; } else{ readyi= setTimeout(CultureInfo.ready,10); } } */ if(core.VW.Clr){ var CultureClass=core.VW.Clr.Manager.current.get('System.Globalization.CultureInfo') var task= CultureClass.loadMembers() task.oncomplete= function(){ if(task.exception) return task=CultureClass.m.CurrentCulture.invoke(undefined,undefined,[], true) task.oncomplete=function(){ if(task.exception) return culture= task.result if(CultureInfo.$current){ CultureInfo.$current= CultureInfo.getCultureInfo(culture) } } } } } }