!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.i18nextFluentBackend=t()}(this,function(){"use strict";let e=[],t=e.forEach,n=e.slice;function s(e,t){if(t&&"object"==typeof t){let n="",s=encodeURIComponent;for(let e in t)n+="&"+s(e)+"="+s(t[e]);if(!n)return e;e=e+(-1!==e.indexOf("?")?"&":"?")+n.slice(1)}return e}function r(e,t,n,r,i){r&&"object"==typeof r&&(i||(r._t=new Date),r=s("",r).slice(1)),t.queryStringParams&&(e=s(e,t.queryStringParams));try{var a;(a=XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("MSXML2.XMLHTTP.3.0")).open(r?"POST":"GET",e,1),t.crossDomain||a.setRequestHeader("X-Requested-With","XMLHttpRequest"),a.withCredentials=!!t.withCredentials,r&&a.setRequestHeader("Content-type","application/x-www-form-urlencoded"),a.overrideMimeType&&a.overrideMimeType("application/json");var o=t.customHeaders;if(o)for(var c in o)a.setRequestHeader(c,o[c]);a.onreadystatechange=function(){a.readyState>3&&n&&n(a.responseText,a)},a.send(r)}catch(e){console&&console.log(e)}}class i{constructor(){this.type="BaseNode"}equals(e,t=["span"]){const n=new Set(Object.keys(this)),s=new Set(Object.keys(e));if(t)for(const e of t)n.delete(e),s.delete(e);if(n.size!==s.size)return!1;for(const r of n){if(!s.has(r))return!1;const n=this[r],i=e[r];if(typeof n!=typeof i)return!1;if(n instanceof Array&&i instanceof Array){if(n.length!==i.length)return!1;for(let e=0;e<n.length;++e)if(!a(n[e],i[e],t))return!1}else if(!a(n,i,t))return!1}return!0}clone(){function e(t){return t instanceof i?t.clone():Array.isArray(t)?t.map(e):t}const t=Object.create(this.constructor.prototype);for(const n of Object.keys(this))t[n]=e(this[n]);return t}}function a(e,t,n){return e instanceof i&&t instanceof i?e.equals(t,n):e===t}class o extends i{constructor(){super(...arguments),this.type="SyntaxNode"}addSpan(e,t){this.span=new N(e,t)}}class c extends o{constructor(e=[]){super(),this.type="Resource",this.body=e}}class h extends o{constructor(){super(...arguments),this.type="Entry"}}class u extends h{constructor(e,t=null,n=[],s=null){super(),this.type="Message",this.id=e,this.value=t,this.attributes=n,this.comment=s}}class l extends h{constructor(e,t,n=[],s=null){super(),this.type="Term",this.id=e,this.value=t,this.attributes=n,this.comment=s}}class p extends o{constructor(e){super(),this.type="Pattern",this.elements=e}}class f extends o{constructor(){super(...arguments),this.type="PatternElement"}}class d extends f{constructor(e){super(),this.type="TextElement",this.value=e}}class g extends f{constructor(e){super(),this.type="Placeable",this.expression=e}}class k extends o{constructor(){super(...arguments),this.type="Expression"}}class m extends k{constructor(e){super(),this.type="Literal",this.value=e}}class x extends m{constructor(){super(...arguments),this.type="StringLiteral"}parse(){return{value:this.value.replace(/(?:\\\\|\\"|\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{6}))/g,function(e,t,n){switch(e){case"\\\\":return"\\";case'\\"':return'"';default:{let e=parseInt(t||n,16);return e<=55295||57344<=e?String.fromCodePoint(e):"�"}}})}}}class w extends m{constructor(){super(...arguments),this.type="NumberLiteral"}parse(){let e=parseFloat(this.value),t=this.value.indexOf(".");return{value:e,precision:t>0?this.value.length-t-1:0}}}class E extends k{constructor(e,t=null){super(),this.type="MessageReference",this.id=e,this.attribute=t}}class C extends k{constructor(e,t=null,n=null){super(),this.type="TermReference",this.id=e,this.attribute=t,this.arguments=n}}class y extends k{constructor(e){super(),this.type="VariableReference",this.id=e}}class b extends k{constructor(e,t){super(),this.type="FunctionReference",this.id=e,this.arguments=t}}class v extends k{constructor(e,t){super(),this.type="SelectExpression",this.selector=e,this.variants=t}}class P extends o{constructor(e=[],t=[]){super(),this.type="CallArguments",this.positional=e,this.named=t}}class S extends o{constructor(e,t){super(),this.type="Attribute",this.id=e,this.value=t}}class B extends o{constructor(e,t,n){super(),this.type="Variant",this.key=e,this.value=t,this.default=n}}class I extends o{constructor(e,t){super(),this.type="NamedArgument",this.name=e,this.value=t}}class A extends o{constructor(e){super(),this.type="Identifier",this.name=e}}class T extends h{constructor(e){super(),this.type="BaseComment",this.content=e}}class O extends T{constructor(){super(...arguments),this.type="Comment"}}class $ extends T{constructor(){super(...arguments),this.type="GroupComment"}}class V extends T{constructor(){super(...arguments),this.type="ResourceComment"}}class L extends o{constructor(e){super(),this.type="Junk",this.annotations=[],this.content=e}addAnnotation(e){this.annotations.push(e)}}class N extends i{constructor(e,t){super(),this.type="Span",this.start=e,this.end=t}}class j extends o{constructor(e,t=[],n){super(),this.type="Annotation",this.code=e,this.arguments=t,this.message=n}}class q extends Error{constructor(e,...t){super(),this.code=e,this.args=t,this.message=function(e,t){switch(e){case"E0001":return"Generic error";case"E0002":return"Expected an entry start";case"E0003":{const[e]=t;return`Expected token: "${e}"`}case"E0004":{const[e]=t;return`Expected a character from range: "${e}"`}case"E0005":{const[e]=t;return`Expected message "${e}" to have a value or attributes`}case"E0006":{const[e]=t;return`Expected term "-${e}" to have a value`}case"E0007":return"Keyword cannot end with a whitespace";case"E0008":return"The callee has to be an upper-case identifier or a term";case"E0009":return"The argument name has to be a simple identifier";case"E0010":return"Expected one of the variants to be marked as default (*)";case"E0011":return'Expected at least one variant after "->"';case"E0012":return"Expected value";case"E0013":return"Expected variant key";case"E0014":return"Expected literal";case"E0015":return"Only one variant can be marked as default (*)";case"E0016":return"Message references cannot be used as selectors";case"E0017":return"Terms cannot be used as selectors";case"E0018":return"Attributes of messages cannot be used as selectors";case"E0019":return"Attributes of terms cannot be used as placeables";case"E0020":return"Unterminated string expression";case"E0021":return"Positional arguments must not follow named arguments";case"E0022":return"Named arguments must be unique";case"E0024":return"Cannot access variants of a message.";case"E0025":{const[e]=t;return`Unknown escape sequence: \\${e}.`}case"E0026":{const[e]=t;return`Invalid Unicode escape sequence: ${e}.`}case"E0027":return"Unbalanced closing brace in TextElement.";case"E0028":return"Expected an inline expression";case"E0029":return"Expected simple expression as selector";default:return e}}(e,t)}}class R{constructor(e){this.string=e,this.index=0,this.peekOffset=0}charAt(e){return"\r"===this.string[e]&&"\n"===this.string[e+1]?"\n":this.string[e]}currentChar(){return this.charAt(this.index)}currentPeek(){return this.charAt(this.index+this.peekOffset)}next(){return this.peekOffset=0,"\r"===this.string[this.index]&&"\n"===this.string[this.index+1]&&this.index++,this.index++,this.string[this.index]}peek(){return"\r"===this.string[this.index+this.peekOffset]&&"\n"===this.string[this.index+this.peekOffset+1]&&this.peekOffset++,this.peekOffset++,this.string[this.index+this.peekOffset]}resetPeek(e=0){this.peekOffset=e}skipToPeek(){this.index+=this.peekOffset,this.peekOffset=0}}const M="\n",D=void 0,U=["}",".","[","*"];class H extends R{peekBlankInline(){const e=this.index+this.peekOffset;for(;" "===this.currentPeek();)this.peek();return this.string.slice(e,this.index+this.peekOffset)}skipBlankInline(){const e=this.peekBlankInline();return this.skipToPeek(),e}peekBlankBlock(){let e="";for(;;){const t=this.peekOffset;if(this.peekBlankInline(),this.currentPeek()!==M)return this.currentPeek()===D?e:(this.resetPeek(t),e);e+=M,this.peek()}}skipBlankBlock(){const e=this.peekBlankBlock();return this.skipToPeek(),e}peekBlank(){for(;" "===this.currentPeek()||this.currentPeek()===M;)this.peek()}skipBlank(){this.peekBlank(),this.skipToPeek()}expectChar(e){if(this.currentChar()!==e)throw new q("E0003",e);this.next()}expectLineEnd(){if(this.currentChar()!==D){if(this.currentChar()!==M)throw new q("E0003","␤");this.next()}}takeChar(e){const t=this.currentChar();return t===D?D:e(t)?(this.next(),t):null}isCharIdStart(e){if(e===D)return!1;const t=e.charCodeAt(0);return t>=97&&t<=122||t>=65&&t<=90}isIdentifierStart(){return this.isCharIdStart(this.currentPeek())}isNumberStart(){const e="-"===this.currentChar()?this.peek():this.currentChar();if(e===D)return this.resetPeek(),!1;const t=e.charCodeAt(0),n=t>=48&&t<=57;return this.resetPeek(),n}isCharPatternContinuation(e){return e!==D&&!U.includes(e)}isValueStart(){const e=this.currentPeek();return e!==M&&e!==D}isValueContinuation(){const e=this.peekOffset;return this.peekBlankInline(),"{"===this.currentPeek()?(this.resetPeek(e),!0):this.peekOffset-e!=0&&(!!this.isCharPatternContinuation(this.currentPeek())&&(this.resetPeek(e),!0))}isNextLineComment(e=-1){if(this.currentChar()!==M)return!1;let t=0;for(;t<=e||-1===e&&t<3;){if("#"!==this.peek()){if(t<=e&&-1!==e)return this.resetPeek(),!1;break}t++}const n=this.peek();return" "===n||n===M?(this.resetPeek(),!0):(this.resetPeek(),!1)}isVariantStart(){const e=this.peekOffset;return"*"===this.currentPeek()&&this.peek(),"["===this.currentPeek()?(this.resetPeek(e),!0):(this.resetPeek(e),!1)}isAttributeStart(){return"."===this.currentPeek()}skipToNextEntryStart(e){let t=this.string.lastIndexOf(M,this.index);for(e<t&&(this.index=t);this.currentChar();){if(this.currentChar()!==M){this.next();continue}const e=this.next();if(this.isCharIdStart(e)||"-"===e||"#"===e)break}}takeIDStart(){if(this.isCharIdStart(this.currentChar())){const e=this.currentChar();return this.next(),e}throw new q("E0004","a-zA-Z")}takeIDChar(){return this.takeChar(e=>{const t=e.charCodeAt(0);return t>=97&&t<=122||t>=65&&t<=90||t>=48&&t<=57||95===t||45===t})}takeDigit(){return this.takeChar(e=>{const t=e.charCodeAt(0);return t>=48&&t<=57})}takeHexDigit(){return this.takeChar(e=>{const t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102})}}const G=/[ \t\n\r]+$/;function z(e){return function(t,...n){if(!this.withSpans)return e.call(this,t,...n);const s=t.index,r=e.call(this,t,...n);if(r.span)return r;const i=t.index;return r.addSpan(s,i),r}}class X{constructor({withSpans:e=!0}={}){this.withSpans=e,this.getComment=z(this.getComment),this.getMessage=z(this.getMessage),this.getTerm=z(this.getTerm),this.getAttribute=z(this.getAttribute),this.getIdentifier=z(this.getIdentifier),this.getVariant=z(this.getVariant),this.getNumber=z(this.getNumber),this.getPattern=z(this.getPattern),this.getTextElement=z(this.getTextElement),this.getPlaceable=z(this.getPlaceable),this.getExpression=z(this.getExpression),this.getInlineExpression=z(this.getInlineExpression),this.getCallArgument=z(this.getCallArgument),this.getCallArguments=z(this.getCallArguments),this.getString=z(this.getString),this.getLiteral=z(this.getLiteral),this.getComment=z(this.getComment)}parse(e){const t=new H(e);t.skipBlankBlock();const n=[];let s=null;for(;t.currentChar();){const e=this.getEntryOrJunk(t),r=t.skipBlankBlock();e instanceof O&&0===r.length&&t.currentChar()?s=e:(s&&(e instanceof u||e instanceof l?(e.comment=s,this.withSpans&&(e.span.start=e.comment.span.start)):n.push(s),s=null),n.push(e))}const r=new c(n);return this.withSpans&&r.addSpan(0,t.index),r}parseEntry(e){const t=new H(e);for(t.skipBlankBlock();"#"===t.currentChar();){const e=this.getEntryOrJunk(t);if(e instanceof L)return e;t.skipBlankBlock()}return this.getEntryOrJunk(t)}getEntryOrJunk(e){const t=e.index;try{const n=this.getEntry(e);return e.expectLineEnd(),n}catch(n){if(!(n instanceof q))throw n;let s=e.index;e.skipToNextEntryStart(t);const r=e.index;r<s&&(s=r);const i=e.string.substring(t,r),a=new L(i);this.withSpans&&a.addSpan(t,r);const o=new j(n.code,n.args,n.message);return o.addSpan(s,s),a.addAnnotation(o),a}}getEntry(e){if("#"===e.currentChar())return this.getComment(e);if("-"===e.currentChar())return this.getTerm(e);if(e.isIdentifierStart())return this.getMessage(e);throw new q("E0002")}getComment(e){let t,n=-1,s="";for(;;){let t=-1;for(;"#"===e.currentChar()&&t<(-1===n?2:n);)e.next(),t++;if(-1===n&&(n=t),e.currentChar()!==M){let t;for(e.expectChar(" ");t=e.takeChar(e=>e!==M);)s+=t}if(!e.isNextLineComment(n))break;s+=e.currentChar(),e.next()}switch(n){case 0:t=O;break;case 1:t=$;break;default:t=V}return new t(s)}getMessage(e){const t=this.getIdentifier(e);e.skipBlankInline(),e.expectChar("=");const n=this.maybeGetPattern(e),s=this.getAttributes(e);if(null===n&&0===s.length)throw new q("E0005",t.name);return new u(t,n,s)}getTerm(e){e.expectChar("-");const t=this.getIdentifier(e);e.skipBlankInline(),e.expectChar("=");const n=this.maybeGetPattern(e);if(null===n)throw new q("E0006",t.name);const s=this.getAttributes(e);return new l(t,n,s)}getAttribute(e){e.expectChar(".");const t=this.getIdentifier(e);e.skipBlankInline(),e.expectChar("=");const n=this.maybeGetPattern(e);if(null===n)throw new q("E0012");return new S(t,n)}getAttributes(e){const t=[];for(e.peekBlank();e.isAttributeStart();){e.skipToPeek();const n=this.getAttribute(e);t.push(n),e.peekBlank()}return t}getIdentifier(e){let t,n=e.takeIDStart();for(;t=e.takeIDChar();)n+=t;return new A(n)}getVariantKey(e){const t=e.currentChar();if(t===D)throw new q("E0013");const n=t.charCodeAt(0);return n>=48&&n<=57||45===n?this.getNumber(e):this.getIdentifier(e)}getVariant(e,t=!1){let n=!1;if("*"===e.currentChar()){if(t)throw new q("E0015");e.next(),n=!0}e.expectChar("["),e.skipBlank();const s=this.getVariantKey(e);e.skipBlank(),e.expectChar("]");const r=this.maybeGetPattern(e);if(null===r)throw new q("E0012");return new B(s,r,n)}getVariants(e){const t=[];let n=!1;for(e.skipBlank();e.isVariantStart();){const s=this.getVariant(e,n);s.default&&(n=!0),t.push(s),e.expectLineEnd(),e.skipBlank()}if(0===t.length)throw new q("E0011");if(!n)throw new q("E0010");return t}getDigits(e){let t,n="";for(;t=e.takeDigit();)n+=t;if(0===n.length)throw new q("E0004","0-9");return n}getNumber(e){let t="";return"-"===e.currentChar()?(e.next(),t+=`-${this.getDigits(e)}`):t+=this.getDigits(e),"."===e.currentChar()&&(e.next(),t+=`.${this.getDigits(e)}`),new w(t)}maybeGetPattern(e){return e.peekBlankInline(),e.isValueStart()?(e.skipToPeek(),this.getPattern(e,!1)):(e.peekBlankBlock(),e.isValueContinuation()?(e.skipToPeek(),this.getPattern(e,!0)):null)}getPattern(e,t){const n=[];let s,r;if(t){const t=e.index,r=e.skipBlankInline();n.push(this.getIndent(e,r,t)),s=r.length}else s=1/0;e:for(;r=e.currentChar();)switch(r){case M:{const t=e.index,r=e.peekBlankBlock();if(e.isValueContinuation()){e.skipToPeek();const i=e.skipBlankInline();s=Math.min(s,i.length),n.push(this.getIndent(e,r+i,t));continue e}e.resetPeek();break e}case"{":n.push(this.getPlaceable(e));continue e;case"}":throw new q("E0027");default:n.push(this.getTextElement(e))}const i=this.dedent(n,s);return new p(i)}getIndent(e,t,n){return new F(t,n,e.index)}dedent(e,t){const n=[];for(let s of e){if(s instanceof g){n.push(s);continue}if(s instanceof F&&(s.value=s.value.slice(0,s.value.length-t),0===s.value.length))continue;let e=n[n.length-1];if(e&&e instanceof d){const t=new d(e.value+s.value);this.withSpans&&t.addSpan(e.span.start,s.span.end),n[n.length-1]=t}else{if(s instanceof F){const e=new d(s.value);this.withSpans&&e.addSpan(s.span.start,s.span.end),s=e}n.push(s)}}const s=n[n.length-1];return s instanceof d&&(s.value=s.value.replace(G,""),0===s.value.length&&n.pop()),n}getTextElement(e){let t,n="";for(;t=e.currentChar();){if("{"===t||"}"===t)return new d(n);if(t===M)return new d(n);n+=t,e.next()}return new d(n)}getEscapeSequence(e){const t=e.currentChar();switch(t){case"\\":case'"':return e.next(),`\\${t}`;case"u":return this.getUnicodeEscapeSequence(e,t,4);case"U":return this.getUnicodeEscapeSequence(e,t,6);default:throw new q("E0025",t)}}getUnicodeEscapeSequence(e,t,n){e.expectChar(t);let s="";for(let r=0;r<n;r++){const n=e.takeHexDigit();if(!n)throw new q("E0026",`\\${t}${s}${e.currentChar()}`);s+=n}return`\\${t}${s}`}getPlaceable(e){e.expectChar("{"),e.skipBlank();const t=this.getExpression(e);return e.expectChar("}"),new g(t)}getExpression(e){const t=this.getInlineExpression(e);if(e.skipBlank(),"-"===e.currentChar()){if(">"!==e.peek())return e.resetPeek(),t;if(t instanceof E)throw null===t.attribute?new q("E0016"):new q("E0018");if(t instanceof C){if(null===t.attribute)throw new q("E0017")}else if(t instanceof g)throw new q("E0029");e.next(),e.next(),e.skipBlankInline(),e.expectLineEnd();const n=this.getVariants(e);return new v(t,n)}if(t instanceof C&&null!==t.attribute)throw new q("E0019");return t}getInlineExpression(e){if("{"===e.currentChar())return this.getPlaceable(e);if(e.isNumberStart())return this.getNumber(e);if('"'===e.currentChar())return this.getString(e);if("$"===e.currentChar()){e.next();const t=this.getIdentifier(e);return new y(t)}if("-"===e.currentChar()){e.next();const t=this.getIdentifier(e);let n,s;return"."===e.currentChar()&&(e.next(),n=this.getIdentifier(e)),e.peekBlank(),"("===e.currentPeek()&&(e.skipToPeek(),s=this.getCallArguments(e)),new C(t,n,s)}if(e.isIdentifierStart()){const t=this.getIdentifier(e);if(e.peekBlank(),"("===e.currentPeek()){if(!/^[A-Z][A-Z0-9_-]*$/.test(t.name))throw new q("E0008");e.skipToPeek();let n=this.getCallArguments(e);return new b(t,n)}let n;return"."===e.currentChar()&&(e.next(),n=this.getIdentifier(e)),new E(t,n)}throw new q("E0028")}getCallArgument(e){const t=this.getInlineExpression(e);if(e.skipBlank(),":"!==e.currentChar())return t;if(t instanceof E&&null===t.attribute){e.next(),e.skipBlank();const n=this.getLiteral(e);return new I(t.id,n)}throw new q("E0009")}getCallArguments(e){const t=[],n=[],s=new Set;for(e.expectChar("("),e.skipBlank();")"!==e.currentChar();){const r=this.getCallArgument(e);if(r instanceof I){if(s.has(r.name.name))throw new q("E0022");n.push(r),s.add(r.name.name)}else{if(s.size>0)throw new q("E0021");t.push(r)}if(e.skipBlank(),","!==e.currentChar())break;e.next(),e.skipBlank()}return e.expectChar(")"),new P(t,n)}getString(e){e.expectChar('"');let t,n="";for(;t=e.takeChar(e=>'"'!==e&&e!==M);)n+="\\"===t?this.getEscapeSequence(e):t;if(e.currentChar()===M)throw new q("E0020");return e.expectChar('"'),new x(n)}getLiteral(e){if(e.isNumberStart())return this.getNumber(e);if('"'===e.currentChar())return this.getString(e);throw new q("E0014")}}class F{constructor(e,t,n){this.type="Indent",this.value=e,this.span=new N(t,n)}}const J=e=>"get"+e.type;var K={serialize(e){if(this[J(e)])return this[J(e)](e);console.warn("unknown type:",e.type,e)},getComment:e=>({key:"comment",value:e.content}),getGroupComment:()=>null,getResourceComment:()=>null,getMessage(e){return{key:this[J(e.id)](e.id),value:this[J(e.value)](e.value),comment:e.comment&&this[J(e.comment)](e.comment),attributes:e.attributes&&e.attributes.map(e=>this.serialize(e))}},getAttribute(e){return{key:this[J(e.id)](e.id),value:this[J(e.value)](e.value)}},getTerm(e){return{key:`-${this[J(e.id)](e.id)}`,value:this[J(e.value)](e.value),comment:e.comment&&this[J(e.comment)](e.comment),attributes:e.attributes&&e.attributes.map(e=>this.serialize(e))}},getIdentifier:e=>e.name,getStringLiteral:e=>e.value,getPattern(e){return e.elements.map(e=>e.expression?this[J(e.expression)]?this[J(e.expression)](e.expression):console.log("unknown1",J(e.expression),e.expression):this[J(e)]?this[J(e)](e):console.log("unknown2",J(e),e)).join("")},getCallExpression(e){const t=e.callee.name,n=e.positional.map(e=>this[J(e)](e,!0)),s=e.named.map(e=>this[J(e)](e));return"{ "+t+"($"+n.join(" ")+(s.length?", "+s.join(", "):"")+") }"},getNamedArgument(e){return this[J(e.name)](e.name)+': "'+this[J(e.value)](e.value)+'"'},getTextElement:e=>e.value,getSelectExpression(e){return"{ $"+this[J(e.selector)](e.selector,!0)+" ->\n"+e.variants.map(e=>this[J(e)](e)).join("\n")+"\n}"},getVariantExpression(e){const t=this[J(e.ref)](e.ref,!0),n=this[J(e.key)](e.key);return n?"{ "+t+"["+n+"] }":" { "+t+" } "},getVariableReference(e,t){return t?this[J(e.id)](e.id):"{ $"+this[J(e.id)](e.id)+" }"},getTermReferences(e,t){return t?this[J(e.id)](e.id):"{ "+this[J(e.id)](e.id)+" }"},getVariantName:e=>e.name,getVariantList(e){return"{\n"+e.variants.map(e=>this[J(e)](e)).join("\n")+"\n}"},getVariant(e){const t=e.key.name?e.key.name:e.key.value,n=e.default,s="["+t+"] "+this[J(e.value)](e.value);return n?" *"+s:"  "+s},getFunctionReference(e){let t="";return e.arguments.positional.forEach((e,n)=>{n>0&&(t+=", "),t+=`$${e.id.name}`}),e.arguments.named.forEach((e,n)=>{(n>0||""!==t)&&(t+=", "),t+=`${e.name.name}: "${e.value.value}"`}),`{ ${e.id.name}(${t}) }`},getTermReference:e=>`{ -${e.id.name} }`,getJunk(e){const t=e.content.split("=");return{key:t.shift().trim(),value:t.join("=").trim().replace(/\n {3}/g,"\n ").replace(/\n {2}}/g,"\n}")}}};function Z(e,t,n={respectComments:!0}){if("string"!=typeof e){if(!t)throw new Error("The first parameter was not a string");return t(new Error("The first parameter was not a string"))}var s;const r=(s=e,new X({withSpans:!1}).parse(s)).body.reduce((e,t)=>{const s=K.serialize(t);if(!s)return e;if(s.attributes&&s.attributes.length||s.comment&&n.respectComments){const t={};s.comment&&(t[s.comment.key]=s.comment.value),s.attributes&&s.attributes.length&&s.attributes.forEach(e=>{t[e.key]=e.value}),t.val=s.value,e[s.key]=t}else e[s.key]=s.value;return e},{});return t&&t(null,r),r}class _{constructor(e,t={}){this.init(e,t),this.type="backend"}init(e,s={}){this.services=e,this.options=function(e){return t.call(n.call(arguments,1),function(t){if(t)for(var n in t)void 0===e[n]&&(e[n]=t[n])}),e}(s,this.options||{},{loadPath:"/locales/{{lng}}/{{ns}}.ftl",addPath:"/locales/add/{{lng}}/{{ns}}",parse:function(e,t){return Z(e)},crossDomain:!1,ajax:r})}read(e,t,n){var s=this.options.loadPath;"function"==typeof this.options.loadPath&&(s=this.options.loadPath([e],[t]));let r=this.services.interpolator.interpolate(s,{lng:e,ns:t});this.loadUrl(r,n)}loadUrl(e,t){this.options.ajax(e,this.options,(n,s)=>{if(s.status>=500&&s.status<600)return t("failed loading "+e,!0);if(s.status>=400&&s.status<500)return t("failed loading "+e,!1);let r,i;try{r=this.options.parse(n,e)}catch(t){i="failed parsing "+e+" to json"}if(i)return t(i,!1);t(null,r)})}create(e,t,n,s){"string"==typeof e&&(e=[e]);let r={};r[n]=s||"",e.forEach(e=>{let n=this.services.interpolator.interpolate(this.options.addPath,{lng:e,ns:t});this.options.ajax(n,this.options,function(e,t){},r)})}}return _.type="backend",_});
