var u=Object.defineProperty;var g=(s,t)=>{for(var e in t)u(s,e,{get:t[e],enumerable:!0})};var m={};g(m,{I18n:()=>l});var d={};g(d,{LocalizedStringSet:()=>c,RegisteredFileStrings:()=>o});import*as n from"./../intl-messageformat/intl-messageformat.js";var h={},o=class{filename;stringStructure;localizedMessages;localizedStringSet;constructor(t,e,r){this.filename=t,this.stringStructure=e,this.localizedMessages=r}getLocalizedStringSetFor(t){if(this.localizedStringSet)return this.localizedStringSet;let e=this.localizedMessages.get(t);if(!e)throw new Error(`No locale data registered for '${t}'`);return this.localizedStringSet=new c(this.filename,this.stringStructure,t,e),this.localizedStringSet}},c=class{filename;stringStructure;localizedMessages;cachedSimpleStrings=new Map;cachedMessageFormatters=new Map;localeForFormatter;constructor(t,e,r,a){this.filename=t,this.stringStructure=e,this.localizedMessages=a,this.localeForFormatter=r==="en-XA"||r==="en-XL"?"de-DE":r}getLocalizedString(t,e=h){return e===h||Object.keys(e).length===0?this.getSimpleLocalizedString(t):this.getFormattedLocalizedString(t,e)}getMessageFormatterFor(t){let e=Object.keys(this.stringStructure).find(S=>this.stringStructure[S]===t);if(!e)throw new Error(`Unable to locate '${t}' in UIStrings object`);let r=`${this.filename} | ${e}`,a=this.localizedMessages[r],i=a?a.message:t;return new n.IntlMessageFormat(i,this.localeForFormatter,void 0,{ignoreTag:!0})}getSimpleLocalizedString(t){let e=this.cachedSimpleStrings.get(t);if(e)return e;let r=this.getMessageFormatterFor(t);try{let a=r.format();return this.cachedSimpleStrings.set(t,a),a}catch{let i=new n.IntlMessageFormat(t,this.localeForFormatter,void 0,{ignoreTag:!0}).format();return this.cachedSimpleStrings.set(t,i),i}}getFormattedLocalizedString(t,e){let r=this.cachedMessageFormatters.get(t);r||(r=this.getMessageFormatterFor(t),this.cachedMessageFormatters.set(t,r));try{return r.format(e)}catch{return new n.IntlMessageFormat(t,this.localeForFormatter,void 0,{ignoreTag:!0}).format(e)}}};var l=class{supportedLocales;localeData=new Map;defaultLocale;constructor(t,e){this.defaultLocale=e,this.supportedLocales=new Set(t)}registerLocaleData(t,e){this.localeData.set(t,e)}hasLocaleDataForTest(t){return this.localeData.has(t)}resetLocaleDataForTest(){this.localeData.clear()}registerFileStrings(t,e){return new o(t,e,this.localeData)}lookupClosestSupportedLocale(t){let r=Intl.getCanonicalLocales(t)[0].split("-");for(;r.length;){let a=r.join("-");if(this.supportedLocales.has(a))return a;r.pop()}return this.defaultLocale}};export{m as I18n,d as LocalizedStringSet};
//# sourceMappingURL=i18n.js.map
