import{StringUtilities as t}from"../platform/platform.js";import e from"../third_party/i18n/i18n.js";const r=e.registerLocaleData;let n,o;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 i=Object.freeze({__proto__:null,registerLocaleData:r,get registeredLocale(){return n},registerLocale:function(t){n=e.lookupLocale(t)},getLocalizedString:function(t,r,o={}){if(!n)throw new Error(`Unsupported locale '${n}'`);const a=t(r,o);return e.getFormatted(a,n)},registerUIStrings:function(t,r){return(a,i)=>{try{return e.createMessageInstanceIdFn(t,r)(a,i)}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(a);if(r>=0)return t[r]}return a}}},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{i as i18n};
