New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

@tolgee/core

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tolgee/core - npm Package Compare versions

Comparing version 5.7.3 to 5.8.0

@@ -962,3 +962,3 @@ 'use strict';

function parseCombinedOptions(_a) {
var { ns, noWrap, orEmpty, params } = _a, rest = __rest(_a, ["ns", "noWrap", "orEmpty", "params"]);
var { ns, noWrap, orEmpty, params, language } = _a, rest = __rest(_a, ["ns", "noWrap", "orEmpty", "params", "language"]);
const options = {

@@ -968,2 +968,3 @@ ns: ns,

orEmpty: orEmpty,
language: language,
};

@@ -1113,5 +1114,5 @@ return Object.assign(Object.assign({}, options), { params: Object.assign({}, rest) });

}
function getTranslation({ key, ns }) {
function getTranslation({ key, ns, language }) {
const namespaces = getDefaultAndFallbackNs(ns || undefined);
const languages = state.getFallbackLangs();
const languages = state.getFallbackLangs(language);
return cache.getTranslationFallback(namespaces, languages, key);

@@ -1118,0 +1119,0 @@ }

@@ -962,3 +962,3 @@ 'use strict';

function parseCombinedOptions(_a) {
var { ns, noWrap, orEmpty, params } = _a, rest = __rest(_a, ["ns", "noWrap", "orEmpty", "params"]);
var { ns, noWrap, orEmpty, params, language } = _a, rest = __rest(_a, ["ns", "noWrap", "orEmpty", "params", "language"]);
const options = {

@@ -968,2 +968,3 @@ ns: ns,

orEmpty: orEmpty,
language: language,
};

@@ -1113,5 +1114,5 @@ return Object.assign(Object.assign({}, options), { params: Object.assign({}, rest) });

}
function getTranslation({ key, ns }) {
function getTranslation({ key, ns, language }) {
const namespaces = getDefaultAndFallbackNs(ns || undefined);
const languages = state.getFallbackLangs();
const languages = state.getFallbackLangs(language);
return cache.getTranslationFallback(namespaces, languages, key);

@@ -1118,0 +1119,0 @@ }

@@ -1,2 +0,2 @@

"use strict";function e(e){return Boolean(e&&"function"==typeof e.then)}Object.defineProperty(exports,"__esModule",{value:!0});const n=(n,t)=>e(n)?Promise.resolve(n).then(t):t(n),t=e=>`Tolgee: You need to specify '${e}' option`;function a(e){return"string"==typeof e?[e]:Array.isArray(e)?e:void 0}function i(e){return a(e)||[]}function o(e,n){return"object"!=typeof(t=n)||Array.isArray(t)||null===t?i(n):i(null==n?void 0:n[e]);var t}function r(e){return Array.from(new Set(e))}function s(e){return e?e.replace(/\/+$/,""):e}const c=e=>{let n=[];return Object.freeze({listen:e=>{const t=n=>{e(n)};return n.push(t),{unsubscribe:()=>{n=n.filter((e=>t!==e))}}},emit:t=>{e()&&n.forEach((e=>e({value:t})))}})},g=(e,n,t)=>{const a=new Set,o=new Set;let r=[];const s=()=>{if(0===r.length)return;const e=r;r=[],a.forEach((e=>{e({value:void 0})}));let t=new Set;e.forEach((e=>{void 0===e?t=void 0:void 0!==t&&e.forEach((e=>t.add(e)))}));(e=>{const t=new Set(n());o.forEach((n=>{(void 0===e||-1!==(null==e?void 0:e.findIndex((e=>t.has(e)||n.namespaces.has(e)))))&&n.fn({value:void 0})}))})(t?Array.from(t.keys()):void 0)};return Object.freeze({listenSome:e=>{const n={fn:n=>{e(n)},namespaces:new Set};o.add(n);const a={unsubscribe:()=>{o.delete(n)},subscribeNs:e=>(i(e).forEach((e=>n.namespaces.add(e))),void 0===e&&n.namespaces.add(t()),a)};return a},listen:e=>{a.add(e);return{unsubscribe:()=>{a.delete(e)}}},emit:(n,t)=>{e()&&(r.push(n),t?setTimeout(s,0):s())}})},u=e=>{const n=new Map;return Object.entries(e).forEach((([e,t])=>{null!=t&&("object"!=typeof t?n.set(e,t):u(t).forEach(((t,a)=>{n.set(e+"."+a,t)})))})),n},l=e=>{const[n,...t]=e.split(":");return{language:n,namespace:t.join(":")||""}},d=({language:e,namespace:n})=>n?`${e}:${n}`:e,f=(e,n,t,a,o,s,c)=>{const g=new Map,f=new Map;let p={},v=0;function h(n,t,a){const i=d(n);f.set(i,{data:u(t),version:a}),e.emit(n)}function b(e,n){h(e,n,v)}function m(e,n=!1){const t=f.get(d(e));return t&&n?t.version===v:Boolean(t)}function y(e){var n;return null===(n=f.get(d(a(e))))||void 0===n?void 0:n.data}function O(e){let t;if(!t){const n=p[d(e)];"function"==typeof n&&(t=n())}return t||(t=n(e)),t}return Object.freeze({addStaticData:function(e){e&&(p=Object.assign(Object.assign({},p),e),Object.entries(e).forEach((([e,n])=>{if("function"!=typeof n){const t=l(e),a=f.get(e);a&&0!==a.version||h(t,n,0)}})))},invalidate:function(){g.clear(),v+=1},addRecord:b,exists:m,getRecord:y,getTranslation:function(e,n){var t;return null===(t=f.get(d(e)))||void 0===t?void 0:t.data.get(n)},getTranslationNs:function(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=f.get(d({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return[i]}return r(e)},getTranslationFallback:function(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=f.get(d({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return n}},changeTranslation:function(n,t,a){var i;const o=null===(i=f.get(d(n)))||void 0===i?void 0:i.data;null==o||o.set(t,a),e.emit(Object.assign(Object.assign({},n),{key:t}))},isFetching:function(e){if(o())return!0;if(void 0===e)return g.size>0;const n=i(e);return Boolean(Array.from(g.keys()).find((e=>n.includes(l(e).namespace))))},isLoading:function(e,n){const t=i(n);return Boolean(o()||Array.from(g.keys()).find((n=>{const a=l(n);return(!t.length||t.includes(a.namespace))&&!m({namespace:a.namespace,language:e})})))},loadRecords:async function(e,n){const i=e.map((e=>{const i=a(e),o=d(i),r=g.get(o);if(r)return{new:!1,promise:r,keyObject:i,cacheKey:o};const s=function(e,n){var a;let i;return n&&(i=null===(a=t(e))||void 0===a?void 0:a.catch((()=>(console.warn("Tolgee: Failed to fetch data from dev backend"),O(e))))),i||(i=O(e)),i}(i,n)||Promise.resolve(void 0);return g.set(o,s),{new:!0,promise:s,keyObject:i,cacheKey:o}}));s.notify(),c.notify();const o=await Promise.all(i.map((e=>e.promise)));return i.forEach(((e,n)=>{const t=g.get(e.cacheKey)!==e.promise;if(e.new&&!t){g.delete(e.cacheKey);const t=o[n];t?b(e.keyObject,t):y(e.keyObject)||b(e.keyObject,{})}})),s.notify(),c.notify(),i.map((e=>y(e.keyObject)))},getAllRecords:function(){return Array.from(f.entries()).map((([e,n])=>Object.assign(Object.assign({},l(e)),{data:n.data})))}})};function p(e,n){var t={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&n.indexOf(a)<0&&(t[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(a=Object.getOwnPropertySymbols(e);i<a.length;i++)n.indexOf(a[i])<0&&Object.prototype.propertyIsEnumerable.call(e,a[i])&&(t[a[i]]=e[a[i]])}return t}const v="invalid",h={defaultNs:"",observerOptions:{tagAttributes:{textarea:["placeholder"],input:["value","placeholder"],img:["alt"],"*":["aria-label","title"]},restrictedElements:["script","style"],highlightKeys:["Alt"],highlightColor:"rgb(255, 0, 0)",highlightWidth:5,inputPrefix:"%-%tolgee:",inputSuffix:"%-%",passToParent:["option","optgroup"]},observerType:"invisible",onFormatError:v,apiUrl:"https://app.tolgee.io"},b=(...e)=>{let n={};return e.forEach((e=>{n=Object.assign(Object.assign(Object.assign({},n),e),{observerOptions:Object.assign(Object.assign({},n.observerOptions),null==e?void 0:e.observerOptions)})})),n},m=(e,n)=>{const t=b(h,null==n?void 0:n.initialOptions,e);return t.apiUrl=s(t.apiUrl),{initialOptions:t,activeNamespaces:(null==n?void 0:n.activeNamespaces)||new Map,language:null==n?void 0:n.language,pendingLanguage:null==n?void 0:n.language,isInitialLoading:!1,isRunning:!1}},y=(t,a,i,o,r,s)=>{const c={ui:void 0},g={formatters:[],finalFormatter:void 0,observer:void 0,devBackend:void 0,backends:[],ui:void 0,languageDetector:void 0,languageStorage:void 0},u=async({keysAndDefaults:e,event:n})=>{var t;const a=e.map((({key:e,ns:n,defaultValue:t})=>({key:e,defaultValue:t,ns:o({key:e,ns:n}),translation:r({key:e,ns:n})})));null===(t=g.ui)||void 0===t||t.handleElementClick(a,n)},l=(e,n)=>{var t,a;return(null===(a=null===(t=g.observer)||void 0===t?void 0:t.highlight)||void 0===a?void 0:a.call(t,e,n))||{unhighlight(){}}},d=(e,n)=>{var t;return(null===(t=g.observer)||void 0===t?void 0:t.findPositions(e,n))||[]},f=e=>{const n=r({key:e.key,ns:e.ns});return N(Object.assign(Object.assign({},e),{translation:n,formatEnabled:!0}))},h=e=>{g.observer=null==e?void 0:e()},b=()=>Boolean(g.observer),m=e=>{e&&g.formatters.push(e)},y=e=>{g.finalFormatter=e},O=e=>{c.ui=e},L=()=>Boolean(c.ui),j=e=>{g.languageStorage=e},k=e=>{g.languageDetector=e},w=e=>{e&&g.backends.push(e)},R=e=>{g.devBackend=e},E=()=>g.devBackend;function N(e){var n,{formatEnabled:i}=e,o=p(e,["formatEnabled"]);const{key:r,translation:s,defaultValue:c,noWrap:u,params:l,orEmpty:d,ns:f}=o,h=s||c;let b=h||(d?"":r);const m=t(),y=i||!(null===(n=g.observer)||void 0===n?void 0:n.outputNotFormattable),O=e=>g.observer&&!u?g.observer.wrap({key:r,translation:e,defaultValue:c,params:l,ns:f}):e;b=O(b);try{if(h&&m&&y)for(const e of g.formatters)b=e.format({translation:b,language:m,params:l});g.finalFormatter&&h&&m&&y&&(b=g.finalFormatter.format({translation:b,language:m,params:l}))}catch(e){console.error(e);const n=("string"==typeof(L=e)?L:"string"==typeof(null==L?void 0:L.message)?L.message:void 0)||v,t=a().onFormatError,i=typeof t;b="string"===i?t:"function"===i?t(n,o):v,b=O(b)}var L;return b}return Object.freeze({addPlugin:function(e,n){n(e,Object.freeze({setFinalFormatter:y,addFormatter:m,setObserver:h,hasObserver:b,setUi:O,hasUi:L,setDevBackend:R,addBackend:w,setLanguageDetector:k,setLanguageStorage:j}))},formatTranslation:N,getDevBackend:E,getBackendRecord:({language:n,namespace:t})=>{for(const a of g.backends){const i=a.getRecord({language:n,namespace:t});if(e(i))return null==i?void 0:i.catch((e=>(console.error(e),{})));if(void 0!==i)return i}},getBackendDevRecord:({language:e,namespace:n})=>{var t;const{apiKey:i,apiUrl:o,projectId:r}=a();return null===(t=g.devBackend)||void 0===t?void 0:t.getRecord({apiKey:i,apiUrl:o,projectId:r,language:e,namespace:n})},getLanguageDetector:()=>g.languageDetector,getLanguageStorage:()=>g.languageStorage,getInitialLanguage:()=>{var e;const t=i(),a=null===(e=g.languageStorage)||void 0===e?void 0:e.getLanguage();return n(a,(e=>t&&!t.includes(e)||!e?(()=>{if(!g.languageDetector)return;const e=i();return g.languageDetector.getLanguage({availableLanguages:e})})():e))},setStoredLanguage:e=>{var n;null===(n=g.languageStorage)||void 0===n||n.setLanguage(e)},run:()=>{var e,n;const{apiKey:t,apiUrl:i,projectId:o,observerOptions:r}=a();g.ui=null===(e=c.ui)||void 0===e?void 0:e.call(c,{apiKey:t,apiUrl:i,projectId:o,highlight:l,changeTranslation:s,findPositions:d}),null===(n=g.observer)||void 0===n||n.run({mouseHighlight:!0,options:r,translate:f,onClick:u})},stop:()=>{var e;g.ui=void 0,null===(e=g.observer)||void 0===e||e.stop()},retranslate:()=>{var e;null===(e=g.observer)||void 0===e||e.retranslate()},highlight:l,unwrap:e=>{var n;return g.observer?null===(n=g.observer)||void 0===n?void 0:n.unwrap(e):{text:e,keys:[]}},wrap:e=>{var n;return g.observer?null===(n=g.observer)||void 0===n?void 0:n.wrap(e):e.translation},hasDevBackend:function(){return Boolean(E())}})},O=(e,n,t)=>{let a=e;return Object.freeze({init:function(e){a=e},notify:function(){const e=n();a!==e&&t(e),a=e}})};const L=(e,...n)=>{let t,a={};return"object"==typeof e?a=e:(a.key=e,"string"==typeof n[0]?(a.defaultValue=n[0],t=n[1]):"object"==typeof n[0]&&(t=n[0])),t&&(a=Object.assign(Object.assign({},function(e){var{ns:n,noWrap:t,orEmpty:a,params:i}=e,o=p(e,["ns","noWrap","orEmpty","params"]);const r={ns:n,noWrap:t,orEmpty:a};return Object.assign(Object.assign({},r),{params:Object.assign({},o)})}(t)),a)),a},j=({options:a})=>{const u=((e,n)=>{let t=!0;function a(){return t}const i=c(a),o=c(a),r=c(a),s=c(a),u=c(a),l=c(a),d=c(a),f=g(a,e,n);return u.listen((()=>f.emit())),o.listen((()=>f.emit())),d.listen((({value:e})=>{f.emit([e.namespace],!0)})),Object.freeze({onPendingLanguageChange:i,onLanguageChange:o,onLoadingChange:r,onFetchingChange:s,onInitialLoaded:u,onRunningChange:l,onCacheChange:d,onUpdate:f,setEmitterActive:function(e){t=e},on:(e,n)=>{switch(e){case"pendingLanguage":return i.listen(n);case"language":return o.listen(n);case"loading":return r.listen(n);case"fetching":return s.listen(n);case"initialLoad":return u.listen(n);case"running":return l.listen(n);case"cache":return d.listen(n);case"update":return f.listen(n)}}})})(j,k),d=O(!1,(()=>b.isFetching()),u.onFetchingChange.emit),p=O(!1,(()=>A()),u.onLoadingChange.emit),v=((e,n,t)=>{let a,c=m();function g(){return c.language||c.initialOptions.language}function u(){return Object.assign(Object.assign({},c.initialOptions),a)}return Object.freeze({init:function(e){c=m(e,c)},isRunning:function(){return c.isRunning},setRunning:function(e){c.isRunning!==e&&(c.isRunning=e,t.emit(e))},isInitialLoading:function(){return c.isInitialLoading},setInitialLoading:function(e){c.isInitialLoading=e},getLanguage:g,setLanguage:function(n){c.language!==n&&(c.language=n,e.emit(n))},getPendingLanguage:function(){return c.pendingLanguage||g()},setPendingLanguage:function(e){c.pendingLanguage!==e&&(c.pendingLanguage=e,n.emit(e))},getInitialOptions:u,addActiveNs:function(e){i(e).forEach((e=>{const n=c.activeNamespaces.get(e);void 0!==n?c.activeNamespaces.set(e,n+1):c.activeNamespaces.set(e,1)}))},removeActiveNs:function(e){i(e).forEach((e=>{const n=c.activeNamespaces.get(e);void 0!==n&&n>1?c.activeNamespaces.set(e,n-1):c.activeNamespaces.delete(e)}))},getRequiredNamespaces:function(){return r([...c.initialOptions.ns||[c.initialOptions.defaultNs],...i(c.initialOptions.fallbackNs),...c.activeNamespaces.keys()])},getFallbackLangs:function(e){const n=e||g();return n?r([n,...o(n,c.initialOptions.fallbackLanguage)]):[]},getFallbackNs:function(){return i(c.initialOptions.fallbackNs)},getDefaultNs:function(e){return void 0===e?c.initialOptions.defaultNs:e},getAvailableLanguages:function(){if(c.initialOptions.availableLanguages)return c.initialOptions.availableLanguages;if(c.initialOptions.staticData){const e=Object.keys(c.initialOptions.staticData).map((e=>l(e).language));return Array.from(new Set(e))}},withDefaultNs:function(e){return{namespace:void 0===e.namespace?u().defaultNs:e.namespace,language:e.language}},overrideCredentials:function(e){a=e?Object.assign(Object.assign({},e),{apiUrl:s(e.apiUrl)}):void 0}})})(u.onLanguageChange,u.onPendingLanguageChange,u.onRunningChange),h=y(v.getLanguage,v.getInitialOptions,v.getAvailableLanguages,(function({key:e,ns:n}){const t=v.getFallbackLangs(),a=w(n||void 0);return b.getTranslationNs(a,t,e)}),D,E),b=f(u.onCacheChange,h.getBackendRecord,h.getBackendDevRecord,v.withDefaultNs,v.isInitialLoading,d,p);function j(){return v.getFallbackNs()}function k(e){return v.getDefaultNs(e)}function w(e){return[...i(k(e)),...j()]}function R(e){return[...i(e||k()),...v.getRequiredNamespaces()]}function E(e,n,t){const a=v.withDefaultNs(e),i=b.getTranslation(a,n);return b.changeTranslation(a,n,t),{revert:()=>{b.changeTranslation(a,n,i)}}}function N(e){v.init(e),b.addStaticData(v.getInitialOptions().staticData)}function A(e){return b.isLoading(v.getLanguage(),e)}function F(){return Boolean(v.getInitialOptions().apiKey&&v.getInitialOptions().apiUrl)}function I(e,t){const a=function(e,n){const t=v.getFallbackLangs(e),a=R(n),i=[];return t.forEach((e=>{a.forEach((n=>{b.exists({language:e,namespace:n},!0)||i.push({language:e,namespace:n})}))})),i}(e,t);if(a.length)return n(P(a),(()=>{}))}function D({key:e,ns:n}){const t=w(n||void 0),a=v.getFallbackLangs();return b.getTranslationFallback(t,a,e)}function S(){const a=n(function(){if(v.getLanguage())return;if(!v.getInitialOptions().defaultLanguage)throw new Error(t("defaultLanguage"));const e=h.getInitialLanguage();return n(e,(e=>{const n=e||v.getInitialOptions().defaultLanguage;n&&v.setLanguage(n)}))}(),(()=>I()));if(e(a))return v.setInitialLoading(!0),d.notify(),p.notify(),Promise.resolve(a).then((()=>{v.setInitialLoading(!1),d.notify(),p.notify(),u.onInitialLoaded.emit()}));u.onInitialLoaded.emit()}function P(e){return b.loadRecords(e,F())}a&&N(a),u.onUpdate.listen((()=>{v.isRunning()&&h.retranslate()}));const T=()=>{const e=h.getLanguageDetector()||h.getLanguageStorage();if(e){if(!v.getAvailableLanguages())throw new Error(t("availableLanguages"))}if(!v.getLanguage()&&!v.getInitialOptions().defaultLanguage)throw e?new Error(t("defaultLanguage")):new Error(t("language"))};return Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},u),v),h),b),{init:N,changeLanguage:async function(e){v.getPendingLanguage()===e&&v.getLanguage()===e||(v.setPendingLanguage(e),v.isRunning()&&await I(e),e===v.getPendingLanguage()&&(v.setLanguage(e),h.setStoredLanguage(e)))},getTranslation:D,changeTranslation:E,addActiveNs:async function(e,n){n||v.addActiveNs(e),v.isRunning()&&await I(void 0,e)},loadRecords:P,loadRecord:async function(e){return(await P([e]))[0]},isLoading:A,isLoaded:function(e){const n=v.getLanguage();if(!n)return!1;const t=v.getFallbackLangs(n),a=R(e),i=[];return t.forEach((e=>{a.forEach((n=>{b.exists({language:e,namespace:n})||i.push({language:e,namespace:n})}))})),0===i.length},t:(...e)=>{const n=L(...e),t=D(n);return h.formatTranslation(Object.assign(Object.assign({},n),{translation:t}))},isDev:F,run:function(){let e;return T(),v.isRunning()||(F()&&b.invalidate(),v.setRunning(!0),h.run(),e=S()),Promise.resolve(e)},stop:function(){v.isRunning()&&(h.stop(),v.setRunning(!1))}}))},k=0,w=1,R=2;class E extends Error{constructor(e,n,t){let a;a=e===k?"Empty parameter":e===w?"Unexpected character":"Unexpected end",super(`Tolgee parser: ${a} at ${n} in "${t}"`),this.code=e,this.index=n}}function N(e){return/\s/.test(e)}const A=0,F=1,I=2,D=3,S=4,P=new Set([I,F,A]),T="'",C=new Set(["{","}",T]),x=e=>/[0-9a-zA-Z_]/.test(e);function B(e,n){const[t,a]=function(e){let n=A,t="",a="",i="";const o=[],r=[];let s=0;function c(n){throw new E(n,s,e)}const g=()=>{o.push(t),t=""},u=()=>{""===a&&c(k),r.push(a),a=""};for(s=0;s<e.length;s++)switch(i=e[s],n){case A:i===T?(t+=i,n=F):"{"===i?(g(),n=D):(t+=i,n=A);break;case F:C.has(i)?(t=t.slice(0,-1)+i,n=I):(t+=i,n=A);break;case I:i===T?n=A:(t+=i,n=I);break;case D:"}"===i?(u(),n=A):N(i)?""!==a&&(u(),n=S):(x(i)||c(w),a+=i,n=D);break;case S:"}"==i?n=A:N(i)?n=S:c(w)}return P.has(n)||c(R),g(),[o,r]}(e),i=[t[0]];for(let o=1;o<t.length;o++){const r=null==n?void 0:n[a[o-1]];if(void 0===r)throw new Error(`Missing parameter "${a[o-1]}" in "${e}"`);i.push(String(r)),i.push(t[o])}return i.join("")}exports.FormatSimple=()=>(e,n)=>(n.setFinalFormatter({format:({translation:e,params:n})=>B(e,n)}),e),exports.TolgeeCore=()=>{const e={plugins:[],options:{}},n=Object.freeze({use:t=>(e.plugins.push(t),n),updateDefaults:t=>(e.options=b(e.options,t),n),init(n){const t=(e=>{const n=j({options:e}),t=e=>{const t=n.isRunning();t&&n.stop(),e(),t&&n.run()},a=Object.freeze({on:n.on,onNsUpdate:n.onUpdate.listenSome,setEmitterActive:n.setEmitterActive,getLanguage:n.getLanguage,getPendingLanguage:n.getPendingLanguage,changeLanguage:n.changeLanguage,changeTranslation:n.changeTranslation,addActiveNs:n.addActiveNs,removeActiveNs:n.removeActiveNs,loadRecords:n.loadRecords,loadRecord:n.loadRecord,addStaticData:n.addStaticData,getRecord:n.getRecord,getAllRecords:n.getAllRecords,isLoaded:n.isLoaded,isInitialLoading:n.isInitialLoading,isLoading:n.isLoading,isFetching:n.isFetching,isRunning:n.isRunning,run:n.run,stop:n.stop,t:n.t,highlight:n.highlight,getInitialOptions:n.getInitialOptions,isDev:n.isDev,wrap:n.wrap,unwrap:n.unwrap,overrideCredentials(e){t((()=>n.overrideCredentials(e)))},addPlugin(e){e&&t((()=>n.addPlugin(a,e)))},updateOptions(e){e&&t((()=>n.init(e)))}});return a})(b(e.options,n));return e.plugins.forEach(t.addPlugin),t}});return n},exports.getFallback=a,exports.getFallbackArray=i,exports.getTranslateProps=L;
"use strict";function e(e){return Boolean(e&&"function"==typeof e.then)}Object.defineProperty(exports,"__esModule",{value:!0});const n=(n,t)=>e(n)?Promise.resolve(n).then(t):t(n),t=e=>`Tolgee: You need to specify '${e}' option`;function a(e){return"string"==typeof e?[e]:Array.isArray(e)?e:void 0}function i(e){return a(e)||[]}function o(e,n){return"object"!=typeof(t=n)||Array.isArray(t)||null===t?i(n):i(null==n?void 0:n[e]);var t}function r(e){return Array.from(new Set(e))}function s(e){return e?e.replace(/\/+$/,""):e}const g=e=>{let n=[];return Object.freeze({listen:e=>{const t=n=>{e(n)};return n.push(t),{unsubscribe:()=>{n=n.filter((e=>t!==e))}}},emit:t=>{e()&&n.forEach((e=>e({value:t})))}})},c=(e,n,t)=>{const a=new Set,o=new Set;let r=[];const s=()=>{if(0===r.length)return;const e=r;r=[],a.forEach((e=>{e({value:void 0})}));let t=new Set;e.forEach((e=>{void 0===e?t=void 0:void 0!==t&&e.forEach((e=>t.add(e)))}));(e=>{const t=new Set(n());o.forEach((n=>{(void 0===e||-1!==(null==e?void 0:e.findIndex((e=>t.has(e)||n.namespaces.has(e)))))&&n.fn({value:void 0})}))})(t?Array.from(t.keys()):void 0)};return Object.freeze({listenSome:e=>{const n={fn:n=>{e(n)},namespaces:new Set};o.add(n);const a={unsubscribe:()=>{o.delete(n)},subscribeNs:e=>(i(e).forEach((e=>n.namespaces.add(e))),void 0===e&&n.namespaces.add(t()),a)};return a},listen:e=>{a.add(e);return{unsubscribe:()=>{a.delete(e)}}},emit:(n,t)=>{e()&&(r.push(n),t?setTimeout(s,0):s())}})},u=e=>{const n=new Map;return Object.entries(e).forEach((([e,t])=>{null!=t&&("object"!=typeof t?n.set(e,t):u(t).forEach(((t,a)=>{n.set(e+"."+a,t)})))})),n},l=e=>{const[n,...t]=e.split(":");return{language:n,namespace:t.join(":")||""}},d=({language:e,namespace:n})=>n?`${e}:${n}`:e,f=(e,n,t,a,o,s,g)=>{const c=new Map,f=new Map;let p={},v=0;function h(n,t,a){const i=d(n);f.set(i,{data:u(t),version:a}),e.emit(n)}function b(e,n){h(e,n,v)}function m(e,n=!1){const t=f.get(d(e));return t&&n?t.version===v:Boolean(t)}function y(e){var n;return null===(n=f.get(d(a(e))))||void 0===n?void 0:n.data}function O(e){let t;if(!t){const n=p[d(e)];"function"==typeof n&&(t=n())}return t||(t=n(e)),t}return Object.freeze({addStaticData:function(e){e&&(p=Object.assign(Object.assign({},p),e),Object.entries(e).forEach((([e,n])=>{if("function"!=typeof n){const t=l(e),a=f.get(e);a&&0!==a.version||h(t,n,0)}})))},invalidate:function(){c.clear(),v+=1},addRecord:b,exists:m,getRecord:y,getTranslation:function(e,n){var t;return null===(t=f.get(d(e)))||void 0===t?void 0:t.data.get(n)},getTranslationNs:function(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=f.get(d({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return[i]}return r(e)},getTranslationFallback:function(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=f.get(d({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return n}},changeTranslation:function(n,t,a){var i;const o=null===(i=f.get(d(n)))||void 0===i?void 0:i.data;null==o||o.set(t,a),e.emit(Object.assign(Object.assign({},n),{key:t}))},isFetching:function(e){if(o())return!0;if(void 0===e)return c.size>0;const n=i(e);return Boolean(Array.from(c.keys()).find((e=>n.includes(l(e).namespace))))},isLoading:function(e,n){const t=i(n);return Boolean(o()||Array.from(c.keys()).find((n=>{const a=l(n);return(!t.length||t.includes(a.namespace))&&!m({namespace:a.namespace,language:e})})))},loadRecords:async function(e,n){const i=e.map((e=>{const i=a(e),o=d(i),r=c.get(o);if(r)return{new:!1,promise:r,keyObject:i,cacheKey:o};const s=function(e,n){var a;let i;return n&&(i=null===(a=t(e))||void 0===a?void 0:a.catch((()=>(console.warn("Tolgee: Failed to fetch data from dev backend"),O(e))))),i||(i=O(e)),i}(i,n)||Promise.resolve(void 0);return c.set(o,s),{new:!0,promise:s,keyObject:i,cacheKey:o}}));s.notify(),g.notify();const o=await Promise.all(i.map((e=>e.promise)));return i.forEach(((e,n)=>{const t=c.get(e.cacheKey)!==e.promise;if(e.new&&!t){c.delete(e.cacheKey);const t=o[n];t?b(e.keyObject,t):y(e.keyObject)||b(e.keyObject,{})}})),s.notify(),g.notify(),i.map((e=>y(e.keyObject)))},getAllRecords:function(){return Array.from(f.entries()).map((([e,n])=>Object.assign(Object.assign({},l(e)),{data:n.data})))}})};function p(e,n){var t={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&n.indexOf(a)<0&&(t[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(a=Object.getOwnPropertySymbols(e);i<a.length;i++)n.indexOf(a[i])<0&&Object.prototype.propertyIsEnumerable.call(e,a[i])&&(t[a[i]]=e[a[i]])}return t}const v="invalid",h={defaultNs:"",observerOptions:{tagAttributes:{textarea:["placeholder"],input:["value","placeholder"],img:["alt"],"*":["aria-label","title"]},restrictedElements:["script","style"],highlightKeys:["Alt"],highlightColor:"rgb(255, 0, 0)",highlightWidth:5,inputPrefix:"%-%tolgee:",inputSuffix:"%-%",passToParent:["option","optgroup"]},observerType:"invisible",onFormatError:v,apiUrl:"https://app.tolgee.io"},b=(...e)=>{let n={};return e.forEach((e=>{n=Object.assign(Object.assign(Object.assign({},n),e),{observerOptions:Object.assign(Object.assign({},n.observerOptions),null==e?void 0:e.observerOptions)})})),n},m=(e,n)=>{const t=b(h,null==n?void 0:n.initialOptions,e);return t.apiUrl=s(t.apiUrl),{initialOptions:t,activeNamespaces:(null==n?void 0:n.activeNamespaces)||new Map,language:null==n?void 0:n.language,pendingLanguage:null==n?void 0:n.language,isInitialLoading:!1,isRunning:!1}},y=(t,a,i,o,r,s)=>{const g={ui:void 0},c={formatters:[],finalFormatter:void 0,observer:void 0,devBackend:void 0,backends:[],ui:void 0,languageDetector:void 0,languageStorage:void 0},u=async({keysAndDefaults:e,event:n})=>{var t;const a=e.map((({key:e,ns:n,defaultValue:t})=>({key:e,defaultValue:t,ns:o({key:e,ns:n}),translation:r({key:e,ns:n})})));null===(t=c.ui)||void 0===t||t.handleElementClick(a,n)},l=(e,n)=>{var t,a;return(null===(a=null===(t=c.observer)||void 0===t?void 0:t.highlight)||void 0===a?void 0:a.call(t,e,n))||{unhighlight(){}}},d=(e,n)=>{var t;return(null===(t=c.observer)||void 0===t?void 0:t.findPositions(e,n))||[]},f=e=>{const n=r({key:e.key,ns:e.ns});return N(Object.assign(Object.assign({},e),{translation:n,formatEnabled:!0}))},h=e=>{c.observer=null==e?void 0:e()},b=()=>Boolean(c.observer),m=e=>{e&&c.formatters.push(e)},y=e=>{c.finalFormatter=e},O=e=>{g.ui=e},L=()=>Boolean(g.ui),j=e=>{c.languageStorage=e},k=e=>{c.languageDetector=e},w=e=>{e&&c.backends.push(e)},R=e=>{c.devBackend=e},E=()=>c.devBackend;function N(e){var n,{formatEnabled:i}=e,o=p(e,["formatEnabled"]);const{key:r,translation:s,defaultValue:g,noWrap:u,params:l,orEmpty:d,ns:f}=o,h=s||g;let b=h||(d?"":r);const m=t(),y=i||!(null===(n=c.observer)||void 0===n?void 0:n.outputNotFormattable),O=e=>c.observer&&!u?c.observer.wrap({key:r,translation:e,defaultValue:g,params:l,ns:f}):e;b=O(b);try{if(h&&m&&y)for(const e of c.formatters)b=e.format({translation:b,language:m,params:l});c.finalFormatter&&h&&m&&y&&(b=c.finalFormatter.format({translation:b,language:m,params:l}))}catch(e){console.error(e);const n=("string"==typeof(L=e)?L:"string"==typeof(null==L?void 0:L.message)?L.message:void 0)||v,t=a().onFormatError,i=typeof t;b="string"===i?t:"function"===i?t(n,o):v,b=O(b)}var L;return b}return Object.freeze({addPlugin:function(e,n){n(e,Object.freeze({setFinalFormatter:y,addFormatter:m,setObserver:h,hasObserver:b,setUi:O,hasUi:L,setDevBackend:R,addBackend:w,setLanguageDetector:k,setLanguageStorage:j}))},formatTranslation:N,getDevBackend:E,getBackendRecord:({language:n,namespace:t})=>{for(const a of c.backends){const i=a.getRecord({language:n,namespace:t});if(e(i))return null==i?void 0:i.catch((e=>(console.error(e),{})));if(void 0!==i)return i}},getBackendDevRecord:({language:e,namespace:n})=>{var t;const{apiKey:i,apiUrl:o,projectId:r}=a();return null===(t=c.devBackend)||void 0===t?void 0:t.getRecord({apiKey:i,apiUrl:o,projectId:r,language:e,namespace:n})},getLanguageDetector:()=>c.languageDetector,getLanguageStorage:()=>c.languageStorage,getInitialLanguage:()=>{var e;const t=i(),a=null===(e=c.languageStorage)||void 0===e?void 0:e.getLanguage();return n(a,(e=>t&&!t.includes(e)||!e?(()=>{if(!c.languageDetector)return;const e=i();return c.languageDetector.getLanguage({availableLanguages:e})})():e))},setStoredLanguage:e=>{var n;null===(n=c.languageStorage)||void 0===n||n.setLanguage(e)},run:()=>{var e,n;const{apiKey:t,apiUrl:i,projectId:o,observerOptions:r}=a();c.ui=null===(e=g.ui)||void 0===e?void 0:e.call(g,{apiKey:t,apiUrl:i,projectId:o,highlight:l,changeTranslation:s,findPositions:d}),null===(n=c.observer)||void 0===n||n.run({mouseHighlight:!0,options:r,translate:f,onClick:u})},stop:()=>{var e;c.ui=void 0,null===(e=c.observer)||void 0===e||e.stop()},retranslate:()=>{var e;null===(e=c.observer)||void 0===e||e.retranslate()},highlight:l,unwrap:e=>{var n;return c.observer?null===(n=c.observer)||void 0===n?void 0:n.unwrap(e):{text:e,keys:[]}},wrap:e=>{var n;return c.observer?null===(n=c.observer)||void 0===n?void 0:n.wrap(e):e.translation},hasDevBackend:function(){return Boolean(E())}})},O=(e,n,t)=>{let a=e;return Object.freeze({init:function(e){a=e},notify:function(){const e=n();a!==e&&t(e),a=e}})};const L=(e,...n)=>{let t,a={};return"object"==typeof e?a=e:(a.key=e,"string"==typeof n[0]?(a.defaultValue=n[0],t=n[1]):"object"==typeof n[0]&&(t=n[0])),t&&(a=Object.assign(Object.assign({},function(e){var{ns:n,noWrap:t,orEmpty:a,params:i,language:o}=e,r=p(e,["ns","noWrap","orEmpty","params","language"]);const s={ns:n,noWrap:t,orEmpty:a,language:o};return Object.assign(Object.assign({},s),{params:Object.assign({},r)})}(t)),a)),a},j=({options:a})=>{const u=((e,n)=>{let t=!0;function a(){return t}const i=g(a),o=g(a),r=g(a),s=g(a),u=g(a),l=g(a),d=g(a),f=c(a,e,n);return u.listen((()=>f.emit())),o.listen((()=>f.emit())),d.listen((({value:e})=>{f.emit([e.namespace],!0)})),Object.freeze({onPendingLanguageChange:i,onLanguageChange:o,onLoadingChange:r,onFetchingChange:s,onInitialLoaded:u,onRunningChange:l,onCacheChange:d,onUpdate:f,setEmitterActive:function(e){t=e},on:(e,n)=>{switch(e){case"pendingLanguage":return i.listen(n);case"language":return o.listen(n);case"loading":return r.listen(n);case"fetching":return s.listen(n);case"initialLoad":return u.listen(n);case"running":return l.listen(n);case"cache":return d.listen(n);case"update":return f.listen(n)}}})})(j,k),d=O(!1,(()=>b.isFetching()),u.onFetchingChange.emit),p=O(!1,(()=>A()),u.onLoadingChange.emit),v=((e,n,t)=>{let a,g=m();function c(){return g.language||g.initialOptions.language}function u(){return Object.assign(Object.assign({},g.initialOptions),a)}return Object.freeze({init:function(e){g=m(e,g)},isRunning:function(){return g.isRunning},setRunning:function(e){g.isRunning!==e&&(g.isRunning=e,t.emit(e))},isInitialLoading:function(){return g.isInitialLoading},setInitialLoading:function(e){g.isInitialLoading=e},getLanguage:c,setLanguage:function(n){g.language!==n&&(g.language=n,e.emit(n))},getPendingLanguage:function(){return g.pendingLanguage||c()},setPendingLanguage:function(e){g.pendingLanguage!==e&&(g.pendingLanguage=e,n.emit(e))},getInitialOptions:u,addActiveNs:function(e){i(e).forEach((e=>{const n=g.activeNamespaces.get(e);void 0!==n?g.activeNamespaces.set(e,n+1):g.activeNamespaces.set(e,1)}))},removeActiveNs:function(e){i(e).forEach((e=>{const n=g.activeNamespaces.get(e);void 0!==n&&n>1?g.activeNamespaces.set(e,n-1):g.activeNamespaces.delete(e)}))},getRequiredNamespaces:function(){return r([...g.initialOptions.ns||[g.initialOptions.defaultNs],...i(g.initialOptions.fallbackNs),...g.activeNamespaces.keys()])},getFallbackLangs:function(e){const n=e||c();return n?r([n,...o(n,g.initialOptions.fallbackLanguage)]):[]},getFallbackNs:function(){return i(g.initialOptions.fallbackNs)},getDefaultNs:function(e){return void 0===e?g.initialOptions.defaultNs:e},getAvailableLanguages:function(){if(g.initialOptions.availableLanguages)return g.initialOptions.availableLanguages;if(g.initialOptions.staticData){const e=Object.keys(g.initialOptions.staticData).map((e=>l(e).language));return Array.from(new Set(e))}},withDefaultNs:function(e){return{namespace:void 0===e.namespace?u().defaultNs:e.namespace,language:e.language}},overrideCredentials:function(e){a=e?Object.assign(Object.assign({},e),{apiUrl:s(e.apiUrl)}):void 0}})})(u.onLanguageChange,u.onPendingLanguageChange,u.onRunningChange),h=y(v.getLanguage,v.getInitialOptions,v.getAvailableLanguages,(function({key:e,ns:n}){const t=v.getFallbackLangs(),a=w(n||void 0);return b.getTranslationNs(a,t,e)}),D,E),b=f(u.onCacheChange,h.getBackendRecord,h.getBackendDevRecord,v.withDefaultNs,v.isInitialLoading,d,p);function j(){return v.getFallbackNs()}function k(e){return v.getDefaultNs(e)}function w(e){return[...i(k(e)),...j()]}function R(e){return[...i(e||k()),...v.getRequiredNamespaces()]}function E(e,n,t){const a=v.withDefaultNs(e),i=b.getTranslation(a,n);return b.changeTranslation(a,n,t),{revert:()=>{b.changeTranslation(a,n,i)}}}function N(e){v.init(e),b.addStaticData(v.getInitialOptions().staticData)}function A(e){return b.isLoading(v.getLanguage(),e)}function F(){return Boolean(v.getInitialOptions().apiKey&&v.getInitialOptions().apiUrl)}function I(e,t){const a=function(e,n){const t=v.getFallbackLangs(e),a=R(n),i=[];return t.forEach((e=>{a.forEach((n=>{b.exists({language:e,namespace:n},!0)||i.push({language:e,namespace:n})}))})),i}(e,t);if(a.length)return n(P(a),(()=>{}))}function D({key:e,ns:n,language:t}){const a=w(n||void 0),i=v.getFallbackLangs(t);return b.getTranslationFallback(a,i,e)}function S(){const a=n(function(){if(v.getLanguage())return;if(!v.getInitialOptions().defaultLanguage)throw new Error(t("defaultLanguage"));const e=h.getInitialLanguage();return n(e,(e=>{const n=e||v.getInitialOptions().defaultLanguage;n&&v.setLanguage(n)}))}(),(()=>I()));if(e(a))return v.setInitialLoading(!0),d.notify(),p.notify(),Promise.resolve(a).then((()=>{v.setInitialLoading(!1),d.notify(),p.notify(),u.onInitialLoaded.emit()}));u.onInitialLoaded.emit()}function P(e){return b.loadRecords(e,F())}a&&N(a),u.onUpdate.listen((()=>{v.isRunning()&&h.retranslate()}));const T=()=>{const e=h.getLanguageDetector()||h.getLanguageStorage();if(e){if(!v.getAvailableLanguages())throw new Error(t("availableLanguages"))}if(!v.getLanguage()&&!v.getInitialOptions().defaultLanguage)throw e?new Error(t("defaultLanguage")):new Error(t("language"))};return Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},u),v),h),b),{init:N,changeLanguage:async function(e){v.getPendingLanguage()===e&&v.getLanguage()===e||(v.setPendingLanguage(e),v.isRunning()&&await I(e),e===v.getPendingLanguage()&&(v.setLanguage(e),h.setStoredLanguage(e)))},getTranslation:D,changeTranslation:E,addActiveNs:async function(e,n){n||v.addActiveNs(e),v.isRunning()&&await I(void 0,e)},loadRecords:P,loadRecord:async function(e){return(await P([e]))[0]},isLoading:A,isLoaded:function(e){const n=v.getLanguage();if(!n)return!1;const t=v.getFallbackLangs(n),a=R(e),i=[];return t.forEach((e=>{a.forEach((n=>{b.exists({language:e,namespace:n})||i.push({language:e,namespace:n})}))})),0===i.length},t:(...e)=>{const n=L(...e),t=D(n);return h.formatTranslation(Object.assign(Object.assign({},n),{translation:t}))},isDev:F,run:function(){let e;return T(),v.isRunning()||(F()&&b.invalidate(),v.setRunning(!0),h.run(),e=S()),Promise.resolve(e)},stop:function(){v.isRunning()&&(h.stop(),v.setRunning(!1))}}))},k=0,w=1,R=2;class E extends Error{constructor(e,n,t){let a;a=e===k?"Empty parameter":e===w?"Unexpected character":"Unexpected end",super(`Tolgee parser: ${a} at ${n} in "${t}"`),this.code=e,this.index=n}}function N(e){return/\s/.test(e)}const A=0,F=1,I=2,D=3,S=4,P=new Set([I,F,A]),T="'",C=new Set(["{","}",T]),x=e=>/[0-9a-zA-Z_]/.test(e);function B(e,n){const[t,a]=function(e){let n=A,t="",a="",i="";const o=[],r=[];let s=0;function g(n){throw new E(n,s,e)}const c=()=>{o.push(t),t=""},u=()=>{""===a&&g(k),r.push(a),a=""};for(s=0;s<e.length;s++)switch(i=e[s],n){case A:i===T?(t+=i,n=F):"{"===i?(c(),n=D):(t+=i,n=A);break;case F:C.has(i)?(t=t.slice(0,-1)+i,n=I):(t+=i,n=A);break;case I:i===T?n=A:(t+=i,n=I);break;case D:"}"===i?(u(),n=A):N(i)?""!==a&&(u(),n=S):(x(i)||g(w),a+=i,n=D);break;case S:"}"==i?n=A:N(i)?n=S:g(w)}return P.has(n)||g(R),c(),[o,r]}(e),i=[t[0]];for(let o=1;o<t.length;o++){const r=null==n?void 0:n[a[o-1]];if(void 0===r)throw new Error(`Missing parameter "${a[o-1]}" in "${e}"`);i.push(String(r)),i.push(t[o])}return i.join("")}exports.FormatSimple=()=>(e,n)=>(n.setFinalFormatter({format:({translation:e,params:n})=>B(e,n)}),e),exports.TolgeeCore=()=>{const e={plugins:[],options:{}},n=Object.freeze({use:t=>(e.plugins.push(t),n),updateDefaults:t=>(e.options=b(e.options,t),n),init(n){const t=(e=>{const n=j({options:e}),t=e=>{const t=n.isRunning();t&&n.stop(),e(),t&&n.run()},a=Object.freeze({on:n.on,onNsUpdate:n.onUpdate.listenSome,setEmitterActive:n.setEmitterActive,getLanguage:n.getLanguage,getPendingLanguage:n.getPendingLanguage,changeLanguage:n.changeLanguage,changeTranslation:n.changeTranslation,addActiveNs:n.addActiveNs,removeActiveNs:n.removeActiveNs,loadRecords:n.loadRecords,loadRecord:n.loadRecord,addStaticData:n.addStaticData,getRecord:n.getRecord,getAllRecords:n.getAllRecords,isLoaded:n.isLoaded,isInitialLoading:n.isInitialLoading,isLoading:n.isLoading,isFetching:n.isFetching,isRunning:n.isRunning,run:n.run,stop:n.stop,t:n.t,highlight:n.highlight,getInitialOptions:n.getInitialOptions,isDev:n.isDev,wrap:n.wrap,unwrap:n.unwrap,overrideCredentials(e){t((()=>n.overrideCredentials(e)))},addPlugin(e){e&&t((()=>n.addPlugin(a,e)))},updateOptions(e){e&&t((()=>n.init(e)))}});return a})(b(e.options,n));return e.plugins.forEach(t.addPlugin),t}});return n},exports.getFallback=a,exports.getFallbackArray=i,exports.getTranslateProps=L;
//# sourceMappingURL=tolgee.cjs.min.js.map

@@ -958,3 +958,3 @@ function isPromise(value) {

function parseCombinedOptions(_a) {
var { ns, noWrap, orEmpty, params } = _a, rest = __rest(_a, ["ns", "noWrap", "orEmpty", "params"]);
var { ns, noWrap, orEmpty, params, language } = _a, rest = __rest(_a, ["ns", "noWrap", "orEmpty", "params", "language"]);
const options = {

@@ -964,2 +964,3 @@ ns: ns,

orEmpty: orEmpty,
language: language,
};

@@ -1109,5 +1110,5 @@ return Object.assign(Object.assign({}, options), { params: Object.assign({}, rest) });

}
function getTranslation({ key, ns }) {
function getTranslation({ key, ns, language }) {
const namespaces = getDefaultAndFallbackNs(ns || undefined);
const languages = state.getFallbackLangs();
const languages = state.getFallbackLangs(language);
return cache.getTranslationFallback(namespaces, languages, key);

@@ -1114,0 +1115,0 @@ }

@@ -1,2 +0,2 @@

function e(e){return Boolean(e&&"function"==typeof e.then)}const n=(n,t)=>e(n)?Promise.resolve(n).then(t):t(n),t=e=>`Tolgee: You need to specify '${e}' option`;function a(e){return"string"==typeof e?[e]:Array.isArray(e)?e:void 0}function i(e){return a(e)||[]}function o(e,n){return"object"!=typeof(t=n)||Array.isArray(t)||null===t?i(n):i(null==n?void 0:n[e]);var t}function r(e){return Array.from(new Set(e))}function s(e){return e?e.replace(/\/+$/,""):e}const c=e=>{let n=[];return Object.freeze({listen:e=>{const t=n=>{e(n)};return n.push(t),{unsubscribe:()=>{n=n.filter((e=>t!==e))}}},emit:t=>{e()&&n.forEach((e=>e({value:t})))}})},g=(e,n,t)=>{const a=new Set,o=new Set;let r=[];const s=()=>{if(0===r.length)return;const e=r;r=[],a.forEach((e=>{e({value:void 0})}));let t=new Set;e.forEach((e=>{void 0===e?t=void 0:void 0!==t&&e.forEach((e=>t.add(e)))}));(e=>{const t=new Set(n());o.forEach((n=>{(void 0===e||-1!==(null==e?void 0:e.findIndex((e=>t.has(e)||n.namespaces.has(e)))))&&n.fn({value:void 0})}))})(t?Array.from(t.keys()):void 0)};return Object.freeze({listenSome:e=>{const n={fn:n=>{e(n)},namespaces:new Set};o.add(n);const a={unsubscribe:()=>{o.delete(n)},subscribeNs:e=>(i(e).forEach((e=>n.namespaces.add(e))),void 0===e&&n.namespaces.add(t()),a)};return a},listen:e=>{a.add(e);return{unsubscribe:()=>{a.delete(e)}}},emit:(n,t)=>{e()&&(r.push(n),t?setTimeout(s,0):s())}})},u=e=>{const n=new Map;return Object.entries(e).forEach((([e,t])=>{null!=t&&("object"!=typeof t?n.set(e,t):u(t).forEach(((t,a)=>{n.set(e+"."+a,t)})))})),n},l=e=>{const[n,...t]=e.split(":");return{language:n,namespace:t.join(":")||""}},d=({language:e,namespace:n})=>n?`${e}:${n}`:e,f=(e,n,t,a,o,s,c)=>{const g=new Map,f=new Map;let p={},v=0;function h(n,t,a){const i=d(n);f.set(i,{data:u(t),version:a}),e.emit(n)}function b(e,n){h(e,n,v)}function m(e,n=!1){const t=f.get(d(e));return t&&n?t.version===v:Boolean(t)}function O(e){var n;return null===(n=f.get(d(a(e))))||void 0===n?void 0:n.data}function y(e){let t;if(!t){const n=p[d(e)];"function"==typeof n&&(t=n())}return t||(t=n(e)),t}return Object.freeze({addStaticData:function(e){e&&(p=Object.assign(Object.assign({},p),e),Object.entries(e).forEach((([e,n])=>{if("function"!=typeof n){const t=l(e),a=f.get(e);a&&0!==a.version||h(t,n,0)}})))},invalidate:function(){g.clear(),v+=1},addRecord:b,exists:m,getRecord:O,getTranslation:function(e,n){var t;return null===(t=f.get(d(e)))||void 0===t?void 0:t.data.get(n)},getTranslationNs:function(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=f.get(d({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return[i]}return r(e)},getTranslationFallback:function(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=f.get(d({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return n}},changeTranslation:function(n,t,a){var i;const o=null===(i=f.get(d(n)))||void 0===i?void 0:i.data;null==o||o.set(t,a),e.emit(Object.assign(Object.assign({},n),{key:t}))},isFetching:function(e){if(o())return!0;if(void 0===e)return g.size>0;const n=i(e);return Boolean(Array.from(g.keys()).find((e=>n.includes(l(e).namespace))))},isLoading:function(e,n){const t=i(n);return Boolean(o()||Array.from(g.keys()).find((n=>{const a=l(n);return(!t.length||t.includes(a.namespace))&&!m({namespace:a.namespace,language:e})})))},loadRecords:async function(e,n){const i=e.map((e=>{const i=a(e),o=d(i),r=g.get(o);if(r)return{new:!1,promise:r,keyObject:i,cacheKey:o};const s=function(e,n){var a;let i;return n&&(i=null===(a=t(e))||void 0===a?void 0:a.catch((()=>(console.warn("Tolgee: Failed to fetch data from dev backend"),y(e))))),i||(i=y(e)),i}(i,n)||Promise.resolve(void 0);return g.set(o,s),{new:!0,promise:s,keyObject:i,cacheKey:o}}));s.notify(),c.notify();const o=await Promise.all(i.map((e=>e.promise)));return i.forEach(((e,n)=>{const t=g.get(e.cacheKey)!==e.promise;if(e.new&&!t){g.delete(e.cacheKey);const t=o[n];t?b(e.keyObject,t):O(e.keyObject)||b(e.keyObject,{})}})),s.notify(),c.notify(),i.map((e=>O(e.keyObject)))},getAllRecords:function(){return Array.from(f.entries()).map((([e,n])=>Object.assign(Object.assign({},l(e)),{data:n.data})))}})};function p(e,n){var t={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&n.indexOf(a)<0&&(t[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(a=Object.getOwnPropertySymbols(e);i<a.length;i++)n.indexOf(a[i])<0&&Object.prototype.propertyIsEnumerable.call(e,a[i])&&(t[a[i]]=e[a[i]])}return t}const v="invalid",h={defaultNs:"",observerOptions:{tagAttributes:{textarea:["placeholder"],input:["value","placeholder"],img:["alt"],"*":["aria-label","title"]},restrictedElements:["script","style"],highlightKeys:["Alt"],highlightColor:"rgb(255, 0, 0)",highlightWidth:5,inputPrefix:"%-%tolgee:",inputSuffix:"%-%",passToParent:["option","optgroup"]},observerType:"invisible",onFormatError:v,apiUrl:"https://app.tolgee.io"},b=(...e)=>{let n={};return e.forEach((e=>{n=Object.assign(Object.assign(Object.assign({},n),e),{observerOptions:Object.assign(Object.assign({},n.observerOptions),null==e?void 0:e.observerOptions)})})),n},m=(e,n)=>{const t=b(h,null==n?void 0:n.initialOptions,e);return t.apiUrl=s(t.apiUrl),{initialOptions:t,activeNamespaces:(null==n?void 0:n.activeNamespaces)||new Map,language:null==n?void 0:n.language,pendingLanguage:null==n?void 0:n.language,isInitialLoading:!1,isRunning:!1}},O=(t,a,i,o,r,s)=>{const c={ui:void 0},g={formatters:[],finalFormatter:void 0,observer:void 0,devBackend:void 0,backends:[],ui:void 0,languageDetector:void 0,languageStorage:void 0},u=async({keysAndDefaults:e,event:n})=>{var t;const a=e.map((({key:e,ns:n,defaultValue:t})=>({key:e,defaultValue:t,ns:o({key:e,ns:n}),translation:r({key:e,ns:n})})));null===(t=g.ui)||void 0===t||t.handleElementClick(a,n)},l=(e,n)=>{var t,a;return(null===(a=null===(t=g.observer)||void 0===t?void 0:t.highlight)||void 0===a?void 0:a.call(t,e,n))||{unhighlight(){}}},d=(e,n)=>{var t;return(null===(t=g.observer)||void 0===t?void 0:t.findPositions(e,n))||[]},f=e=>{const n=r({key:e.key,ns:e.ns});return N(Object.assign(Object.assign({},e),{translation:n,formatEnabled:!0}))},h=e=>{g.observer=null==e?void 0:e()},b=()=>Boolean(g.observer),m=e=>{e&&g.formatters.push(e)},O=e=>{g.finalFormatter=e},y=e=>{c.ui=e},L=()=>Boolean(c.ui),j=e=>{g.languageStorage=e},k=e=>{g.languageDetector=e},w=e=>{e&&g.backends.push(e)},R=e=>{g.devBackend=e},E=()=>g.devBackend;function N(e){var n,{formatEnabled:i}=e,o=p(e,["formatEnabled"]);const{key:r,translation:s,defaultValue:c,noWrap:u,params:l,orEmpty:d,ns:f}=o,h=s||c;let b=h||(d?"":r);const m=t(),O=i||!(null===(n=g.observer)||void 0===n?void 0:n.outputNotFormattable),y=e=>g.observer&&!u?g.observer.wrap({key:r,translation:e,defaultValue:c,params:l,ns:f}):e;b=y(b);try{if(h&&m&&O)for(const e of g.formatters)b=e.format({translation:b,language:m,params:l});g.finalFormatter&&h&&m&&O&&(b=g.finalFormatter.format({translation:b,language:m,params:l}))}catch(e){console.error(e);const n=("string"==typeof(L=e)?L:"string"==typeof(null==L?void 0:L.message)?L.message:void 0)||v,t=a().onFormatError,i=typeof t;b="string"===i?t:"function"===i?t(n,o):v,b=y(b)}var L;return b}return Object.freeze({addPlugin:function(e,n){n(e,Object.freeze({setFinalFormatter:O,addFormatter:m,setObserver:h,hasObserver:b,setUi:y,hasUi:L,setDevBackend:R,addBackend:w,setLanguageDetector:k,setLanguageStorage:j}))},formatTranslation:N,getDevBackend:E,getBackendRecord:({language:n,namespace:t})=>{for(const a of g.backends){const i=a.getRecord({language:n,namespace:t});if(e(i))return null==i?void 0:i.catch((e=>(console.error(e),{})));if(void 0!==i)return i}},getBackendDevRecord:({language:e,namespace:n})=>{var t;const{apiKey:i,apiUrl:o,projectId:r}=a();return null===(t=g.devBackend)||void 0===t?void 0:t.getRecord({apiKey:i,apiUrl:o,projectId:r,language:e,namespace:n})},getLanguageDetector:()=>g.languageDetector,getLanguageStorage:()=>g.languageStorage,getInitialLanguage:()=>{var e;const t=i(),a=null===(e=g.languageStorage)||void 0===e?void 0:e.getLanguage();return n(a,(e=>t&&!t.includes(e)||!e?(()=>{if(!g.languageDetector)return;const e=i();return g.languageDetector.getLanguage({availableLanguages:e})})():e))},setStoredLanguage:e=>{var n;null===(n=g.languageStorage)||void 0===n||n.setLanguage(e)},run:()=>{var e,n;const{apiKey:t,apiUrl:i,projectId:o,observerOptions:r}=a();g.ui=null===(e=c.ui)||void 0===e?void 0:e.call(c,{apiKey:t,apiUrl:i,projectId:o,highlight:l,changeTranslation:s,findPositions:d}),null===(n=g.observer)||void 0===n||n.run({mouseHighlight:!0,options:r,translate:f,onClick:u})},stop:()=>{var e;g.ui=void 0,null===(e=g.observer)||void 0===e||e.stop()},retranslate:()=>{var e;null===(e=g.observer)||void 0===e||e.retranslate()},highlight:l,unwrap:e=>{var n;return g.observer?null===(n=g.observer)||void 0===n?void 0:n.unwrap(e):{text:e,keys:[]}},wrap:e=>{var n;return g.observer?null===(n=g.observer)||void 0===n?void 0:n.wrap(e):e.translation},hasDevBackend:function(){return Boolean(E())}})},y=(e,n,t)=>{let a=e;return Object.freeze({init:function(e){a=e},notify:function(){const e=n();a!==e&&t(e),a=e}})};const L=(e,...n)=>{let t,a={};return"object"==typeof e?a=e:(a.key=e,"string"==typeof n[0]?(a.defaultValue=n[0],t=n[1]):"object"==typeof n[0]&&(t=n[0])),t&&(a=Object.assign(Object.assign({},function(e){var{ns:n,noWrap:t,orEmpty:a,params:i}=e,o=p(e,["ns","noWrap","orEmpty","params"]);const r={ns:n,noWrap:t,orEmpty:a};return Object.assign(Object.assign({},r),{params:Object.assign({},o)})}(t)),a)),a},j=({options:a})=>{const u=((e,n)=>{let t=!0;function a(){return t}const i=c(a),o=c(a),r=c(a),s=c(a),u=c(a),l=c(a),d=c(a),f=g(a,e,n);return u.listen((()=>f.emit())),o.listen((()=>f.emit())),d.listen((({value:e})=>{f.emit([e.namespace],!0)})),Object.freeze({onPendingLanguageChange:i,onLanguageChange:o,onLoadingChange:r,onFetchingChange:s,onInitialLoaded:u,onRunningChange:l,onCacheChange:d,onUpdate:f,setEmitterActive:function(e){t=e},on:(e,n)=>{switch(e){case"pendingLanguage":return i.listen(n);case"language":return o.listen(n);case"loading":return r.listen(n);case"fetching":return s.listen(n);case"initialLoad":return u.listen(n);case"running":return l.listen(n);case"cache":return d.listen(n);case"update":return f.listen(n)}}})})(j,k),d=y(!1,(()=>b.isFetching()),u.onFetchingChange.emit),p=y(!1,(()=>A()),u.onLoadingChange.emit),v=((e,n,t)=>{let a,c=m();function g(){return c.language||c.initialOptions.language}function u(){return Object.assign(Object.assign({},c.initialOptions),a)}return Object.freeze({init:function(e){c=m(e,c)},isRunning:function(){return c.isRunning},setRunning:function(e){c.isRunning!==e&&(c.isRunning=e,t.emit(e))},isInitialLoading:function(){return c.isInitialLoading},setInitialLoading:function(e){c.isInitialLoading=e},getLanguage:g,setLanguage:function(n){c.language!==n&&(c.language=n,e.emit(n))},getPendingLanguage:function(){return c.pendingLanguage||g()},setPendingLanguage:function(e){c.pendingLanguage!==e&&(c.pendingLanguage=e,n.emit(e))},getInitialOptions:u,addActiveNs:function(e){i(e).forEach((e=>{const n=c.activeNamespaces.get(e);void 0!==n?c.activeNamespaces.set(e,n+1):c.activeNamespaces.set(e,1)}))},removeActiveNs:function(e){i(e).forEach((e=>{const n=c.activeNamespaces.get(e);void 0!==n&&n>1?c.activeNamespaces.set(e,n-1):c.activeNamespaces.delete(e)}))},getRequiredNamespaces:function(){return r([...c.initialOptions.ns||[c.initialOptions.defaultNs],...i(c.initialOptions.fallbackNs),...c.activeNamespaces.keys()])},getFallbackLangs:function(e){const n=e||g();return n?r([n,...o(n,c.initialOptions.fallbackLanguage)]):[]},getFallbackNs:function(){return i(c.initialOptions.fallbackNs)},getDefaultNs:function(e){return void 0===e?c.initialOptions.defaultNs:e},getAvailableLanguages:function(){if(c.initialOptions.availableLanguages)return c.initialOptions.availableLanguages;if(c.initialOptions.staticData){const e=Object.keys(c.initialOptions.staticData).map((e=>l(e).language));return Array.from(new Set(e))}},withDefaultNs:function(e){return{namespace:void 0===e.namespace?u().defaultNs:e.namespace,language:e.language}},overrideCredentials:function(e){a=e?Object.assign(Object.assign({},e),{apiUrl:s(e.apiUrl)}):void 0}})})(u.onLanguageChange,u.onPendingLanguageChange,u.onRunningChange),h=O(v.getLanguage,v.getInitialOptions,v.getAvailableLanguages,(function({key:e,ns:n}){const t=v.getFallbackLangs(),a=w(n||void 0);return b.getTranslationNs(a,t,e)}),S,E),b=f(u.onCacheChange,h.getBackendRecord,h.getBackendDevRecord,v.withDefaultNs,v.isInitialLoading,d,p);function j(){return v.getFallbackNs()}function k(e){return v.getDefaultNs(e)}function w(e){return[...i(k(e)),...j()]}function R(e){return[...i(e||k()),...v.getRequiredNamespaces()]}function E(e,n,t){const a=v.withDefaultNs(e),i=b.getTranslation(a,n);return b.changeTranslation(a,n,t),{revert:()=>{b.changeTranslation(a,n,i)}}}function N(e){v.init(e),b.addStaticData(v.getInitialOptions().staticData)}function A(e){return b.isLoading(v.getLanguage(),e)}function I(){return Boolean(v.getInitialOptions().apiKey&&v.getInitialOptions().apiUrl)}function D(e,t){const a=function(e,n){const t=v.getFallbackLangs(e),a=R(n),i=[];return t.forEach((e=>{a.forEach((n=>{b.exists({language:e,namespace:n},!0)||i.push({language:e,namespace:n})}))})),i}(e,t);if(a.length)return n(P(a),(()=>{}))}function S({key:e,ns:n}){const t=w(n||void 0),a=v.getFallbackLangs();return b.getTranslationFallback(t,a,e)}function F(){const a=n(function(){if(v.getLanguage())return;if(!v.getInitialOptions().defaultLanguage)throw new Error(t("defaultLanguage"));const e=h.getInitialLanguage();return n(e,(e=>{const n=e||v.getInitialOptions().defaultLanguage;n&&v.setLanguage(n)}))}(),(()=>D()));if(e(a))return v.setInitialLoading(!0),d.notify(),p.notify(),Promise.resolve(a).then((()=>{v.setInitialLoading(!1),d.notify(),p.notify(),u.onInitialLoaded.emit()}));u.onInitialLoaded.emit()}function P(e){return b.loadRecords(e,I())}a&&N(a),u.onUpdate.listen((()=>{v.isRunning()&&h.retranslate()}));const T=()=>{const e=h.getLanguageDetector()||h.getLanguageStorage();if(e){if(!v.getAvailableLanguages())throw new Error(t("availableLanguages"))}if(!v.getLanguage()&&!v.getInitialOptions().defaultLanguage)throw e?new Error(t("defaultLanguage")):new Error(t("language"))};return Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},u),v),h),b),{init:N,changeLanguage:async function(e){v.getPendingLanguage()===e&&v.getLanguage()===e||(v.setPendingLanguage(e),v.isRunning()&&await D(e),e===v.getPendingLanguage()&&(v.setLanguage(e),h.setStoredLanguage(e)))},getTranslation:S,changeTranslation:E,addActiveNs:async function(e,n){n||v.addActiveNs(e),v.isRunning()&&await D(void 0,e)},loadRecords:P,loadRecord:async function(e){return(await P([e]))[0]},isLoading:A,isLoaded:function(e){const n=v.getLanguage();if(!n)return!1;const t=v.getFallbackLangs(n),a=R(e),i=[];return t.forEach((e=>{a.forEach((n=>{b.exists({language:e,namespace:n})||i.push({language:e,namespace:n})}))})),0===i.length},t:(...e)=>{const n=L(...e),t=S(n);return h.formatTranslation(Object.assign(Object.assign({},n),{translation:t}))},isDev:I,run:function(){let e;return T(),v.isRunning()||(I()&&b.invalidate(),v.setRunning(!0),h.run(),e=F()),Promise.resolve(e)},stop:function(){v.isRunning()&&(h.stop(),v.setRunning(!1))}}))},k=()=>{const e={plugins:[],options:{}},n=Object.freeze({use:t=>(e.plugins.push(t),n),updateDefaults:t=>(e.options=b(e.options,t),n),init(n){const t=(e=>{const n=j({options:e}),t=e=>{const t=n.isRunning();t&&n.stop(),e(),t&&n.run()},a=Object.freeze({on:n.on,onNsUpdate:n.onUpdate.listenSome,setEmitterActive:n.setEmitterActive,getLanguage:n.getLanguage,getPendingLanguage:n.getPendingLanguage,changeLanguage:n.changeLanguage,changeTranslation:n.changeTranslation,addActiveNs:n.addActiveNs,removeActiveNs:n.removeActiveNs,loadRecords:n.loadRecords,loadRecord:n.loadRecord,addStaticData:n.addStaticData,getRecord:n.getRecord,getAllRecords:n.getAllRecords,isLoaded:n.isLoaded,isInitialLoading:n.isInitialLoading,isLoading:n.isLoading,isFetching:n.isFetching,isRunning:n.isRunning,run:n.run,stop:n.stop,t:n.t,highlight:n.highlight,getInitialOptions:n.getInitialOptions,isDev:n.isDev,wrap:n.wrap,unwrap:n.unwrap,overrideCredentials(e){t((()=>n.overrideCredentials(e)))},addPlugin(e){e&&t((()=>n.addPlugin(a,e)))},updateOptions(e){e&&t((()=>n.init(e)))}});return a})(b(e.options,n));return e.plugins.forEach(t.addPlugin),t}});return n},w=0,R=1,E=2;class N extends Error{constructor(e,n,t){let a;a=e===w?"Empty parameter":e===R?"Unexpected character":"Unexpected end",super(`Tolgee parser: ${a} at ${n} in "${t}"`),this.code=e,this.index=n}}function A(e){return/\s/.test(e)}const I=0,D=1,S=2,F=3,P=4,T=new Set([S,D,I]),B="'",C=new Set(["{","}",B]),U=e=>/[0-9a-zA-Z_]/.test(e);function x(e,n){const[t,a]=function(e){let n=I,t="",a="",i="";const o=[],r=[];let s=0;function c(n){throw new N(n,s,e)}const g=()=>{o.push(t),t=""},u=()=>{""===a&&c(w),r.push(a),a=""};for(s=0;s<e.length;s++)switch(i=e[s],n){case I:i===B?(t+=i,n=D):"{"===i?(g(),n=F):(t+=i,n=I);break;case D:C.has(i)?(t=t.slice(0,-1)+i,n=S):(t+=i,n=I);break;case S:i===B?n=I:(t+=i,n=S);break;case F:"}"===i?(u(),n=I):A(i)?""!==a&&(u(),n=P):(U(i)||c(R),a+=i,n=F);break;case P:"}"==i?n=I:A(i)?n=P:c(R)}return T.has(n)||c(E),g(),[o,r]}(e),i=[t[0]];for(let o=1;o<t.length;o++){const r=null==n?void 0:n[a[o-1]];if(void 0===r)throw new Error(`Missing parameter "${a[o-1]}" in "${e}"`);i.push(String(r)),i.push(t[o])}return i.join("")}const z=()=>(e,n)=>(n.setFinalFormatter({format:({translation:e,params:n})=>x(e,n)}),e);export{z as FormatSimple,k as TolgeeCore,a as getFallback,i as getFallbackArray,L as getTranslateProps};
function e(e){return Boolean(e&&"function"==typeof e.then)}const n=(n,t)=>e(n)?Promise.resolve(n).then(t):t(n),t=e=>`Tolgee: You need to specify '${e}' option`;function a(e){return"string"==typeof e?[e]:Array.isArray(e)?e:void 0}function i(e){return a(e)||[]}function o(e,n){return"object"!=typeof(t=n)||Array.isArray(t)||null===t?i(n):i(null==n?void 0:n[e]);var t}function r(e){return Array.from(new Set(e))}function s(e){return e?e.replace(/\/+$/,""):e}const g=e=>{let n=[];return Object.freeze({listen:e=>{const t=n=>{e(n)};return n.push(t),{unsubscribe:()=>{n=n.filter((e=>t!==e))}}},emit:t=>{e()&&n.forEach((e=>e({value:t})))}})},c=(e,n,t)=>{const a=new Set,o=new Set;let r=[];const s=()=>{if(0===r.length)return;const e=r;r=[],a.forEach((e=>{e({value:void 0})}));let t=new Set;e.forEach((e=>{void 0===e?t=void 0:void 0!==t&&e.forEach((e=>t.add(e)))}));(e=>{const t=new Set(n());o.forEach((n=>{(void 0===e||-1!==(null==e?void 0:e.findIndex((e=>t.has(e)||n.namespaces.has(e)))))&&n.fn({value:void 0})}))})(t?Array.from(t.keys()):void 0)};return Object.freeze({listenSome:e=>{const n={fn:n=>{e(n)},namespaces:new Set};o.add(n);const a={unsubscribe:()=>{o.delete(n)},subscribeNs:e=>(i(e).forEach((e=>n.namespaces.add(e))),void 0===e&&n.namespaces.add(t()),a)};return a},listen:e=>{a.add(e);return{unsubscribe:()=>{a.delete(e)}}},emit:(n,t)=>{e()&&(r.push(n),t?setTimeout(s,0):s())}})},u=e=>{const n=new Map;return Object.entries(e).forEach((([e,t])=>{null!=t&&("object"!=typeof t?n.set(e,t):u(t).forEach(((t,a)=>{n.set(e+"."+a,t)})))})),n},l=e=>{const[n,...t]=e.split(":");return{language:n,namespace:t.join(":")||""}},d=({language:e,namespace:n})=>n?`${e}:${n}`:e,f=(e,n,t,a,o,s,g)=>{const c=new Map,f=new Map;let p={},v=0;function h(n,t,a){const i=d(n);f.set(i,{data:u(t),version:a}),e.emit(n)}function b(e,n){h(e,n,v)}function m(e,n=!1){const t=f.get(d(e));return t&&n?t.version===v:Boolean(t)}function O(e){var n;return null===(n=f.get(d(a(e))))||void 0===n?void 0:n.data}function y(e){let t;if(!t){const n=p[d(e)];"function"==typeof n&&(t=n())}return t||(t=n(e)),t}return Object.freeze({addStaticData:function(e){e&&(p=Object.assign(Object.assign({},p),e),Object.entries(e).forEach((([e,n])=>{if("function"!=typeof n){const t=l(e),a=f.get(e);a&&0!==a.version||h(t,n,0)}})))},invalidate:function(){c.clear(),v+=1},addRecord:b,exists:m,getRecord:O,getTranslation:function(e,n){var t;return null===(t=f.get(d(e)))||void 0===t?void 0:t.data.get(n)},getTranslationNs:function(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=f.get(d({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return[i]}return r(e)},getTranslationFallback:function(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=f.get(d({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return n}},changeTranslation:function(n,t,a){var i;const o=null===(i=f.get(d(n)))||void 0===i?void 0:i.data;null==o||o.set(t,a),e.emit(Object.assign(Object.assign({},n),{key:t}))},isFetching:function(e){if(o())return!0;if(void 0===e)return c.size>0;const n=i(e);return Boolean(Array.from(c.keys()).find((e=>n.includes(l(e).namespace))))},isLoading:function(e,n){const t=i(n);return Boolean(o()||Array.from(c.keys()).find((n=>{const a=l(n);return(!t.length||t.includes(a.namespace))&&!m({namespace:a.namespace,language:e})})))},loadRecords:async function(e,n){const i=e.map((e=>{const i=a(e),o=d(i),r=c.get(o);if(r)return{new:!1,promise:r,keyObject:i,cacheKey:o};const s=function(e,n){var a;let i;return n&&(i=null===(a=t(e))||void 0===a?void 0:a.catch((()=>(console.warn("Tolgee: Failed to fetch data from dev backend"),y(e))))),i||(i=y(e)),i}(i,n)||Promise.resolve(void 0);return c.set(o,s),{new:!0,promise:s,keyObject:i,cacheKey:o}}));s.notify(),g.notify();const o=await Promise.all(i.map((e=>e.promise)));return i.forEach(((e,n)=>{const t=c.get(e.cacheKey)!==e.promise;if(e.new&&!t){c.delete(e.cacheKey);const t=o[n];t?b(e.keyObject,t):O(e.keyObject)||b(e.keyObject,{})}})),s.notify(),g.notify(),i.map((e=>O(e.keyObject)))},getAllRecords:function(){return Array.from(f.entries()).map((([e,n])=>Object.assign(Object.assign({},l(e)),{data:n.data})))}})};function p(e,n){var t={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&n.indexOf(a)<0&&(t[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(a=Object.getOwnPropertySymbols(e);i<a.length;i++)n.indexOf(a[i])<0&&Object.prototype.propertyIsEnumerable.call(e,a[i])&&(t[a[i]]=e[a[i]])}return t}const v="invalid",h={defaultNs:"",observerOptions:{tagAttributes:{textarea:["placeholder"],input:["value","placeholder"],img:["alt"],"*":["aria-label","title"]},restrictedElements:["script","style"],highlightKeys:["Alt"],highlightColor:"rgb(255, 0, 0)",highlightWidth:5,inputPrefix:"%-%tolgee:",inputSuffix:"%-%",passToParent:["option","optgroup"]},observerType:"invisible",onFormatError:v,apiUrl:"https://app.tolgee.io"},b=(...e)=>{let n={};return e.forEach((e=>{n=Object.assign(Object.assign(Object.assign({},n),e),{observerOptions:Object.assign(Object.assign({},n.observerOptions),null==e?void 0:e.observerOptions)})})),n},m=(e,n)=>{const t=b(h,null==n?void 0:n.initialOptions,e);return t.apiUrl=s(t.apiUrl),{initialOptions:t,activeNamespaces:(null==n?void 0:n.activeNamespaces)||new Map,language:null==n?void 0:n.language,pendingLanguage:null==n?void 0:n.language,isInitialLoading:!1,isRunning:!1}},O=(t,a,i,o,r,s)=>{const g={ui:void 0},c={formatters:[],finalFormatter:void 0,observer:void 0,devBackend:void 0,backends:[],ui:void 0,languageDetector:void 0,languageStorage:void 0},u=async({keysAndDefaults:e,event:n})=>{var t;const a=e.map((({key:e,ns:n,defaultValue:t})=>({key:e,defaultValue:t,ns:o({key:e,ns:n}),translation:r({key:e,ns:n})})));null===(t=c.ui)||void 0===t||t.handleElementClick(a,n)},l=(e,n)=>{var t,a;return(null===(a=null===(t=c.observer)||void 0===t?void 0:t.highlight)||void 0===a?void 0:a.call(t,e,n))||{unhighlight(){}}},d=(e,n)=>{var t;return(null===(t=c.observer)||void 0===t?void 0:t.findPositions(e,n))||[]},f=e=>{const n=r({key:e.key,ns:e.ns});return N(Object.assign(Object.assign({},e),{translation:n,formatEnabled:!0}))},h=e=>{c.observer=null==e?void 0:e()},b=()=>Boolean(c.observer),m=e=>{e&&c.formatters.push(e)},O=e=>{c.finalFormatter=e},y=e=>{g.ui=e},L=()=>Boolean(g.ui),j=e=>{c.languageStorage=e},k=e=>{c.languageDetector=e},w=e=>{e&&c.backends.push(e)},R=e=>{c.devBackend=e},E=()=>c.devBackend;function N(e){var n,{formatEnabled:i}=e,o=p(e,["formatEnabled"]);const{key:r,translation:s,defaultValue:g,noWrap:u,params:l,orEmpty:d,ns:f}=o,h=s||g;let b=h||(d?"":r);const m=t(),O=i||!(null===(n=c.observer)||void 0===n?void 0:n.outputNotFormattable),y=e=>c.observer&&!u?c.observer.wrap({key:r,translation:e,defaultValue:g,params:l,ns:f}):e;b=y(b);try{if(h&&m&&O)for(const e of c.formatters)b=e.format({translation:b,language:m,params:l});c.finalFormatter&&h&&m&&O&&(b=c.finalFormatter.format({translation:b,language:m,params:l}))}catch(e){console.error(e);const n=("string"==typeof(L=e)?L:"string"==typeof(null==L?void 0:L.message)?L.message:void 0)||v,t=a().onFormatError,i=typeof t;b="string"===i?t:"function"===i?t(n,o):v,b=y(b)}var L;return b}return Object.freeze({addPlugin:function(e,n){n(e,Object.freeze({setFinalFormatter:O,addFormatter:m,setObserver:h,hasObserver:b,setUi:y,hasUi:L,setDevBackend:R,addBackend:w,setLanguageDetector:k,setLanguageStorage:j}))},formatTranslation:N,getDevBackend:E,getBackendRecord:({language:n,namespace:t})=>{for(const a of c.backends){const i=a.getRecord({language:n,namespace:t});if(e(i))return null==i?void 0:i.catch((e=>(console.error(e),{})));if(void 0!==i)return i}},getBackendDevRecord:({language:e,namespace:n})=>{var t;const{apiKey:i,apiUrl:o,projectId:r}=a();return null===(t=c.devBackend)||void 0===t?void 0:t.getRecord({apiKey:i,apiUrl:o,projectId:r,language:e,namespace:n})},getLanguageDetector:()=>c.languageDetector,getLanguageStorage:()=>c.languageStorage,getInitialLanguage:()=>{var e;const t=i(),a=null===(e=c.languageStorage)||void 0===e?void 0:e.getLanguage();return n(a,(e=>t&&!t.includes(e)||!e?(()=>{if(!c.languageDetector)return;const e=i();return c.languageDetector.getLanguage({availableLanguages:e})})():e))},setStoredLanguage:e=>{var n;null===(n=c.languageStorage)||void 0===n||n.setLanguage(e)},run:()=>{var e,n;const{apiKey:t,apiUrl:i,projectId:o,observerOptions:r}=a();c.ui=null===(e=g.ui)||void 0===e?void 0:e.call(g,{apiKey:t,apiUrl:i,projectId:o,highlight:l,changeTranslation:s,findPositions:d}),null===(n=c.observer)||void 0===n||n.run({mouseHighlight:!0,options:r,translate:f,onClick:u})},stop:()=>{var e;c.ui=void 0,null===(e=c.observer)||void 0===e||e.stop()},retranslate:()=>{var e;null===(e=c.observer)||void 0===e||e.retranslate()},highlight:l,unwrap:e=>{var n;return c.observer?null===(n=c.observer)||void 0===n?void 0:n.unwrap(e):{text:e,keys:[]}},wrap:e=>{var n;return c.observer?null===(n=c.observer)||void 0===n?void 0:n.wrap(e):e.translation},hasDevBackend:function(){return Boolean(E())}})},y=(e,n,t)=>{let a=e;return Object.freeze({init:function(e){a=e},notify:function(){const e=n();a!==e&&t(e),a=e}})};const L=(e,...n)=>{let t,a={};return"object"==typeof e?a=e:(a.key=e,"string"==typeof n[0]?(a.defaultValue=n[0],t=n[1]):"object"==typeof n[0]&&(t=n[0])),t&&(a=Object.assign(Object.assign({},function(e){var{ns:n,noWrap:t,orEmpty:a,params:i,language:o}=e,r=p(e,["ns","noWrap","orEmpty","params","language"]);const s={ns:n,noWrap:t,orEmpty:a,language:o};return Object.assign(Object.assign({},s),{params:Object.assign({},r)})}(t)),a)),a},j=({options:a})=>{const u=((e,n)=>{let t=!0;function a(){return t}const i=g(a),o=g(a),r=g(a),s=g(a),u=g(a),l=g(a),d=g(a),f=c(a,e,n);return u.listen((()=>f.emit())),o.listen((()=>f.emit())),d.listen((({value:e})=>{f.emit([e.namespace],!0)})),Object.freeze({onPendingLanguageChange:i,onLanguageChange:o,onLoadingChange:r,onFetchingChange:s,onInitialLoaded:u,onRunningChange:l,onCacheChange:d,onUpdate:f,setEmitterActive:function(e){t=e},on:(e,n)=>{switch(e){case"pendingLanguage":return i.listen(n);case"language":return o.listen(n);case"loading":return r.listen(n);case"fetching":return s.listen(n);case"initialLoad":return u.listen(n);case"running":return l.listen(n);case"cache":return d.listen(n);case"update":return f.listen(n)}}})})(j,k),d=y(!1,(()=>b.isFetching()),u.onFetchingChange.emit),p=y(!1,(()=>A()),u.onLoadingChange.emit),v=((e,n,t)=>{let a,g=m();function c(){return g.language||g.initialOptions.language}function u(){return Object.assign(Object.assign({},g.initialOptions),a)}return Object.freeze({init:function(e){g=m(e,g)},isRunning:function(){return g.isRunning},setRunning:function(e){g.isRunning!==e&&(g.isRunning=e,t.emit(e))},isInitialLoading:function(){return g.isInitialLoading},setInitialLoading:function(e){g.isInitialLoading=e},getLanguage:c,setLanguage:function(n){g.language!==n&&(g.language=n,e.emit(n))},getPendingLanguage:function(){return g.pendingLanguage||c()},setPendingLanguage:function(e){g.pendingLanguage!==e&&(g.pendingLanguage=e,n.emit(e))},getInitialOptions:u,addActiveNs:function(e){i(e).forEach((e=>{const n=g.activeNamespaces.get(e);void 0!==n?g.activeNamespaces.set(e,n+1):g.activeNamespaces.set(e,1)}))},removeActiveNs:function(e){i(e).forEach((e=>{const n=g.activeNamespaces.get(e);void 0!==n&&n>1?g.activeNamespaces.set(e,n-1):g.activeNamespaces.delete(e)}))},getRequiredNamespaces:function(){return r([...g.initialOptions.ns||[g.initialOptions.defaultNs],...i(g.initialOptions.fallbackNs),...g.activeNamespaces.keys()])},getFallbackLangs:function(e){const n=e||c();return n?r([n,...o(n,g.initialOptions.fallbackLanguage)]):[]},getFallbackNs:function(){return i(g.initialOptions.fallbackNs)},getDefaultNs:function(e){return void 0===e?g.initialOptions.defaultNs:e},getAvailableLanguages:function(){if(g.initialOptions.availableLanguages)return g.initialOptions.availableLanguages;if(g.initialOptions.staticData){const e=Object.keys(g.initialOptions.staticData).map((e=>l(e).language));return Array.from(new Set(e))}},withDefaultNs:function(e){return{namespace:void 0===e.namespace?u().defaultNs:e.namespace,language:e.language}},overrideCredentials:function(e){a=e?Object.assign(Object.assign({},e),{apiUrl:s(e.apiUrl)}):void 0}})})(u.onLanguageChange,u.onPendingLanguageChange,u.onRunningChange),h=O(v.getLanguage,v.getInitialOptions,v.getAvailableLanguages,(function({key:e,ns:n}){const t=v.getFallbackLangs(),a=w(n||void 0);return b.getTranslationNs(a,t,e)}),S,E),b=f(u.onCacheChange,h.getBackendRecord,h.getBackendDevRecord,v.withDefaultNs,v.isInitialLoading,d,p);function j(){return v.getFallbackNs()}function k(e){return v.getDefaultNs(e)}function w(e){return[...i(k(e)),...j()]}function R(e){return[...i(e||k()),...v.getRequiredNamespaces()]}function E(e,n,t){const a=v.withDefaultNs(e),i=b.getTranslation(a,n);return b.changeTranslation(a,n,t),{revert:()=>{b.changeTranslation(a,n,i)}}}function N(e){v.init(e),b.addStaticData(v.getInitialOptions().staticData)}function A(e){return b.isLoading(v.getLanguage(),e)}function I(){return Boolean(v.getInitialOptions().apiKey&&v.getInitialOptions().apiUrl)}function D(e,t){const a=function(e,n){const t=v.getFallbackLangs(e),a=R(n),i=[];return t.forEach((e=>{a.forEach((n=>{b.exists({language:e,namespace:n},!0)||i.push({language:e,namespace:n})}))})),i}(e,t);if(a.length)return n(P(a),(()=>{}))}function S({key:e,ns:n,language:t}){const a=w(n||void 0),i=v.getFallbackLangs(t);return b.getTranslationFallback(a,i,e)}function F(){const a=n(function(){if(v.getLanguage())return;if(!v.getInitialOptions().defaultLanguage)throw new Error(t("defaultLanguage"));const e=h.getInitialLanguage();return n(e,(e=>{const n=e||v.getInitialOptions().defaultLanguage;n&&v.setLanguage(n)}))}(),(()=>D()));if(e(a))return v.setInitialLoading(!0),d.notify(),p.notify(),Promise.resolve(a).then((()=>{v.setInitialLoading(!1),d.notify(),p.notify(),u.onInitialLoaded.emit()}));u.onInitialLoaded.emit()}function P(e){return b.loadRecords(e,I())}a&&N(a),u.onUpdate.listen((()=>{v.isRunning()&&h.retranslate()}));const T=()=>{const e=h.getLanguageDetector()||h.getLanguageStorage();if(e){if(!v.getAvailableLanguages())throw new Error(t("availableLanguages"))}if(!v.getLanguage()&&!v.getInitialOptions().defaultLanguage)throw e?new Error(t("defaultLanguage")):new Error(t("language"))};return Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},u),v),h),b),{init:N,changeLanguage:async function(e){v.getPendingLanguage()===e&&v.getLanguage()===e||(v.setPendingLanguage(e),v.isRunning()&&await D(e),e===v.getPendingLanguage()&&(v.setLanguage(e),h.setStoredLanguage(e)))},getTranslation:S,changeTranslation:E,addActiveNs:async function(e,n){n||v.addActiveNs(e),v.isRunning()&&await D(void 0,e)},loadRecords:P,loadRecord:async function(e){return(await P([e]))[0]},isLoading:A,isLoaded:function(e){const n=v.getLanguage();if(!n)return!1;const t=v.getFallbackLangs(n),a=R(e),i=[];return t.forEach((e=>{a.forEach((n=>{b.exists({language:e,namespace:n})||i.push({language:e,namespace:n})}))})),0===i.length},t:(...e)=>{const n=L(...e),t=S(n);return h.formatTranslation(Object.assign(Object.assign({},n),{translation:t}))},isDev:I,run:function(){let e;return T(),v.isRunning()||(I()&&b.invalidate(),v.setRunning(!0),h.run(),e=F()),Promise.resolve(e)},stop:function(){v.isRunning()&&(h.stop(),v.setRunning(!1))}}))},k=()=>{const e={plugins:[],options:{}},n=Object.freeze({use:t=>(e.plugins.push(t),n),updateDefaults:t=>(e.options=b(e.options,t),n),init(n){const t=(e=>{const n=j({options:e}),t=e=>{const t=n.isRunning();t&&n.stop(),e(),t&&n.run()},a=Object.freeze({on:n.on,onNsUpdate:n.onUpdate.listenSome,setEmitterActive:n.setEmitterActive,getLanguage:n.getLanguage,getPendingLanguage:n.getPendingLanguage,changeLanguage:n.changeLanguage,changeTranslation:n.changeTranslation,addActiveNs:n.addActiveNs,removeActiveNs:n.removeActiveNs,loadRecords:n.loadRecords,loadRecord:n.loadRecord,addStaticData:n.addStaticData,getRecord:n.getRecord,getAllRecords:n.getAllRecords,isLoaded:n.isLoaded,isInitialLoading:n.isInitialLoading,isLoading:n.isLoading,isFetching:n.isFetching,isRunning:n.isRunning,run:n.run,stop:n.stop,t:n.t,highlight:n.highlight,getInitialOptions:n.getInitialOptions,isDev:n.isDev,wrap:n.wrap,unwrap:n.unwrap,overrideCredentials(e){t((()=>n.overrideCredentials(e)))},addPlugin(e){e&&t((()=>n.addPlugin(a,e)))},updateOptions(e){e&&t((()=>n.init(e)))}});return a})(b(e.options,n));return e.plugins.forEach(t.addPlugin),t}});return n},w=0,R=1,E=2;class N extends Error{constructor(e,n,t){let a;a=e===w?"Empty parameter":e===R?"Unexpected character":"Unexpected end",super(`Tolgee parser: ${a} at ${n} in "${t}"`),this.code=e,this.index=n}}function A(e){return/\s/.test(e)}const I=0,D=1,S=2,F=3,P=4,T=new Set([S,D,I]),B="'",C=new Set(["{","}",B]),U=e=>/[0-9a-zA-Z_]/.test(e);function x(e,n){const[t,a]=function(e){let n=I,t="",a="",i="";const o=[],r=[];let s=0;function g(n){throw new N(n,s,e)}const c=()=>{o.push(t),t=""},u=()=>{""===a&&g(w),r.push(a),a=""};for(s=0;s<e.length;s++)switch(i=e[s],n){case I:i===B?(t+=i,n=D):"{"===i?(c(),n=F):(t+=i,n=I);break;case D:C.has(i)?(t=t.slice(0,-1)+i,n=S):(t+=i,n=I);break;case S:i===B?n=I:(t+=i,n=S);break;case F:"}"===i?(u(),n=I):A(i)?""!==a&&(u(),n=P):(U(i)||g(R),a+=i,n=F);break;case P:"}"==i?n=I:A(i)?n=P:g(R)}return T.has(n)||g(E),c(),[o,r]}(e),i=[t[0]];for(let o=1;o<t.length;o++){const r=null==n?void 0:n[a[o-1]];if(void 0===r)throw new Error(`Missing parameter "${a[o-1]}" in "${e}"`);i.push(String(r)),i.push(t[o])}return i.join("")}const z=()=>(e,n)=>(n.setFinalFormatter({format:({translation:e,params:n})=>x(e,n)}),e);export{z as FormatSimple,k as TolgeeCore,a as getFallback,i as getFallbackArray,L as getTranslateProps};
//# sourceMappingURL=tolgee.esm.min.js.map

@@ -964,3 +964,3 @@ (function (global, factory) {

function parseCombinedOptions(_a) {
var { ns, noWrap, orEmpty, params } = _a, rest = __rest(_a, ["ns", "noWrap", "orEmpty", "params"]);
var { ns, noWrap, orEmpty, params, language } = _a, rest = __rest(_a, ["ns", "noWrap", "orEmpty", "params", "language"]);
const options = {

@@ -970,2 +970,3 @@ ns: ns,

orEmpty: orEmpty,
language: language,
};

@@ -1115,5 +1116,5 @@ return Object.assign(Object.assign({}, options), { params: Object.assign({}, rest) });

}
function getTranslation({ key, ns }) {
function getTranslation({ key, ns, language }) {
const namespaces = getDefaultAndFallbackNs(ns || undefined);
const languages = state.getFallbackLangs();
const languages = state.getFallbackLangs(language);
return cache.getTranslationFallback(namespaces, languages, key);

@@ -1120,0 +1121,0 @@ }

@@ -1,2 +0,2 @@

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self)["@tolgee/core"]={})}(this,(function(e){"use strict";function n(e){return Boolean(e&&"function"==typeof e.then)}const t=(e,t)=>n(e)?Promise.resolve(e).then(t):t(e),a=e=>`Tolgee: You need to specify '${e}' option`;function i(e){return"string"==typeof e?[e]:Array.isArray(e)?e:void 0}function o(e){return i(e)||[]}function r(e,n){return"object"!=typeof(t=n)||Array.isArray(t)||null===t?o(n):o(null==n?void 0:n[e]);var t}function s(e){return Array.from(new Set(e))}function c(e){return e?e.replace(/\/+$/,""):e}const g=e=>{let n=[];return Object.freeze({listen:e=>{const t=n=>{e(n)};return n.push(t),{unsubscribe:()=>{n=n.filter((e=>t!==e))}}},emit:t=>{e()&&n.forEach((e=>e({value:t})))}})},u=(e,n,t)=>{const a=new Set,i=new Set;let r=[];const s=()=>{if(0===r.length)return;const e=r;r=[],a.forEach((e=>{e({value:void 0})}));let t=new Set;e.forEach((e=>{void 0===e?t=void 0:void 0!==t&&e.forEach((e=>t.add(e)))}));(e=>{const t=new Set(n());i.forEach((n=>{(void 0===e||-1!==(null==e?void 0:e.findIndex((e=>t.has(e)||n.namespaces.has(e)))))&&n.fn({value:void 0})}))})(t?Array.from(t.keys()):void 0)};return Object.freeze({listenSome:e=>{const n={fn:n=>{e(n)},namespaces:new Set};i.add(n);const a={unsubscribe:()=>{i.delete(n)},subscribeNs:e=>(o(e).forEach((e=>n.namespaces.add(e))),void 0===e&&n.namespaces.add(t()),a)};return a},listen:e=>{a.add(e);return{unsubscribe:()=>{a.delete(e)}}},emit:(n,t)=>{e()&&(r.push(n),t?setTimeout(s,0):s())}})},l=e=>{const n=new Map;return Object.entries(e).forEach((([e,t])=>{null!=t&&("object"!=typeof t?n.set(e,t):l(t).forEach(((t,a)=>{n.set(e+"."+a,t)})))})),n},d=e=>{const[n,...t]=e.split(":");return{language:n,namespace:t.join(":")||""}},f=({language:e,namespace:n})=>n?`${e}:${n}`:e,p=(e,n,t,a,i,r,c)=>{const g=new Map,u=new Map;let p={},v=0;function h(n,t,a){const i=f(n);u.set(i,{data:l(t),version:a}),e.emit(n)}function b(e,n){h(e,n,v)}function m(e,n=!1){const t=u.get(f(e));return t&&n?t.version===v:Boolean(t)}function y(e){var n;return null===(n=u.get(f(a(e))))||void 0===n?void 0:n.data}function O(e){let t;if(!t){const n=p[f(e)];"function"==typeof n&&(t=n())}return t||(t=n(e)),t}return Object.freeze({addStaticData:function(e){e&&(p=Object.assign(Object.assign({},p),e),Object.entries(e).forEach((([e,n])=>{if("function"!=typeof n){const t=d(e),a=u.get(e);a&&0!==a.version||h(t,n,0)}})))},invalidate:function(){g.clear(),v+=1},addRecord:b,exists:m,getRecord:y,getTranslation:function(e,n){var t;return null===(t=u.get(f(e)))||void 0===t?void 0:t.data.get(n)},getTranslationNs:function(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(f({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return[i]}return s(e)},getTranslationFallback:function(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(f({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return n}},changeTranslation:function(n,t,a){var i;const o=null===(i=u.get(f(n)))||void 0===i?void 0:i.data;null==o||o.set(t,a),e.emit(Object.assign(Object.assign({},n),{key:t}))},isFetching:function(e){if(i())return!0;if(void 0===e)return g.size>0;const n=o(e);return Boolean(Array.from(g.keys()).find((e=>n.includes(d(e).namespace))))},isLoading:function(e,n){const t=o(n);return Boolean(i()||Array.from(g.keys()).find((n=>{const a=d(n);return(!t.length||t.includes(a.namespace))&&!m({namespace:a.namespace,language:e})})))},loadRecords:async function(e,n){const i=e.map((e=>{const i=a(e),o=f(i),r=g.get(o);if(r)return{new:!1,promise:r,keyObject:i,cacheKey:o};const s=function(e,n){var a;let i;return n&&(i=null===(a=t(e))||void 0===a?void 0:a.catch((()=>(console.warn("Tolgee: Failed to fetch data from dev backend"),O(e))))),i||(i=O(e)),i}(i,n)||Promise.resolve(void 0);return g.set(o,s),{new:!0,promise:s,keyObject:i,cacheKey:o}}));r.notify(),c.notify();const o=await Promise.all(i.map((e=>e.promise)));return i.forEach(((e,n)=>{const t=g.get(e.cacheKey)!==e.promise;if(e.new&&!t){g.delete(e.cacheKey);const t=o[n];t?b(e.keyObject,t):y(e.keyObject)||b(e.keyObject,{})}})),r.notify(),c.notify(),i.map((e=>y(e.keyObject)))},getAllRecords:function(){return Array.from(u.entries()).map((([e,n])=>Object.assign(Object.assign({},d(e)),{data:n.data})))}})};function v(e,n){var t={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&n.indexOf(a)<0&&(t[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(a=Object.getOwnPropertySymbols(e);i<a.length;i++)n.indexOf(a[i])<0&&Object.prototype.propertyIsEnumerable.call(e,a[i])&&(t[a[i]]=e[a[i]])}return t}const h="invalid",b={defaultNs:"",observerOptions:{tagAttributes:{textarea:["placeholder"],input:["value","placeholder"],img:["alt"],"*":["aria-label","title"]},restrictedElements:["script","style"],highlightKeys:["Alt"],highlightColor:"rgb(255, 0, 0)",highlightWidth:5,inputPrefix:"%-%tolgee:",inputSuffix:"%-%",passToParent:["option","optgroup"]},observerType:"invisible",onFormatError:h,apiUrl:"https://app.tolgee.io"},m=(...e)=>{let n={};return e.forEach((e=>{n=Object.assign(Object.assign(Object.assign({},n),e),{observerOptions:Object.assign(Object.assign({},n.observerOptions),null==e?void 0:e.observerOptions)})})),n},y=(e,n)=>{const t=m(b,null==n?void 0:n.initialOptions,e);return t.apiUrl=c(t.apiUrl),{initialOptions:t,activeNamespaces:(null==n?void 0:n.activeNamespaces)||new Map,language:null==n?void 0:n.language,pendingLanguage:null==n?void 0:n.language,isInitialLoading:!1,isRunning:!1}},O=(e,a,i,o,r,s)=>{const c={ui:void 0},g={formatters:[],finalFormatter:void 0,observer:void 0,devBackend:void 0,backends:[],ui:void 0,languageDetector:void 0,languageStorage:void 0},u=async({keysAndDefaults:e,event:n})=>{var t;const a=e.map((({key:e,ns:n,defaultValue:t})=>({key:e,defaultValue:t,ns:o({key:e,ns:n}),translation:r({key:e,ns:n})})));null===(t=g.ui)||void 0===t||t.handleElementClick(a,n)},l=(e,n)=>{var t,a;return(null===(a=null===(t=g.observer)||void 0===t?void 0:t.highlight)||void 0===a?void 0:a.call(t,e,n))||{unhighlight(){}}},d=(e,n)=>{var t;return(null===(t=g.observer)||void 0===t?void 0:t.findPositions(e,n))||[]},f=e=>{const n=r({key:e.key,ns:e.ns});return N(Object.assign(Object.assign({},e),{translation:n,formatEnabled:!0}))},p=e=>{g.observer=null==e?void 0:e()},b=()=>Boolean(g.observer),m=e=>{e&&g.formatters.push(e)},y=e=>{g.finalFormatter=e},O=e=>{c.ui=e},L=()=>Boolean(c.ui),j=e=>{g.languageStorage=e},k=e=>{g.languageDetector=e},w=e=>{e&&g.backends.push(e)},R=e=>{g.devBackend=e},E=()=>g.devBackend;function N(n){var t,{formatEnabled:i}=n,o=v(n,["formatEnabled"]);const{key:r,translation:s,defaultValue:c,noWrap:u,params:l,orEmpty:d,ns:f}=o,p=s||c;let b=p||(d?"":r);const m=e(),y=i||!(null===(t=g.observer)||void 0===t?void 0:t.outputNotFormattable),O=e=>g.observer&&!u?g.observer.wrap({key:r,translation:e,defaultValue:c,params:l,ns:f}):e;b=O(b);try{if(p&&m&&y)for(const e of g.formatters)b=e.format({translation:b,language:m,params:l});g.finalFormatter&&p&&m&&y&&(b=g.finalFormatter.format({translation:b,language:m,params:l}))}catch(e){console.error(e);const n=("string"==typeof(L=e)?L:"string"==typeof(null==L?void 0:L.message)?L.message:void 0)||h,t=a().onFormatError,i=typeof t;b="string"===i?t:"function"===i?t(n,o):h,b=O(b)}var L;return b}return Object.freeze({addPlugin:function(e,n){n(e,Object.freeze({setFinalFormatter:y,addFormatter:m,setObserver:p,hasObserver:b,setUi:O,hasUi:L,setDevBackend:R,addBackend:w,setLanguageDetector:k,setLanguageStorage:j}))},formatTranslation:N,getDevBackend:E,getBackendRecord:({language:e,namespace:t})=>{for(const a of g.backends){const i=a.getRecord({language:e,namespace:t});if(n(i))return null==i?void 0:i.catch((e=>(console.error(e),{})));if(void 0!==i)return i}},getBackendDevRecord:({language:e,namespace:n})=>{var t;const{apiKey:i,apiUrl:o,projectId:r}=a();return null===(t=g.devBackend)||void 0===t?void 0:t.getRecord({apiKey:i,apiUrl:o,projectId:r,language:e,namespace:n})},getLanguageDetector:()=>g.languageDetector,getLanguageStorage:()=>g.languageStorage,getInitialLanguage:()=>{var e;const n=i(),a=null===(e=g.languageStorage)||void 0===e?void 0:e.getLanguage();return t(a,(e=>n&&!n.includes(e)||!e?(()=>{if(!g.languageDetector)return;const e=i();return g.languageDetector.getLanguage({availableLanguages:e})})():e))},setStoredLanguage:e=>{var n;null===(n=g.languageStorage)||void 0===n||n.setLanguage(e)},run:()=>{var e,n;const{apiKey:t,apiUrl:i,projectId:o,observerOptions:r}=a();g.ui=null===(e=c.ui)||void 0===e?void 0:e.call(c,{apiKey:t,apiUrl:i,projectId:o,highlight:l,changeTranslation:s,findPositions:d}),null===(n=g.observer)||void 0===n||n.run({mouseHighlight:!0,options:r,translate:f,onClick:u})},stop:()=>{var e;g.ui=void 0,null===(e=g.observer)||void 0===e||e.stop()},retranslate:()=>{var e;null===(e=g.observer)||void 0===e||e.retranslate()},highlight:l,unwrap:e=>{var n;return g.observer?null===(n=g.observer)||void 0===n?void 0:n.unwrap(e):{text:e,keys:[]}},wrap:e=>{var n;return g.observer?null===(n=g.observer)||void 0===n?void 0:n.wrap(e):e.translation},hasDevBackend:function(){return Boolean(E())}})},L=(e,n,t)=>{let a=e;return Object.freeze({init:function(e){a=e},notify:function(){const e=n();a!==e&&t(e),a=e}})};const j=(e,...n)=>{let t,a={};return"object"==typeof e?a=e:(a.key=e,"string"==typeof n[0]?(a.defaultValue=n[0],t=n[1]):"object"==typeof n[0]&&(t=n[0])),t&&(a=Object.assign(Object.assign({},function(e){var{ns:n,noWrap:t,orEmpty:a,params:i}=e,o=v(e,["ns","noWrap","orEmpty","params"]);const r={ns:n,noWrap:t,orEmpty:a};return Object.assign(Object.assign({},r),{params:Object.assign({},o)})}(t)),a)),a},k=({options:e})=>{const i=((e,n)=>{let t=!0;function a(){return t}const i=g(a),o=g(a),r=g(a),s=g(a),c=g(a),l=g(a),d=g(a),f=u(a,e,n);return c.listen((()=>f.emit())),o.listen((()=>f.emit())),d.listen((({value:e})=>{f.emit([e.namespace],!0)})),Object.freeze({onPendingLanguageChange:i,onLanguageChange:o,onLoadingChange:r,onFetchingChange:s,onInitialLoaded:c,onRunningChange:l,onCacheChange:d,onUpdate:f,setEmitterActive:function(e){t=e},on:(e,n)=>{switch(e){case"pendingLanguage":return i.listen(n);case"language":return o.listen(n);case"loading":return r.listen(n);case"fetching":return s.listen(n);case"initialLoad":return c.listen(n);case"running":return l.listen(n);case"cache":return d.listen(n);case"update":return f.listen(n)}}})})(m,k),l=L(!1,(()=>b.isFetching()),i.onFetchingChange.emit),f=L(!1,(()=>A()),i.onLoadingChange.emit),v=((e,n,t)=>{let a,i=y();function g(){return i.language||i.initialOptions.language}function u(){return Object.assign(Object.assign({},i.initialOptions),a)}return Object.freeze({init:function(e){i=y(e,i)},isRunning:function(){return i.isRunning},setRunning:function(e){i.isRunning!==e&&(i.isRunning=e,t.emit(e))},isInitialLoading:function(){return i.isInitialLoading},setInitialLoading:function(e){i.isInitialLoading=e},getLanguage:g,setLanguage:function(n){i.language!==n&&(i.language=n,e.emit(n))},getPendingLanguage:function(){return i.pendingLanguage||g()},setPendingLanguage:function(e){i.pendingLanguage!==e&&(i.pendingLanguage=e,n.emit(e))},getInitialOptions:u,addActiveNs:function(e){o(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n?i.activeNamespaces.set(e,n+1):i.activeNamespaces.set(e,1)}))},removeActiveNs:function(e){o(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n&&n>1?i.activeNamespaces.set(e,n-1):i.activeNamespaces.delete(e)}))},getRequiredNamespaces:function(){return s([...i.initialOptions.ns||[i.initialOptions.defaultNs],...o(i.initialOptions.fallbackNs),...i.activeNamespaces.keys()])},getFallbackLangs:function(e){const n=e||g();return n?s([n,...r(n,i.initialOptions.fallbackLanguage)]):[]},getFallbackNs:function(){return o(i.initialOptions.fallbackNs)},getDefaultNs:function(e){return void 0===e?i.initialOptions.defaultNs:e},getAvailableLanguages:function(){if(i.initialOptions.availableLanguages)return i.initialOptions.availableLanguages;if(i.initialOptions.staticData){const e=Object.keys(i.initialOptions.staticData).map((e=>d(e).language));return Array.from(new Set(e))}},withDefaultNs:function(e){return{namespace:void 0===e.namespace?u().defaultNs:e.namespace,language:e.language}},overrideCredentials:function(e){a=e?Object.assign(Object.assign({},e),{apiUrl:c(e.apiUrl)}):void 0}})})(i.onLanguageChange,i.onPendingLanguageChange,i.onRunningChange),h=O(v.getLanguage,v.getInitialOptions,v.getAvailableLanguages,(function({key:e,ns:n}){const t=v.getFallbackLangs(),a=w(n||void 0);return b.getTranslationNs(a,t,e)}),D,E),b=p(i.onCacheChange,h.getBackendRecord,h.getBackendDevRecord,v.withDefaultNs,v.isInitialLoading,l,f);function m(){return v.getFallbackNs()}function k(e){return v.getDefaultNs(e)}function w(e){return[...o(k(e)),...m()]}function R(e){return[...o(e||k()),...v.getRequiredNamespaces()]}function E(e,n,t){const a=v.withDefaultNs(e),i=b.getTranslation(a,n);return b.changeTranslation(a,n,t),{revert:()=>{b.changeTranslation(a,n,i)}}}function N(e){v.init(e),b.addStaticData(v.getInitialOptions().staticData)}function A(e){return b.isLoading(v.getLanguage(),e)}function F(){return Boolean(v.getInitialOptions().apiKey&&v.getInitialOptions().apiUrl)}function I(e,n){const a=function(e,n){const t=v.getFallbackLangs(e),a=R(n),i=[];return t.forEach((e=>{a.forEach((n=>{b.exists({language:e,namespace:n},!0)||i.push({language:e,namespace:n})}))})),i}(e,n);if(a.length)return t(P(a),(()=>{}))}function D({key:e,ns:n}){const t=w(n||void 0),a=v.getFallbackLangs();return b.getTranslationFallback(t,a,e)}function S(){const e=t(function(){if(v.getLanguage())return;if(!v.getInitialOptions().defaultLanguage)throw new Error(a("defaultLanguage"));const e=h.getInitialLanguage();return t(e,(e=>{const n=e||v.getInitialOptions().defaultLanguage;n&&v.setLanguage(n)}))}(),(()=>I()));if(n(e))return v.setInitialLoading(!0),l.notify(),f.notify(),Promise.resolve(e).then((()=>{v.setInitialLoading(!1),l.notify(),f.notify(),i.onInitialLoaded.emit()}));i.onInitialLoaded.emit()}function P(e){return b.loadRecords(e,F())}e&&N(e),i.onUpdate.listen((()=>{v.isRunning()&&h.retranslate()}));const T=()=>{const e=h.getLanguageDetector()||h.getLanguageStorage();if(e){if(!v.getAvailableLanguages())throw new Error(a("availableLanguages"))}if(!v.getLanguage()&&!v.getInitialOptions().defaultLanguage)throw e?new Error(a("defaultLanguage")):new Error(a("language"))};return Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},i),v),h),b),{init:N,changeLanguage:async function(e){v.getPendingLanguage()===e&&v.getLanguage()===e||(v.setPendingLanguage(e),v.isRunning()&&await I(e),e===v.getPendingLanguage()&&(v.setLanguage(e),h.setStoredLanguage(e)))},getTranslation:D,changeTranslation:E,addActiveNs:async function(e,n){n||v.addActiveNs(e),v.isRunning()&&await I(void 0,e)},loadRecords:P,loadRecord:async function(e){return(await P([e]))[0]},isLoading:A,isLoaded:function(e){const n=v.getLanguage();if(!n)return!1;const t=v.getFallbackLangs(n),a=R(e),i=[];return t.forEach((e=>{a.forEach((n=>{b.exists({language:e,namespace:n})||i.push({language:e,namespace:n})}))})),0===i.length},t:(...e)=>{const n=j(...e),t=D(n);return h.formatTranslation(Object.assign(Object.assign({},n),{translation:t}))},isDev:F,run:function(){let e;return T(),v.isRunning()||(F()&&b.invalidate(),v.setRunning(!0),h.run(),e=S()),Promise.resolve(e)},stop:function(){v.isRunning()&&(h.stop(),v.setRunning(!1))}}))},w=0,R=1,E=2;class N extends Error{constructor(e,n,t){let a;a=e===w?"Empty parameter":e===R?"Unexpected character":"Unexpected end",super(`Tolgee parser: ${a} at ${n} in "${t}"`),this.code=e,this.index=n}}function A(e){return/\s/.test(e)}const F=0,I=1,D=2,S=3,P=4,T=new Set([D,I,F]),C="'",B=new Set(["{","}",C]),U=e=>/[0-9a-zA-Z_]/.test(e);function x(e,n){const[t,a]=function(e){let n=F,t="",a="",i="";const o=[],r=[];let s=0;function c(n){throw new N(n,s,e)}const g=()=>{o.push(t),t=""},u=()=>{""===a&&c(w),r.push(a),a=""};for(s=0;s<e.length;s++)switch(i=e[s],n){case F:i===C?(t+=i,n=I):"{"===i?(g(),n=S):(t+=i,n=F);break;case I:B.has(i)?(t=t.slice(0,-1)+i,n=D):(t+=i,n=F);break;case D:i===C?n=F:(t+=i,n=D);break;case S:"}"===i?(u(),n=F):A(i)?""!==a&&(u(),n=P):(U(i)||c(R),a+=i,n=S);break;case P:"}"==i?n=F:A(i)?n=P:c(R)}return T.has(n)||c(E),g(),[o,r]}(e),i=[t[0]];for(let o=1;o<t.length;o++){const r=null==n?void 0:n[a[o-1]];if(void 0===r)throw new Error(`Missing parameter "${a[o-1]}" in "${e}"`);i.push(String(r)),i.push(t[o])}return i.join("")}e.FormatSimple=()=>(e,n)=>(n.setFinalFormatter({format:({translation:e,params:n})=>x(e,n)}),e),e.TolgeeCore=()=>{const e={plugins:[],options:{}},n=Object.freeze({use:t=>(e.plugins.push(t),n),updateDefaults:t=>(e.options=m(e.options,t),n),init(n){const t=(e=>{const n=k({options:e}),t=e=>{const t=n.isRunning();t&&n.stop(),e(),t&&n.run()},a=Object.freeze({on:n.on,onNsUpdate:n.onUpdate.listenSome,setEmitterActive:n.setEmitterActive,getLanguage:n.getLanguage,getPendingLanguage:n.getPendingLanguage,changeLanguage:n.changeLanguage,changeTranslation:n.changeTranslation,addActiveNs:n.addActiveNs,removeActiveNs:n.removeActiveNs,loadRecords:n.loadRecords,loadRecord:n.loadRecord,addStaticData:n.addStaticData,getRecord:n.getRecord,getAllRecords:n.getAllRecords,isLoaded:n.isLoaded,isInitialLoading:n.isInitialLoading,isLoading:n.isLoading,isFetching:n.isFetching,isRunning:n.isRunning,run:n.run,stop:n.stop,t:n.t,highlight:n.highlight,getInitialOptions:n.getInitialOptions,isDev:n.isDev,wrap:n.wrap,unwrap:n.unwrap,overrideCredentials(e){t((()=>n.overrideCredentials(e)))},addPlugin(e){e&&t((()=>n.addPlugin(a,e)))},updateOptions(e){e&&t((()=>n.init(e)))}});return a})(m(e.options,n));return e.plugins.forEach(t.addPlugin),t}});return n},e.getFallback=i,e.getFallbackArray=o,e.getTranslateProps=j,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self)["@tolgee/core"]={})}(this,(function(e){"use strict";function n(e){return Boolean(e&&"function"==typeof e.then)}const t=(e,t)=>n(e)?Promise.resolve(e).then(t):t(e),a=e=>`Tolgee: You need to specify '${e}' option`;function i(e){return"string"==typeof e?[e]:Array.isArray(e)?e:void 0}function o(e){return i(e)||[]}function r(e,n){return"object"!=typeof(t=n)||Array.isArray(t)||null===t?o(n):o(null==n?void 0:n[e]);var t}function s(e){return Array.from(new Set(e))}function g(e){return e?e.replace(/\/+$/,""):e}const c=e=>{let n=[];return Object.freeze({listen:e=>{const t=n=>{e(n)};return n.push(t),{unsubscribe:()=>{n=n.filter((e=>t!==e))}}},emit:t=>{e()&&n.forEach((e=>e({value:t})))}})},u=(e,n,t)=>{const a=new Set,i=new Set;let r=[];const s=()=>{if(0===r.length)return;const e=r;r=[],a.forEach((e=>{e({value:void 0})}));let t=new Set;e.forEach((e=>{void 0===e?t=void 0:void 0!==t&&e.forEach((e=>t.add(e)))}));(e=>{const t=new Set(n());i.forEach((n=>{(void 0===e||-1!==(null==e?void 0:e.findIndex((e=>t.has(e)||n.namespaces.has(e)))))&&n.fn({value:void 0})}))})(t?Array.from(t.keys()):void 0)};return Object.freeze({listenSome:e=>{const n={fn:n=>{e(n)},namespaces:new Set};i.add(n);const a={unsubscribe:()=>{i.delete(n)},subscribeNs:e=>(o(e).forEach((e=>n.namespaces.add(e))),void 0===e&&n.namespaces.add(t()),a)};return a},listen:e=>{a.add(e);return{unsubscribe:()=>{a.delete(e)}}},emit:(n,t)=>{e()&&(r.push(n),t?setTimeout(s,0):s())}})},l=e=>{const n=new Map;return Object.entries(e).forEach((([e,t])=>{null!=t&&("object"!=typeof t?n.set(e,t):l(t).forEach(((t,a)=>{n.set(e+"."+a,t)})))})),n},d=e=>{const[n,...t]=e.split(":");return{language:n,namespace:t.join(":")||""}},f=({language:e,namespace:n})=>n?`${e}:${n}`:e,p=(e,n,t,a,i,r,g)=>{const c=new Map,u=new Map;let p={},v=0;function h(n,t,a){const i=f(n);u.set(i,{data:l(t),version:a}),e.emit(n)}function b(e,n){h(e,n,v)}function m(e,n=!1){const t=u.get(f(e));return t&&n?t.version===v:Boolean(t)}function y(e){var n;return null===(n=u.get(f(a(e))))||void 0===n?void 0:n.data}function O(e){let t;if(!t){const n=p[f(e)];"function"==typeof n&&(t=n())}return t||(t=n(e)),t}return Object.freeze({addStaticData:function(e){e&&(p=Object.assign(Object.assign({},p),e),Object.entries(e).forEach((([e,n])=>{if("function"!=typeof n){const t=d(e),a=u.get(e);a&&0!==a.version||h(t,n,0)}})))},invalidate:function(){c.clear(),v+=1},addRecord:b,exists:m,getRecord:y,getTranslation:function(e,n){var t;return null===(t=u.get(f(e)))||void 0===t?void 0:t.data.get(n)},getTranslationNs:function(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(f({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return[i]}return s(e)},getTranslationFallback:function(e,n,t){var a;for(const i of e)for(const e of n){const n=null===(a=u.get(f({language:e,namespace:i})))||void 0===a?void 0:a.data.get(t);if(null!=n)return n}},changeTranslation:function(n,t,a){var i;const o=null===(i=u.get(f(n)))||void 0===i?void 0:i.data;null==o||o.set(t,a),e.emit(Object.assign(Object.assign({},n),{key:t}))},isFetching:function(e){if(i())return!0;if(void 0===e)return c.size>0;const n=o(e);return Boolean(Array.from(c.keys()).find((e=>n.includes(d(e).namespace))))},isLoading:function(e,n){const t=o(n);return Boolean(i()||Array.from(c.keys()).find((n=>{const a=d(n);return(!t.length||t.includes(a.namespace))&&!m({namespace:a.namespace,language:e})})))},loadRecords:async function(e,n){const i=e.map((e=>{const i=a(e),o=f(i),r=c.get(o);if(r)return{new:!1,promise:r,keyObject:i,cacheKey:o};const s=function(e,n){var a;let i;return n&&(i=null===(a=t(e))||void 0===a?void 0:a.catch((()=>(console.warn("Tolgee: Failed to fetch data from dev backend"),O(e))))),i||(i=O(e)),i}(i,n)||Promise.resolve(void 0);return c.set(o,s),{new:!0,promise:s,keyObject:i,cacheKey:o}}));r.notify(),g.notify();const o=await Promise.all(i.map((e=>e.promise)));return i.forEach(((e,n)=>{const t=c.get(e.cacheKey)!==e.promise;if(e.new&&!t){c.delete(e.cacheKey);const t=o[n];t?b(e.keyObject,t):y(e.keyObject)||b(e.keyObject,{})}})),r.notify(),g.notify(),i.map((e=>y(e.keyObject)))},getAllRecords:function(){return Array.from(u.entries()).map((([e,n])=>Object.assign(Object.assign({},d(e)),{data:n.data})))}})};function v(e,n){var t={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&n.indexOf(a)<0&&(t[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(a=Object.getOwnPropertySymbols(e);i<a.length;i++)n.indexOf(a[i])<0&&Object.prototype.propertyIsEnumerable.call(e,a[i])&&(t[a[i]]=e[a[i]])}return t}const h="invalid",b={defaultNs:"",observerOptions:{tagAttributes:{textarea:["placeholder"],input:["value","placeholder"],img:["alt"],"*":["aria-label","title"]},restrictedElements:["script","style"],highlightKeys:["Alt"],highlightColor:"rgb(255, 0, 0)",highlightWidth:5,inputPrefix:"%-%tolgee:",inputSuffix:"%-%",passToParent:["option","optgroup"]},observerType:"invisible",onFormatError:h,apiUrl:"https://app.tolgee.io"},m=(...e)=>{let n={};return e.forEach((e=>{n=Object.assign(Object.assign(Object.assign({},n),e),{observerOptions:Object.assign(Object.assign({},n.observerOptions),null==e?void 0:e.observerOptions)})})),n},y=(e,n)=>{const t=m(b,null==n?void 0:n.initialOptions,e);return t.apiUrl=g(t.apiUrl),{initialOptions:t,activeNamespaces:(null==n?void 0:n.activeNamespaces)||new Map,language:null==n?void 0:n.language,pendingLanguage:null==n?void 0:n.language,isInitialLoading:!1,isRunning:!1}},O=(e,a,i,o,r,s)=>{const g={ui:void 0},c={formatters:[],finalFormatter:void 0,observer:void 0,devBackend:void 0,backends:[],ui:void 0,languageDetector:void 0,languageStorage:void 0},u=async({keysAndDefaults:e,event:n})=>{var t;const a=e.map((({key:e,ns:n,defaultValue:t})=>({key:e,defaultValue:t,ns:o({key:e,ns:n}),translation:r({key:e,ns:n})})));null===(t=c.ui)||void 0===t||t.handleElementClick(a,n)},l=(e,n)=>{var t,a;return(null===(a=null===(t=c.observer)||void 0===t?void 0:t.highlight)||void 0===a?void 0:a.call(t,e,n))||{unhighlight(){}}},d=(e,n)=>{var t;return(null===(t=c.observer)||void 0===t?void 0:t.findPositions(e,n))||[]},f=e=>{const n=r({key:e.key,ns:e.ns});return N(Object.assign(Object.assign({},e),{translation:n,formatEnabled:!0}))},p=e=>{c.observer=null==e?void 0:e()},b=()=>Boolean(c.observer),m=e=>{e&&c.formatters.push(e)},y=e=>{c.finalFormatter=e},O=e=>{g.ui=e},L=()=>Boolean(g.ui),j=e=>{c.languageStorage=e},k=e=>{c.languageDetector=e},w=e=>{e&&c.backends.push(e)},R=e=>{c.devBackend=e},E=()=>c.devBackend;function N(n){var t,{formatEnabled:i}=n,o=v(n,["formatEnabled"]);const{key:r,translation:s,defaultValue:g,noWrap:u,params:l,orEmpty:d,ns:f}=o,p=s||g;let b=p||(d?"":r);const m=e(),y=i||!(null===(t=c.observer)||void 0===t?void 0:t.outputNotFormattable),O=e=>c.observer&&!u?c.observer.wrap({key:r,translation:e,defaultValue:g,params:l,ns:f}):e;b=O(b);try{if(p&&m&&y)for(const e of c.formatters)b=e.format({translation:b,language:m,params:l});c.finalFormatter&&p&&m&&y&&(b=c.finalFormatter.format({translation:b,language:m,params:l}))}catch(e){console.error(e);const n=("string"==typeof(L=e)?L:"string"==typeof(null==L?void 0:L.message)?L.message:void 0)||h,t=a().onFormatError,i=typeof t;b="string"===i?t:"function"===i?t(n,o):h,b=O(b)}var L;return b}return Object.freeze({addPlugin:function(e,n){n(e,Object.freeze({setFinalFormatter:y,addFormatter:m,setObserver:p,hasObserver:b,setUi:O,hasUi:L,setDevBackend:R,addBackend:w,setLanguageDetector:k,setLanguageStorage:j}))},formatTranslation:N,getDevBackend:E,getBackendRecord:({language:e,namespace:t})=>{for(const a of c.backends){const i=a.getRecord({language:e,namespace:t});if(n(i))return null==i?void 0:i.catch((e=>(console.error(e),{})));if(void 0!==i)return i}},getBackendDevRecord:({language:e,namespace:n})=>{var t;const{apiKey:i,apiUrl:o,projectId:r}=a();return null===(t=c.devBackend)||void 0===t?void 0:t.getRecord({apiKey:i,apiUrl:o,projectId:r,language:e,namespace:n})},getLanguageDetector:()=>c.languageDetector,getLanguageStorage:()=>c.languageStorage,getInitialLanguage:()=>{var e;const n=i(),a=null===(e=c.languageStorage)||void 0===e?void 0:e.getLanguage();return t(a,(e=>n&&!n.includes(e)||!e?(()=>{if(!c.languageDetector)return;const e=i();return c.languageDetector.getLanguage({availableLanguages:e})})():e))},setStoredLanguage:e=>{var n;null===(n=c.languageStorage)||void 0===n||n.setLanguage(e)},run:()=>{var e,n;const{apiKey:t,apiUrl:i,projectId:o,observerOptions:r}=a();c.ui=null===(e=g.ui)||void 0===e?void 0:e.call(g,{apiKey:t,apiUrl:i,projectId:o,highlight:l,changeTranslation:s,findPositions:d}),null===(n=c.observer)||void 0===n||n.run({mouseHighlight:!0,options:r,translate:f,onClick:u})},stop:()=>{var e;c.ui=void 0,null===(e=c.observer)||void 0===e||e.stop()},retranslate:()=>{var e;null===(e=c.observer)||void 0===e||e.retranslate()},highlight:l,unwrap:e=>{var n;return c.observer?null===(n=c.observer)||void 0===n?void 0:n.unwrap(e):{text:e,keys:[]}},wrap:e=>{var n;return c.observer?null===(n=c.observer)||void 0===n?void 0:n.wrap(e):e.translation},hasDevBackend:function(){return Boolean(E())}})},L=(e,n,t)=>{let a=e;return Object.freeze({init:function(e){a=e},notify:function(){const e=n();a!==e&&t(e),a=e}})};const j=(e,...n)=>{let t,a={};return"object"==typeof e?a=e:(a.key=e,"string"==typeof n[0]?(a.defaultValue=n[0],t=n[1]):"object"==typeof n[0]&&(t=n[0])),t&&(a=Object.assign(Object.assign({},function(e){var{ns:n,noWrap:t,orEmpty:a,params:i,language:o}=e,r=v(e,["ns","noWrap","orEmpty","params","language"]);const s={ns:n,noWrap:t,orEmpty:a,language:o};return Object.assign(Object.assign({},s),{params:Object.assign({},r)})}(t)),a)),a},k=({options:e})=>{const i=((e,n)=>{let t=!0;function a(){return t}const i=c(a),o=c(a),r=c(a),s=c(a),g=c(a),l=c(a),d=c(a),f=u(a,e,n);return g.listen((()=>f.emit())),o.listen((()=>f.emit())),d.listen((({value:e})=>{f.emit([e.namespace],!0)})),Object.freeze({onPendingLanguageChange:i,onLanguageChange:o,onLoadingChange:r,onFetchingChange:s,onInitialLoaded:g,onRunningChange:l,onCacheChange:d,onUpdate:f,setEmitterActive:function(e){t=e},on:(e,n)=>{switch(e){case"pendingLanguage":return i.listen(n);case"language":return o.listen(n);case"loading":return r.listen(n);case"fetching":return s.listen(n);case"initialLoad":return g.listen(n);case"running":return l.listen(n);case"cache":return d.listen(n);case"update":return f.listen(n)}}})})(m,k),l=L(!1,(()=>b.isFetching()),i.onFetchingChange.emit),f=L(!1,(()=>A()),i.onLoadingChange.emit),v=((e,n,t)=>{let a,i=y();function c(){return i.language||i.initialOptions.language}function u(){return Object.assign(Object.assign({},i.initialOptions),a)}return Object.freeze({init:function(e){i=y(e,i)},isRunning:function(){return i.isRunning},setRunning:function(e){i.isRunning!==e&&(i.isRunning=e,t.emit(e))},isInitialLoading:function(){return i.isInitialLoading},setInitialLoading:function(e){i.isInitialLoading=e},getLanguage:c,setLanguage:function(n){i.language!==n&&(i.language=n,e.emit(n))},getPendingLanguage:function(){return i.pendingLanguage||c()},setPendingLanguage:function(e){i.pendingLanguage!==e&&(i.pendingLanguage=e,n.emit(e))},getInitialOptions:u,addActiveNs:function(e){o(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n?i.activeNamespaces.set(e,n+1):i.activeNamespaces.set(e,1)}))},removeActiveNs:function(e){o(e).forEach((e=>{const n=i.activeNamespaces.get(e);void 0!==n&&n>1?i.activeNamespaces.set(e,n-1):i.activeNamespaces.delete(e)}))},getRequiredNamespaces:function(){return s([...i.initialOptions.ns||[i.initialOptions.defaultNs],...o(i.initialOptions.fallbackNs),...i.activeNamespaces.keys()])},getFallbackLangs:function(e){const n=e||c();return n?s([n,...r(n,i.initialOptions.fallbackLanguage)]):[]},getFallbackNs:function(){return o(i.initialOptions.fallbackNs)},getDefaultNs:function(e){return void 0===e?i.initialOptions.defaultNs:e},getAvailableLanguages:function(){if(i.initialOptions.availableLanguages)return i.initialOptions.availableLanguages;if(i.initialOptions.staticData){const e=Object.keys(i.initialOptions.staticData).map((e=>d(e).language));return Array.from(new Set(e))}},withDefaultNs:function(e){return{namespace:void 0===e.namespace?u().defaultNs:e.namespace,language:e.language}},overrideCredentials:function(e){a=e?Object.assign(Object.assign({},e),{apiUrl:g(e.apiUrl)}):void 0}})})(i.onLanguageChange,i.onPendingLanguageChange,i.onRunningChange),h=O(v.getLanguage,v.getInitialOptions,v.getAvailableLanguages,(function({key:e,ns:n}){const t=v.getFallbackLangs(),a=w(n||void 0);return b.getTranslationNs(a,t,e)}),D,E),b=p(i.onCacheChange,h.getBackendRecord,h.getBackendDevRecord,v.withDefaultNs,v.isInitialLoading,l,f);function m(){return v.getFallbackNs()}function k(e){return v.getDefaultNs(e)}function w(e){return[...o(k(e)),...m()]}function R(e){return[...o(e||k()),...v.getRequiredNamespaces()]}function E(e,n,t){const a=v.withDefaultNs(e),i=b.getTranslation(a,n);return b.changeTranslation(a,n,t),{revert:()=>{b.changeTranslation(a,n,i)}}}function N(e){v.init(e),b.addStaticData(v.getInitialOptions().staticData)}function A(e){return b.isLoading(v.getLanguage(),e)}function F(){return Boolean(v.getInitialOptions().apiKey&&v.getInitialOptions().apiUrl)}function I(e,n){const a=function(e,n){const t=v.getFallbackLangs(e),a=R(n),i=[];return t.forEach((e=>{a.forEach((n=>{b.exists({language:e,namespace:n},!0)||i.push({language:e,namespace:n})}))})),i}(e,n);if(a.length)return t(P(a),(()=>{}))}function D({key:e,ns:n,language:t}){const a=w(n||void 0),i=v.getFallbackLangs(t);return b.getTranslationFallback(a,i,e)}function S(){const e=t(function(){if(v.getLanguage())return;if(!v.getInitialOptions().defaultLanguage)throw new Error(a("defaultLanguage"));const e=h.getInitialLanguage();return t(e,(e=>{const n=e||v.getInitialOptions().defaultLanguage;n&&v.setLanguage(n)}))}(),(()=>I()));if(n(e))return v.setInitialLoading(!0),l.notify(),f.notify(),Promise.resolve(e).then((()=>{v.setInitialLoading(!1),l.notify(),f.notify(),i.onInitialLoaded.emit()}));i.onInitialLoaded.emit()}function P(e){return b.loadRecords(e,F())}e&&N(e),i.onUpdate.listen((()=>{v.isRunning()&&h.retranslate()}));const T=()=>{const e=h.getLanguageDetector()||h.getLanguageStorage();if(e){if(!v.getAvailableLanguages())throw new Error(a("availableLanguages"))}if(!v.getLanguage()&&!v.getInitialOptions().defaultLanguage)throw e?new Error(a("defaultLanguage")):new Error(a("language"))};return Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},i),v),h),b),{init:N,changeLanguage:async function(e){v.getPendingLanguage()===e&&v.getLanguage()===e||(v.setPendingLanguage(e),v.isRunning()&&await I(e),e===v.getPendingLanguage()&&(v.setLanguage(e),h.setStoredLanguage(e)))},getTranslation:D,changeTranslation:E,addActiveNs:async function(e,n){n||v.addActiveNs(e),v.isRunning()&&await I(void 0,e)},loadRecords:P,loadRecord:async function(e){return(await P([e]))[0]},isLoading:A,isLoaded:function(e){const n=v.getLanguage();if(!n)return!1;const t=v.getFallbackLangs(n),a=R(e),i=[];return t.forEach((e=>{a.forEach((n=>{b.exists({language:e,namespace:n})||i.push({language:e,namespace:n})}))})),0===i.length},t:(...e)=>{const n=j(...e),t=D(n);return h.formatTranslation(Object.assign(Object.assign({},n),{translation:t}))},isDev:F,run:function(){let e;return T(),v.isRunning()||(F()&&b.invalidate(),v.setRunning(!0),h.run(),e=S()),Promise.resolve(e)},stop:function(){v.isRunning()&&(h.stop(),v.setRunning(!1))}}))},w=0,R=1,E=2;class N extends Error{constructor(e,n,t){let a;a=e===w?"Empty parameter":e===R?"Unexpected character":"Unexpected end",super(`Tolgee parser: ${a} at ${n} in "${t}"`),this.code=e,this.index=n}}function A(e){return/\s/.test(e)}const F=0,I=1,D=2,S=3,P=4,T=new Set([D,I,F]),C="'",B=new Set(["{","}",C]),U=e=>/[0-9a-zA-Z_]/.test(e);function x(e,n){const[t,a]=function(e){let n=F,t="",a="",i="";const o=[],r=[];let s=0;function g(n){throw new N(n,s,e)}const c=()=>{o.push(t),t=""},u=()=>{""===a&&g(w),r.push(a),a=""};for(s=0;s<e.length;s++)switch(i=e[s],n){case F:i===C?(t+=i,n=I):"{"===i?(c(),n=S):(t+=i,n=F);break;case I:B.has(i)?(t=t.slice(0,-1)+i,n=D):(t+=i,n=F);break;case D:i===C?n=F:(t+=i,n=D);break;case S:"}"===i?(u(),n=F):A(i)?""!==a&&(u(),n=P):(U(i)||g(R),a+=i,n=S);break;case P:"}"==i?n=F:A(i)?n=P:g(R)}return T.has(n)||g(E),c(),[o,r]}(e),i=[t[0]];for(let o=1;o<t.length;o++){const r=null==n?void 0:n[a[o-1]];if(void 0===r)throw new Error(`Missing parameter "${a[o-1]}" in "${e}"`);i.push(String(r)),i.push(t[o])}return i.join("")}e.FormatSimple=()=>(e,n)=>(n.setFinalFormatter({format:({translation:e,params:n})=>x(e,n)}),e),e.TolgeeCore=()=>{const e={plugins:[],options:{}},n=Object.freeze({use:t=>(e.plugins.push(t),n),updateDefaults:t=>(e.options=m(e.options,t),n),init(n){const t=(e=>{const n=k({options:e}),t=e=>{const t=n.isRunning();t&&n.stop(),e(),t&&n.run()},a=Object.freeze({on:n.on,onNsUpdate:n.onUpdate.listenSome,setEmitterActive:n.setEmitterActive,getLanguage:n.getLanguage,getPendingLanguage:n.getPendingLanguage,changeLanguage:n.changeLanguage,changeTranslation:n.changeTranslation,addActiveNs:n.addActiveNs,removeActiveNs:n.removeActiveNs,loadRecords:n.loadRecords,loadRecord:n.loadRecord,addStaticData:n.addStaticData,getRecord:n.getRecord,getAllRecords:n.getAllRecords,isLoaded:n.isLoaded,isInitialLoading:n.isInitialLoading,isLoading:n.isLoading,isFetching:n.isFetching,isRunning:n.isRunning,run:n.run,stop:n.stop,t:n.t,highlight:n.highlight,getInitialOptions:n.getInitialOptions,isDev:n.isDev,wrap:n.wrap,unwrap:n.unwrap,overrideCredentials(e){t((()=>n.overrideCredentials(e)))},addPlugin(e){e&&t((()=>n.addPlugin(a,e)))},updateOptions(e){e&&t((()=>n.init(e)))}});return a})(m(e.options,n));return e.plugins.forEach(t.addPlugin),t}});return n},e.getFallback=i,e.getFallbackArray=o,e.getTranslateProps=j,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=tolgee.umd.min.js.map

@@ -8,3 +8,3 @@ import { CacheDescriptor, NsFallback, TolgeeOptions, TFnType, KeyAndNamespacesInternal } from '../types';

changeLanguage: (language: string) => Promise<void>;
getTranslation: ({ key, ns }: KeyAndNamespacesInternal) => string | undefined;
getTranslation: ({ key, ns, language }: KeyAndNamespacesInternal) => string | undefined;
changeTranslation: (descriptor: CacheDescriptor, key: string, value: string) => {

@@ -11,0 +11,0 @@ revert: () => void;

@@ -15,2 +15,3 @@ export declare type FallbackGeneral = undefined | false | string | string[];

orEmpty?: boolean;
language?: string;
};

@@ -34,3 +35,3 @@ export declare type TranslateProps<T = DefaultParamType, K extends string = TranslationKey> = {

};
export declare type KeyAndNamespacesInternal = Pick<TranslatePropsInternal, 'key' | 'ns'>;
export declare type KeyAndNamespacesInternal = Pick<TranslatePropsInternal, 'key' | 'ns' | 'language'>;
export {};
{
"name": "@tolgee/core",
"version": "5.7.3",
"version": "5.8.0",
"description": "Library providing ability to translate messages directly in context of developed application.",

@@ -70,3 +70,3 @@ "main": "./dist/tolgee.cjs.js",

"sideEffects": false,
"gitHead": "fde08c663fc22333a09c1a6f8e976d16c500e79e"
"gitHead": "a6185bf50f9319a81cbd4d768daf56417427d14e"
}

@@ -190,2 +190,15 @@ /* eslint-disable no-console */

});
it('language prop overrides current language', () => {
tolgee = TolgeeCore().init({
language: 'en',
staticData: {
en: { hello: 'Hello' },
cs: { hello: 'Ahoj' },
},
});
expect(tolgee.t('hello')).toEqual('Hello');
expect(tolgee.t('hello', { language: 'cs' })).toEqual('Ahoj');
});
});

@@ -198,5 +198,5 @@ import { Events } from './Events/Events';

function getTranslation({ key, ns }: KeyAndNamespacesInternal) {
function getTranslation({ key, ns, language }: KeyAndNamespacesInternal) {
const namespaces = getDefaultAndFallbackNs(ns || undefined);
const languages = state.getFallbackLangs();
const languages = state.getFallbackLangs(language);
return cache.getTranslationFallback(namespaces, languages, key);

@@ -203,0 +203,0 @@ }

@@ -13,2 +13,3 @@ import {

params,
language,
...rest

@@ -20,2 +21,3 @@ }: Partial<TranslateProps>): Partial<TranslateProps> {

orEmpty: orEmpty!,
language: language!,
};

@@ -22,0 +24,0 @@ return {

@@ -25,2 +25,3 @@ export type FallbackGeneral = undefined | false | string | string[];

orEmpty?: boolean;
language?: string;
};

@@ -59,3 +60,3 @@

TranslatePropsInternal,
'key' | 'ns'
'key' | 'ns' | 'language'
>;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet