import{StringUtilities as t}from"../platform/platform.js";import e from"../third_party/i18n/i18n.js";const r=e.registerLocaleData;let n,o;function i(t,r,o={}){if(!n)throw new Error(`Unsupported locale '${n}'`);const i=t(r,o);return e.getFormatted(i,n)}function a(e,r){const n={s:t=>t};return t.format(e,r,n,document.createElement("span"),(function(t,e){return t.appendChild("string"==typeof e?document.createTextNode(e):e),t})).formattedResult}var c=Object.freeze({__proto__:null,registerLocaleData:r,get registeredLocale(){return n},registerLocale:function(t){n=e.lookupLocale(t)},getLazilyComputedLocalizedString:function(t,e,r={}){return()=>i(t,e,r)},getLocalizedString:i,registerUIStrings:function(t,r){return(i,a)=>{try{return e.createMessageInstanceIdFn(t,r)(i,a)}catch(t){if(t instanceof e.idNotInMainDictionaryException){const t=Object.getOwnPropertyNames(function(){if(!n)throw new Error(`Unsupported locale '${n}'`);return o=o||e.getRendererFormattedStrings(n),o}()),r=t.indexOf(i);if(r>=0)return t[r]}return i}}},getFormatLocalizedString:function(t,r,o){if(!n)throw new Error(`Unsupported locale '${n}'`);const i=t(r,o),c=e.getFormatter(i,n).getAst().elements,s=[];let u="";for(const t of c){if("argumentElement"===t.type){const e=o[t.id];e&&(s.push(e),t.value="%s")}u+=t.value}return a(u,s)},formatLocalized:a});export{c as i18n};
