jb-core
Version:
jb design system core modules
2 lines • 1.66 kB
JavaScript
function e(e,t,a,n){if("a"===a&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===a?n:"a"===a?n.call(e):n?n.value:t.get(e)}var t,a,n,i,r=class{constructor(){t.add(this),a.set(this,{localeChange:[]}),e(this,t,"m",n).call(this),e(this,t,"m",i).call(this)}setLocale(e){this.locale=e,this.callListeners("localeChange")}addEventListener(t,n){e(this,a,"f")[t].push(n)}callListeners(t){e(this,a,"f")[t].forEach((e=>e()))}};a=new WeakMap,t=new WeakSet,n=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"})},i=function(){new MutationObserver((a=>{a.forEach((a=>{"lang"==a.attributeName&&(e(this,t,"m",n).call(this),this.callListeners("localeChange"))}))})).observe(document.documentElement,{attributeFilter:["lang"],childList:!1,subtree:!1,attributes:!0})};const l=new r;function s(e,t){return"fa"===e.locale.language?t?`لطفاً ${t} خود را وارد نمایید`:"لطفاً این قسمت را پر کنید":t?`Please enter your ${t}`:"Please complete this field"}var o=class{constructor(e){this.dictionary={},this.dictionary=e}setLanguage(e,t){this.dictionary[e]=t}get(e,t){const a=this.dictionary[e.locale.language]?this.dictionary[e.locale.language]:this.dictionary.en;return a[t]?a[t]:this.dictionary.en[t]}};export{o as JBDictionary,r as JBI18N,s as getRequiredMessage,l as i18n};
//# sourceMappingURL=index.js.map