UNPKG

jb-core

Version:

jb design system core modules

2 lines 1.87 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).JBCoreI18N={})}(this,(function(e){function t(e,t,n,a){if("a"===n&&!a)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!a:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?a:"a"===n?a.call(e):a?a.value:t.get(e)}var n,a,i,o,s=class{constructor(){n.add(this),a.set(this,{localeChange:[]}),t(this,n,"m",i).call(this),t(this,n,"m",o).call(this)}setLocale(e){this.locale=e,this.callListeners("localeChange")}addEventListener(e,n){t(this,a,"f")[e].push(n)}callListeners(e){t(this,a,"f")[e].forEach((e=>e()))}};a=new WeakMap,n=new WeakSet,i=function(){if("fa"===(document?.documentElement?.lang||"en"))this.locale=new Intl.Locale("fa",{calendar:"persian",numeric:!1,region:"IR"});else this.locale=new Intl.Locale("en",{calendar:"gregory",region:"US"})},o=function(){new MutationObserver((e=>{e.forEach((e=>{"lang"==e.attributeName&&(t(this,n,"m",i).call(this),this.callListeners("localeChange"))}))})).observe(document.documentElement,{attributeFilter:["lang"],childList:!1,subtree:!1,attributes:!0})};const l=new s;e.JBDictionary=class{constructor(e){this.dictionary={},this.dictionary=e}setLanguage(e,t){this.dictionary[e]=t}get(e,t){const n=this.dictionary[e.locale.language]?this.dictionary[e.locale.language]:this.dictionary.en;return n[t]?n[t]:this.dictionary.en[t]}},e.JBI18N=s,e.getRequiredMessage=function(e,t){return"fa"===e.locale.language?t?`لطفاً ${t} خود را وارد نمایید`:"لطفاً این قسمت را پر کنید":t?`Please enter your ${t}`:"Please complete this field"},e.i18n=l})); //# sourceMappingURL=index.umd.js.map