UNPKG

@ngx-i18nsupport/ngx-i18nsupport-lib

Version:

A Typescript library to work with Angular generated i18n files (xliff, xmb)

2 lines 72.7 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("util"),require("xmldom"),require("tokenizr")):"function"==typeof define&&define.amd?define("@ngx-i18nsupport/ngx-i18nsupport-lib",["exports","@angular/core","util","xmldom","tokenizr"],t):t(((e=e||self)["ngx-i18nsupport"]=e["ngx-i18nsupport"]||{},e["ngx-i18nsupport"]["ngx-i18nsupport-lib"]={}),e.ng.core,e.util,e.xmldom,e.tokenizr)}(this,function(e,t,n,r,i){"use strict";var a=function(e,t){return(a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function o(e,t){function n(){this.constructor=e}a(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function s(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,i,a=n.call(e),o=[];try{for(;(void 0===t||t-- >0)&&!(r=a.next()).done;)o.push(r.value)}catch(s){i={error:s}}finally{try{r&&!r.done&&(n=a["return"])&&n.call(a)}finally{if(i)throw i.error}}return o}var u=function(){function e(){}return e.decorators=[{type:t.NgModule,args:[{imports:[],declarations:[],exports:[]}]}],e}(),l=function(){function e(){}return e.getFirstElementByTagName=function(e,t){var n=e.getElementsByTagName(t);return n&&n.length>0?n.item(0):null},e.getElementByTagNameAndId=function(e,t,n){var r=e.getElementsByTagName(t);if(r&&r.length>0)for(var i=0;i<r.length;i++){var a=r.item(i);if(a.getAttribute("id")===n)return a}return null},e.getElementFollowingSibling=function(e){if(!e)return null;for(var t=e.nextSibling;t;){if(t.nodeType===t.ELEMENT_NODE)return t;t=t.nextSibling}return null},e.getElementPrecedingSibling=function(e){if(!e)return null;for(var t=e.previousSibling;t;){if(t.nodeType===t.ELEMENT_NODE)return t;t=t.previousSibling}return null},e.getXMLContent=function(e){if(!e)return null;var t=(new r.XMLSerializer).serializeToString(e),n=e.nodeName,i=new RegExp("<"+n+"[^>]*>","g");t=t.replace(i,"");var a=new RegExp("</"+n+">","g");return t=t.replace(a,"")},e.getPCDATA=function(e){if(!e)return null;for(var t="",n=e.childNodes,r=0;r<n.length;r++){var i=n.item(r);i.nodeType!==i.TEXT_NODE&&i.nodeType!==i.CDATA_SECTION_NODE||(t+=i.nodeValue)}return 0===t.length?null:t},e.replaceContentWithXMLContent=function(e,t){for(;e.firstChild;)e.removeChild(e.firstChild);for(var n=(new r.DOMParser).parseFromString("<fragment>"+t+"</fragment>","application/xml").getElementsByTagName("fragment").item(0).childNodes,i=0;i<n.length;i++){var a=n.item(i);e.appendChild(e.ownerDocument.importNode(a,!0))}},e.getPreviousElementSibling=function(e){for(var t=e.previousSibling;null!==t;){if(t.nodeType===t.ELEMENT_NODE)return t;t=t.previousSibling}return null},e.createFollowingSibling=function(t,n){var r=n.ownerDocument.createElement(t);return e.insertAfter(r,n)},e.insertAfter=function(e,t){return null!==t.nextSibling?t.parentNode.insertBefore(e,t.nextSibling):t.parentNode.appendChild(e),e},e.insertBefore=function(e,t){return t.parentNode.insertBefore(e,t),e},e}(),p=function(){function e(){}return e.prototype.serializeToString=function(e,t){var n=[],r=[],i=e.documentElement,a=i.prefix,o=i.namespaceURI;if(o&&null==a&&null==(a=i.lookupPrefix(o))&&(r=[{namespace:o,prefix:null}]),t||(t={}),t.indentString&&!this.containsOnlyWhiteSpace(t.indentString))throw new Error("indentString must not contain non white characters");return this.doSerializeToString(e,t,n,0,!1,r),n.join("")},e.prototype.doSerializeToString=function(e,t,n,r,i,a){var o;switch(e.nodeType){case e.ELEMENT_NODE:var s=e,u=s.attributes,l=u.length;o=s.firstChild;var p=s.tagName,c=this.isMixedContentElement(p,t);i?n.push("<",p):this.outputIndented(t,n,r,"<",p);for(var m=0;m<l;m++){"xmlns"===(f=u.item(m)).prefix?a.push({prefix:f.localName,namespace:f.value}):"xmlns"===f.nodeName&&a.push({prefix:"",namespace:f.value})}for(m=0;m<l;m++){var f=u.item(m);if(this.needNamespaceDefine(f,a)){var h=f.prefix||"",g=f.namespaceURI,d=h?" xmlns:"+h:" xmlns";n.push(d,'="',g,'"'),a.push({prefix:h,namespace:g})}this.doSerializeToString(f,t,n,r,!1,a)}if(this.needNamespaceDefine(s,a)){h=s.prefix||"",g=e.namespaceURI,d=h?" xmlns:"+h:" xmlns";n.push(d,'="',g,'"'),a.push({prefix:h,namespace:g})}if(o){n.push(">");for(var T=!1;o;)o.nodeType===o.ELEMENT_NODE&&(T=!0),this.doSerializeToString(o,t,n,r+1,i||c,a),o=o.nextSibling;i||c||!T?n.push("</",p,">"):this.outputIndented(t,n,r,"</",p,">")}else n.push("/>");return;case e.DOCUMENT_NODE:case e.DOCUMENT_FRAGMENT_NODE:for(o=e.firstChild;o;)this.doSerializeToString(o,t,n,r,!1,a),o=o.nextSibling;return;case e.ATTRIBUTE_NODE:var E=e;return n.push(" ",E.name,'="',E.value.replace(/[<&"]/g,this._xmlEncoder),'"');case e.TEXT_NODE:var y=e;return t.beautify&&!i&&this.containsOnlyWhiteSpace(y.data)?void 0:n.push(y.data.replace(/[<&]/g,this._xmlEncoder));case e.CDATA_SECTION_NODE:var N=e;return n.push("<![CDATA[",N.data,"]]>");case e.COMMENT_NODE:var _=e;return n.push("\x3c!--",_.data,"--\x3e");case e.DOCUMENT_TYPE_NODE:var v=e,C=v.publicId,A=v.systemId;return n.push("<!DOCTYPE ",v.name),void(C?(n.push(' PUBLIC "',C),A&&"."!==A&&n.push('" "',A),n.push('">')):A&&"."!==A?n.push(' SYSTEM "',A,'">'):n.push(">"));case e.PROCESSING_INSTRUCTION_NODE:var S=e;return n.push("<?",S.target," ",S.data,"?>");case e.ENTITY_REFERENCE_NODE:return n.push("&",e.nodeName,";");default:n.push("??",e.nodeName)}},e.prototype.needNamespaceDefine=function(e,t){var n=e.prefix||"",r=e.namespaceURI;if(!n&&!r)return!1;if("xml"===n&&"http://www.w3.org/XML/1998/namespace"===r||"http://www.w3.org/2000/xmlns/"===r)return!1;for(var i=t.length;i--;){var a=t[i];if(a.prefix===n)return a.namespace!==r}return!0},e.prototype._xmlEncoder=function(e){return("<"===e?"&lt;":">"===e&&"&gt;")||"&"===e&&"&amp;"||'"'===e&&"&quot;"||"&#"+e.charCodeAt(0)+";"},e.prototype.outputIndented=function(e,t,n){for(var r=[],i=3;i<arguments.length;i++)r[i-3]=arguments[i];e.beautify&&(t.push("\n"),n>0&&t.push(this.indentationString(e,n))),t.push.apply(t,function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(s(arguments[t]));return e}(r))},e.prototype.indentationString=function(e,t){for(var n=e.indentString?e.indentString:"  ",r="",i=0;i<t;i++)r+=n;return r},e.prototype.isMixedContentElement=function(e,t){return!(!t||!t.mixedContentElements)&&!!t.mixedContentElements.find(function(t){return t===e})},e.prototype.containsOnlyWhiteSpace=function(e){for(var t=0;t<e.length;t++){var n=e.charAt(t);if(" "!==n&&"\t"!==n&&"\r"!==n&&"\n"!==n)return!1}return!0},e}(),c=function(){function e(){this.transUnits=null,this._warnings=[]}return e.prototype.parseContent=function(e,t,n,i){this._filename=t,this._encoding=n,this._parsedDocument=(new r.DOMParser).parseFromString(e,"text/xml"),this._fileEndsWithEOL=e.endsWith("\n")},e.prototype.lazyInitializeTransUnits=function(){n.isNullOrUndefined(this.transUnits)&&(this.initializeTransUnits(),this.countNumbers())},e.prototype.countNumbers=function(){var e=this;this._numberOfTransUnitsWithMissingId=0,this._numberOfUntranslatedTransUnits=0,this._numberOfReviewedTransUnits=0,this.forEachTransUnit(function(t){(n.isNullOrUndefined(t.id)||""===t.id)&&e._numberOfTransUnitsWithMissingId++;var r=t.targetState();(n.isNullOrUndefined(r)||"new"===r)&&e._numberOfUntranslatedTransUnits++,"translated"===r&&e._numberOfReviewedTransUnits++})},e.prototype.warnings=function(){return this.lazyInitializeTransUnits(),this._warnings},e.prototype.numberOfTransUnits=function(){return this.lazyInitializeTransUnits(),this.transUnits.length},e.prototype.numberOfUntranslatedTransUnits=function(){return this.lazyInitializeTransUnits(),this._numberOfUntranslatedTransUnits},e.prototype.numberOfReviewedTransUnits=function(){return this.lazyInitializeTransUnits(),this._numberOfReviewedTransUnits},e.prototype.numberOfTransUnitsWithMissingId=function(){return this.lazyInitializeTransUnits(),this._numberOfTransUnitsWithMissingId},e.prototype.forEachTransUnit=function(e){this.lazyInitializeTransUnits(),this.transUnits.forEach(function(t){return e(t)})},e.prototype.transUnitWithId=function(e){return this.lazyInitializeTransUnits(),this.transUnits.find(function(t){return t.id===e})},e.prototype.setNewTransUnitTargetPraefix=function(e){this.targetPraefix=e},e.prototype.getNewTransUnitTargetPraefix=function(){return n.isNullOrUndefined(this.targetPraefix)?"":this.targetPraefix},e.prototype.setNewTransUnitTargetSuffix=function(e){this.targetSuffix=e},e.prototype.getNewTransUnitTargetSuffix=function(){return n.isNullOrUndefined(this.targetSuffix)?"":this.targetSuffix},e.prototype.removeTransUnitWithId=function(e){var t=this._parsedDocument.getElementById(e);t&&(t.parentNode.removeChild(t),this.lazyInitializeTransUnits(),this.transUnits=this.transUnits.filter(function(t){return t.id!==e}),this.countNumbers())},e.prototype.filename=function(){return this._filename},e.prototype.encoding=function(){return this._encoding},e.prototype.editedContent=function(e){var t={};!0===e&&(t.beautify=!0,t.indentString="  ",t.mixedContentElements=this.elementsWithMixedContent());var n=(new p).serializeToString(this._parsedDocument,t);return this._fileEndsWithEOL?n+"\n":n},e}(),m=function(){function e(e,t,n){this._element=e,this._id=t,this._translationMessagesFile=n}return Object.defineProperty(e.prototype,"id",{get:function(){return this._id},enumerable:!0,configurable:!0}),e.prototype.translationMessagesFile=function(){return this._translationMessagesFile},e.prototype.supportsSetSourceContent=function(){return!0},e.prototype.sourceContentNormalized=function(){return n.isNullOrUndefined(this._sourceContentNormalized)&&(this._sourceContentNormalized=this.createSourceContentNormalized()),this._sourceContentNormalized},e.prototype.targetState=function(){var e=this.nativeTargetState();return this.mapNativeStateToState(e)},e.prototype.setTargetState=function(e){this.setNativeTargetState(this.mapStateToNativeState(e)),this.translationMessagesFile()instanceof c&&this.translationMessagesFile().countNumbers()},e.prototype.supportsSetSourceReferences=function(){return!0},e.prototype.supportsSetDescriptionAndMeaning=function(){return!0},e.prototype.checkNotes=function(e){var t=e.find(function(e){return"description"===e.from||"meaning"===e.from});if(!n.isNullOrUndefined(t))throw new Error("description or meaning are not allowed as from atttribute")},e.prototype.asXmlElement=function(){return this._element},e.prototype.translate=function(e){var t;t=n.isString(e)?e:e.asNativeString(),this.translateNative(t),this.setTargetState("translated")},e.prototype.isICUMessage=function(e){return this.messageParser().isICUMessageStart(e)},e}(),f={TEXT:0,PLACEHOLDER:1,START_TAG:2,END_TAG:3,EMPTY_TAG:4,ICU_MESSAGE:5,ICU_MESSAGE_REF:6};f[f.TEXT]="TEXT",f[f.PLACEHOLDER]="PLACEHOLDER",f[f.START_TAG]="START_TAG",f[f.END_TAG]="END_TAG",f[f.EMPTY_TAG]="EMPTY_TAG",f[f.ICU_MESSAGE]="ICU_MESSAGE",f[f.ICU_MESSAGE_REF]="ICU_MESSAGE_REF";var h=function(){return function(e){this.type=e}}(),g=function(e){function t(t){var n=e.call(this,f.TEXT)||this;return n.text=t,n}return o(t,e),t.prototype.asDisplayString=function(e){return this.text},t}(h),d=function(e){function t(t,n){var r=e.call(this,f.PLACEHOLDER)||this;return r._index=t,r._disp=n,r}return o(t,e),t.prototype.asDisplayString=function(e){return"{{"+this._index+"}}"},t.prototype.index=function(){return this._index},t.prototype.disp=function(){return this._disp},t}(h),T=function(e){function t(t,n){var r=e.call(this,f.START_TAG)||this;return r._tagname=t,r._idcounter=n,r}return o(t,e),t.prototype.asDisplayString=function(e){return 0===this._idcounter?"<"+this._tagname+">":"<"+this._tagname+' id="'+this._idcounter.toString()+'">'},t.prototype.tagName=function(){return this._tagname},t.prototype.idCounter=function(){return this._idcounter},t}(h),E=function(e){function t(t){var n=e.call(this,f.END_TAG)||this;return n._tagname=t,n}return o(t,e),t.prototype.asDisplayString=function(e){return"</"+this._tagname+">"},t.prototype.tagName=function(){return this._tagname},t}(h),y="TEXT",N=function(){function e(){}return e.prototype.getLexer=function(){var e=this,t=new i,n="",r=0;return t.before(function(t,r,i){i.name!==y&&(e.containsNonWhiteSpace(n)?(t.accept(y,n),n=""):t.ignore())}),t.finish(function(t){e.containsNonWhiteSpace(n)&&t.accept(y,n)}),t.rule("default",/{/,function(e,t){e.accept("CURLY_BRACE_OPEN",t[0]),e.push("normal")},"CURLY_BRACE_OPEN"),t.rule("normal",/{/,function(e,t){e.accept("CURLY_BRACE_OPEN",t[0]),e.push("in_message")},"CURLY_BRACE_OPEN"),t.rule("normal",/}/,function(e,t){e.pop(),e.accept("CURLY_BRACE_CLOSE",t[0])},"CURLY_BRACE_CLOSE"),t.rule("in_message",/'[{}]?'/,function(e,t){"''"===t[0]?n+="'":"'{'"===t[0]?n+="{":"'}'"===t[0]&&(n+="}"),e.ignore()},y),t.rule("in_message",/./,function(e,t){var i=t[0];"{"===i?(r++,n+=t[0],e.ignore()):"}"===i?r>0?(r--,n+=t[0],e.ignore()):(e.pop(),e.accept(y,n),n="",e.accept("CURLY_BRACE_CLOSE",t[0])):(n+=t[0],e.ignore())},y),t.rule("normal",/,/,function(e,t){e.accept("COMMA",t[0])},"COMMA"),t.rule("normal",/plural/,function(e,t){e.accept("PLURAL",t[0])},"PLURAL"),t.rule("normal",/select/,function(e,t){e.accept("SELECT",t[0])},"SELECT"),t.rule(/./,function(e,t){n+=t[0],e.ignore()},y),t.rule(/[\s]+/,function(e,t){n+=t[0],e.ignore()},y),t},e.prototype.containsNonWhiteSpace=function(e){for(var t=0;t<e.length;t++)if(!/\s/.test(e.charAt(t)))return!0;return!1},e.prototype.tokenize=function(e){var t=this.getLexer();return t.input(e),t.tokens()},e.prototype.input=function(e){this.lexer=this.getLexer(),this.lexer.input(e)},e.prototype.next=function(){return this.lexer.token()},e.prototype.peek=function(){return this.lexer.peek()},e}(),_=function(){function e(e,t){this._category=e,this._message=t}return e.prototype.getCategory=function(){return this._category},e.prototype.getMessageNormalized=function(){return this._message},e}(),v=function(){function e(e,t){this._parser=e,this._isPluralMessage=t,this._categories=[]}return e.prototype.addCategory=function(e,t){this._categories.push(new _(e,t))},e.prototype.asNativeString=function(){var e=this.isPluralMessage()?"VAR_PLURAL":"VAR_SELECT",t=this.isPluralMessage()?"plural":"select",r="";return this._categories.forEach(function(e){r+=n.format(" %s {%s}",e.getCategory(),e.getMessageNormalized().asNativeString())}),n.format("{%s, %s,%s}",e,t,r)},e.prototype.isPluralMessage=function(){return this._isPluralMessage},e.prototype.isSelectMessage=function(){return!this._isPluralMessage},e.prototype.getCategories=function(){return this._categories},e.prototype.translate=function(t){var r=this,i=new e(this._parser,this.isPluralMessage()),a=new Set;return this._categories.forEach(function(e){var o,s=t[e.getCategory()];n.isNullOrUndefined(s)?o=e.getMessageNormalized():n.isString(s)?(a.add(e.getCategory()),o=r._parser.parseNormalizedString(s,null)):o=null,i.addCategory(e.getCategory(),o)}),Object.keys(t).forEach(function(e){if(!a.has(e)){if(r.isSelectMessage())throw new Error(n.format('adding a new category not allowed for select messages ("%s" is not part of message)',e));r.checkValidPluralCategory(e);var o=r._parser.parseNormalizedString(t[e],null);i.addCategory(e,o)}}),i},e.prototype.checkValidPluralCategory=function(e){var t=["zero","one","two","few","many","other"];if(!e.match(/=\d+/)&&!t.find(function(t){return t===e}))throw new Error(n.format('invalid plural category "%s", allowed are =<n> and %s',e,t))},e}(),C=function(e){function t(t,n){var r=e.call(this,f.ICU_MESSAGE)||this;return r._parser=n,t&&r.parseICUMessage(t),r}return o(t,e),t.looksLikeICUMessage=function(e){return new t(null,null).looksLikeICUMessage(e)},t.prototype.asDisplayString=function(e){return"<ICU-Message/>"},t.prototype.getICUMessage=function(){return this._message},t.prototype.parseICUMessage=function(e){this._messageText=e,this._tokenizer=new N,this._tokenizer.input(e),this.expectNext("CURLY_BRACE_OPEN"),this.expectNext(y),this.expectNext("COMMA");var t=this._tokenizer.next();for("PLURAL"===t.type?this._message=new v(this._parser,!0):"SELECT"===t.type&&(this._message=new v(this._parser,!1)),this.expectNext("COMMA"),t=this._tokenizer.peek();"CURLY_BRACE_CLOSE"!==t.type;){var n=this.expectNext(y).value.trim();this.expectNext("CURLY_BRACE_OPEN");var r=this.expectNext(y).value;this._message.addCategory(n,this.parseNativeSubMessage(r)),this.expectNext("CURLY_BRACE_CLOSE"),t=this._tokenizer.peek()}this.expectNext("CURLY_BRACE_CLOSE"),this.expectNext("EOF")},t.prototype.looksLikeICUMessage=function(e){this._tokenizer=new N,this._tokenizer.input(e);try{this.expectNext("CURLY_BRACE_OPEN"),this.expectNext(y),this.expectNext("COMMA");var t=this._tokenizer.next();return("PLURAL"===t.type||"SELECT"===t.type)&&(this.expectNext("COMMA"),!0)}catch(n){return!1}},t.prototype.expectNext=function(e){var t=this._tokenizer.next();if(t.type!==e)throw new Error(n.format("Error parsing ICU Message: expected %s, found %s (%s) (message %s)",e,t.type,t.value,this._messageText));return t},t.prototype.parseNativeSubMessage=function(e){return this._parser.createNormalizedMessageFromXMLString(e,null)},t}(h),A=function(e){function t(t,n){var r=e.call(this,f.ICU_MESSAGE_REF)||this;return r._index=t,r._disp=n,r}return o(t,e),t.prototype.asDisplayString=function(e){return"<ICU-Message-Ref_"+this._index+"/>"},t.prototype.index=function(){return this._index},t.prototype.disp=function(){return this._disp},t}(h),S=function(e){function t(t,n){var r=e.call(this,f.EMPTY_TAG)||this;return r._tagname=t,r._idcounter=n,r}return o(t,e),t.prototype.asDisplayString=function(e){return 0===this._idcounter?"<"+this._tagname+">":"<"+this._tagname+' id="'+this._idcounter.toString()+'">'},t.prototype.tagName=function(){return this._tagname},t.prototype.idCounter=function(){return this._idcounter},t}(h),x=function(){function e(e,t){this._parser=e,this.sourceMessage=t,this._parts=[]}return e.prototype.getParser=function(){return this._parser},e.prototype.translate=function(e){if(n.isNullOrUndefined(this.getICUMessage()))return this._parser.parseNormalizedString(e,this);throw new Error(n.format('cannot translate ICU message with simple string, use translateICUMessage() instead ("%s", "%s")',e,this.asNativeString()))},e.prototype.translateICUMessage=function(e){var t=this.getICUMessage();if(n.isNullOrUndefined(t))throw new Error(n.format('this is not an ICU message, use translate() instead ("%s", "%s")',e,this.asNativeString()));var r=t.translate(e);return this._parser.parseICUMessage(r.asNativeString(),this)},e.prototype.translateNativeString=function(e){return this._parser.createNormalizedMessageFromXMLString(e,this)},e.prototype.asDisplayString=function(e){return this._parts.map(function(t){return t.asDisplayString(e)}).join("")},e.prototype.asNativeString=function(){return n.isNullOrUndefined(this.getICUMessage())?l.getXMLContent(this._xmlRepresentation):this.getICUMessage().asNativeString()},e.prototype.validate=function(){var e,t=!1,r={};return e=this.checkPlaceholderAdded(),n.isNullOrUndefined(e)||(r.placeholderAdded=e,t=!0),e=this.checkICUMessageRefRemoved(),n.isNullOrUndefined(e)||(r.icuMessageRefRemoved=e,t=!0),e=this.checkICUMessageRefAdded(),n.isNullOrUndefined(e)||(r.icuMessageRefAdded=e,t=!0),t?r:null},e.prototype.validateWarnings=function(){var e,t=!1,r={};return e=this.checkPlaceholderRemoved(),n.isNullOrUndefined(e)||(r.placeholderRemoved=e,t=!0),e=this.checkTagRemoved(),n.isNullOrUndefined(e)||(r.tagRemoved=e,t=!0),e=this.checkTagAdded(),n.isNullOrUndefined(e)||(r.tagAdded=e,t=!0),t?r:null},e.prototype.isICUMessage=function(){return 1===this._parts.length&&this._parts[0].type===f.ICU_MESSAGE},e.prototype.containsICUMessageRef=function(){return this._parts.findIndex(function(e){return e.type===f.ICU_MESSAGE_REF})>=0},e.prototype.getICUMessage=function(){return 1===this._parts.length&&this._parts[0].type===f.ICU_MESSAGE?this._parts[0].getICUMessage():null},e.prototype.checkPlaceholderAdded=function(){var e=null,t=[];if(this.sourceMessage){var n=this.sourceMessage.allPlaceholders();this.allPlaceholders().forEach(function(e){n.has(e)||t.push(e)})}if(1===t.length)e="added placeholder "+t[0]+", which is not in original message";else if(t.length>1){var r="",i=!0;t.forEach(function(e){i||(r+=", "),r+=e,i=!1}),e="added placeholders "+r+", which are not in original message"}return e},e.prototype.checkPlaceholderRemoved=function(){var e=null,t=[];if(this.sourceMessage){var n=this.sourceMessage.allPlaceholders(),r=this.allPlaceholders();n.forEach(function(e){r.has(e)||t.push(e)})}if(1===t.length)e="removed placeholder "+t[0]+" from original message";else if(t.length>1){var i="",a=!0;t.forEach(function(e){a||(i+=", "),i+=e,a=!1}),e="removed placeholders "+i+" from original message"}return e},e.prototype.checkICUMessageRefAdded=function(){var e=null,t=[];if(this.sourceMessage){var n=this.sourceMessage.allICUMessageRefs();this.allICUMessageRefs().forEach(function(e){n.has(e)||t.push(e)})}if(1===t.length)e="added ICU message reference "+t[0]+", which is not in original message";else if(t.length>1){var r="",i=!0;t.forEach(function(e){i||(r+=", "),r+=e,i=!1}),e="added ICU message references "+r+", which are not in original message"}return e},e.prototype.checkICUMessageRefRemoved=function(){var e=null,t=[];if(this.sourceMessage){var n=this.sourceMessage.allICUMessageRefs(),r=this.allICUMessageRefs();n.forEach(function(e){r.has(e)||t.push(e)})}if(1===t.length)e="removed ICU message reference "+t[0]+" from original message";else if(t.length>1){var i="",a=!0;t.forEach(function(e){a||(i+=", "),i+=e,a=!1}),e="removed ICU message references "+i+" from original message"}return e},e.prototype.allPlaceholders=function(){var e=new Set;return this.parts().forEach(function(t){if(t.type===f.PLACEHOLDER){var n=t.index();e.add(n)}}),e},e.prototype.getPlaceholderDisp=function(e){var t=null;return this.parts().forEach(function(n){if(n.type===f.PLACEHOLDER){var r=n;r.index()===e&&(t=r)}}),t?t.disp():null},e.prototype.allICUMessageRefs=function(){var e=new Set;return this.parts().forEach(function(t){if(t.type===f.ICU_MESSAGE_REF){var n=t.index();e.add(n)}}),e},e.prototype.getICUMessageRefDisp=function(e){var t=null;return this.parts().forEach(function(n){if(n.type===f.ICU_MESSAGE_REF){var r=n;r.index()===e&&(t=r)}}),t?t.disp():null},e.prototype.checkTagAdded=function(){var e=null,t=[];if(this.sourceMessage){var n=this.sourceMessage.allTags();this.allTags().forEach(function(e){n.has(e)||t.push(e)})}if(1===t.length)e="added tag <"+t[0]+">, which is not in original message";else if(t.length>1){var r="",i=!0;t.forEach(function(e){i||(r+=", "),r=r+"<"+e+">",i=!1}),e="added tags "+r+", which are not in original message"}return e},e.prototype.checkTagRemoved=function(){var e=null,t=[];if(this.sourceMessage){var n=this.sourceMessage.allTags(),r=this.allTags();n.forEach(function(e){r.has(e)||t.push(e)})}if(1===t.length)e="removed tag <"+t[0]+"> from original message";else if(t.length>1){var i="",a=!0;t.forEach(function(e){a||(i+=", "),i=i+"<"+e+">",a=!1}),e="removed tags "+i+" from original message"}return e},e.prototype.allTags=function(){var e=new Set;return this.parts().forEach(function(t){if(t.type===f.START_TAG||t.type===f.EMPTY_TAG){var n=t.tagName();e.add(n)}}),e},e.prototype.parts=function(){return this._parts},e.prototype.setXmlRepresentation=function(e){this._xmlRepresentation=e},e.prototype.addText=function(e){this._parts.push(new g(e))},e.prototype.addPlaceholder=function(e,t){this._parts.push(new d(e,t))},e.prototype.addStartTag=function(e,t){this._parts.push(new T(e,t))},e.prototype.addEndTag=function(e){var t=this.calculateOpenTagName();if(!t||t!==e)throw new Error(n.format('unexpected close tag %s (currently open is %s, native xml is "%s")',e,t,this.asNativeString()));this._parts.push(new E(e))},e.prototype.addEmptyTag=function(e,t){this._parts.push(new S(e,t))},e.prototype.addICUMessageRef=function(e,t){this._parts.push(new A(e,t))},e.prototype.addICUMessage=function(e){this._parts.push(new C(e,this._parser))},e.prototype.calculateOpenTagName=function(){var e=this,t=[];return this._parts.forEach(function(r){switch(r.type){case f.START_TAG:t.push(r.tagName());break;case f.END_TAG:var i=r.tagName();if(0===t.length||t[t.length-1]!==i){var a=0===t.length?"nothing":t[t.length-1];throw new Error(n.format('unexpected close tag %s (currently open is %s, native xml is "%s")',i,a,e.asNativeString()))}t.pop()}}),0===t.length?null:t[t.length-1]},e}(),b=function(){function e(){}return e.prototype.getLexer=function(){var e=new i,t="";return e.before(function(e,n,r){"TEXT"!==r.name&&""!==t&&(e.accept("TEXT",{text:t}),t="")}),e.finish(function(e){""!==t&&e.accept("TEXT",{text:t})}),e.rule(/<(br|hr|img|area|link|wbr)( id="([0-9])*")?\>/,function(e,t){var r=n.isNullOrUndefined(t[3])?0:parseInt(t[3],10);e.accept("EMPTY_TAG",{name:t[1],idcounter:r})},"EMPTY_TAG"),e.rule(/<([a-zA-Z][a-zA-Z-0-9]*)( id="([0-9]*)")?>/,function(e,t){var r=n.isNullOrUndefined(t[3])?0:parseInt(t[3],10);e.accept("START_TAG",{name:t[1],idcounter:r})},"START_TAG"),e.rule(/<\/([a-zA-Z][a-zA-Z-0-9]*)>/,function(e,t){e.accept("END_TAG",{name:t[1]})},"END_TAG"),e.rule(/{{([0-9]+)}}/,function(e,t){e.accept("PLACEHOLDER",{idcounter:parseInt(t[1],10)})},"PLACEHOLDER"),e.rule(/<ICU-Message-Ref_([0-9]+)\/>/,function(e,t){e.accept("ICU_MESSAGE_REF",{idcounter:parseInt(t[1],10)})},"ICU_MESSAGE_REF"),e.rule(/<ICU-Message\/>/,function(e,t){e.accept("ICU_MESSAGE",{message:t[0]})},"ICU_MESSAGE"),e.rule(/./,function(e,n){t+=n[0],e.ignore()},"TEXT"),e.rule(/[\t\r\n]+/,function(e,n){t+=n[0],e.ignore()},"TEXT"),e},e.prototype.tokenize=function(e){var t=this.getLexer();return t.reset(),t.input(e),t.tokens()},e}(),U=function(){function e(){}return e.prototype.createNormalizedMessageFromXML=function(e,t){var n=new x(this,t);return e&&(n.setXmlRepresentation(e),this.addPartsOfNodeToMessage(e,n,!1)),n},e.prototype.createNormalizedMessageFromXMLString=function(e,t){var n=(new r.DOMParser).parseFromString("<dummy>"+e+"</dummy>","text/xml").childNodes.item(0);return this.createNormalizedMessageFromXML(n,t)},e.prototype.addPartsOfNodeToMessage=function(e,t,r){var i=!0;if(r){if(e.nodeType===e.TEXT_NODE)return void t.addText(e.textContent);e.nodeType===e.ELEMENT_NODE&&(i=this.processStartElement(e,t))}if(i){var a=this.getICUMessageText(e),o=!n.isNullOrUndefined(a);if(o)try{t.addICUMessage(a)}catch(l){console.log("non ICU message: ",a,l),o=!1}if(!o)for(var s=e.childNodes,u=0;u<s.length;u++)this.addPartsOfNodeToMessage(s.item(u),t,!0)}e.nodeType===e.ELEMENT_NODE&&this.processEndElement(e,t)},e.prototype.getICUMessageText=function(e){var t=e.childNodes;if(0===t.length)return null;var n=t.item(0);return n.nodeType===n.TEXT_NODE&&this.isICUMessageStart(n.textContent)?l.getXMLContent(e):null},e.prototype.isICUMessageStart=function(e){return C.looksLikeICUMessage(e)},e.prototype.parseNormalizedString=function(e,t){var r,i=new x(this,t),a=[];try{r=(new b).tokenize(e)}catch(o){throw new Error(n.format('unexpected error while parsing message: "%s" (parsed "%")',o.message,e))}if(r.forEach(function(r){var o=null;switch(r.type){case"TEXT":i.addText(r.value.text);break;case"START_TAG":i.addStartTag(r.value.name,r.value.idcounter),a.push(r.value.name);break;case"END_TAG":if(i.addEndTag(r.value.name),0===a.length||a[a.length-1]!==r.value.name)throw new Error(n.format('unexpected close tag "%s" (parsed "%s")',r.value.name,e));a.pop();break;case"EMPTY_TAG":i.addEmptyTag(r.value.name,r.value.idcounter);break;case"PLACEHOLDER":o=t?t.getPlaceholderDisp(r.value.idcounter):null,i.addPlaceholder(r.value.idcounter,o);break;case"ICU_MESSAGE_REF":o=t?t.getICUMessageRefDisp(r.value.idcounter):null,i.addICUMessageRef(r.value.idcounter,o);break;case"ICU_MESSAGE":throw new Error(n.format('<ICUMessage/> not allowed here, use parseICUMessage instead (parsed "%")',e))}}),a.length>0)throw new Error(n.format('missing close tag "%s" (parsed "%s")',a[a.length-1],e));return i.setXmlRepresentation(this.createXmlRepresentation(i)),i},e.prototype.parseICUMessage=function(e,t){var n=new x(this,t);return n.addICUMessage(e),n},e.prototype.parseIdCountFromName=function(e){var t=/.*_([0-9]*)/.exec(e);if(n.isNullOrUndefined(t)||""===t[1])return 0;var r=t[1];return parseInt(r,10)},e.prototype.createXmlRepresentation=function(e){var t=(new r.DOMParser).parseFromString("<dummy/>","text/xml").getElementsByTagName("dummy").item(0);return this.addXmlRepresentationToRoot(e,t),t},e.prototype.createXmlRepresentationOfTextPart=function(e,t){return t.ownerDocument.createTextNode(e.asDisplayString())},e}(),w={A:"LINK",B:"BOLD_TEXT",BR:"LINE_BREAK",EM:"EMPHASISED_TEXT",H1:"HEADING_LEVEL1",H2:"HEADING_LEVEL2",H3:"HEADING_LEVEL3",H4:"HEADING_LEVEL4",H5:"HEADING_LEVEL5",H6:"HEADING_LEVEL6",HR:"HORIZONTAL_RULE",I:"ITALIC_TEXT",LI:"LIST_ITEM",LINK:"MEDIA_LINK",OL:"ORDERED_LIST",P:"PARAGRAPH",Q:"QUOTATION",S:"STRIKETHROUGH_TEXT",SMALL:"SMALL_TEXT",SUB:"SUBSTRIPT",SUP:"SUPERSCRIPT",TBODY:"TABLE_BODY",TD:"TABLE_CELL",TFOOT:"TABLE_FOOTER",TH:"TABLE_HEADER_CELL",THEAD:"TABLE_HEADER",TR:"TABLE_ROW",TT:"MONOSPACED_TEXT",U:"UNDERLINED_TEXT",UL:"UNORDERED_LIST"},M=["BR","HR","IMG","AREA","LINK","WBR"],I=function(){function e(){}return e.prototype.getStartTagPlaceholderName=function(e,t){var n=e.toUpperCase();return"START_"+(w[n]||"TAG_"+n)+this.counterString(t)},e.prototype.getCloseTagPlaceholderName=function(e){var t=e.toUpperCase();return"CLOSE_"+(w[t]||"TAG_"+t)},e.prototype.getEmptyTagPlaceholderName=function(e,t){var n=e.toUpperCase();return(w[n]||"TAG_"+n)+this.counterString(t)},e.prototype.getCtypeForTag=function(e){switch(e.toLowerCase()){case"br":return"lb";case"img":return"image";default:return"x-"+e}},e.prototype.getTagnameFromStartTagPlaceholderName=function(e){if(e.startsWith("START_TAG_"))return this.stripCounter(e.substring("START_TAG_".length)).toLowerCase();if(e.startsWith("START_")){var t=this.stripCounter(e.substring("START_".length)),n=Object.keys(w).find(function(e){return w[e]===t});return n?n.toLowerCase():null}return null},e.prototype.getTagnameFromCloseTagPlaceholderName=function(e){if(e.startsWith("CLOSE_TAG_"))return this.stripCounter(e.substring("CLOSE_TAG_".length)).toLowerCase();if(e.startsWith("CLOSE_")){var t=this.stripCounter(e.substring("CLOSE_".length)),n=Object.keys(w).find(function(e){return w[e]===t});return n?n.toLowerCase():null}return null},e.prototype.isEmptyTagPlaceholderName=function(e){var t,n=this.stripCounter(e);return!!((t=n.startsWith("TAG_")?n.substring(4).toUpperCase():Object.keys(w).find(function(e){return w[e]===n}))&&M.indexOf(t)>=0)},e.prototype.getTagnameFromEmptyTagPlaceholderName=function(e){var t,n=this.stripCounter(e);return(t=n.startsWith("TAG_")?n.substring(4).toUpperCase():Object.keys(w).find(function(e){return w[e]===n}))&&M.indexOf(t)>=0?t.toLowerCase():null},e.prototype.stripCounter=function(e){if(e){var t=/(.*)_[0-9]+$/;if(e.match(t))return e.replace(t,"$1")}return e},e.prototype.counterString=function(e){return 0===e?"":"_"+e.toString(10)},e}(),F=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return o(t,e),t.prototype.processStartElement=function(e,t){var n=e.tagName,r=new I;if("x"===n){var i=e.getAttribute("id");if(!i)return;if(i.startsWith("INTERPOLATION")){var a=this.parsePlaceholderIndexFromId(i);t.addPlaceholder(a,null)}else if(i.startsWith("ICU")){a=this.parseICUMessageRefIndexFromId(i);t.addICUMessageRef(a,null)}else if(i.startsWith("START_")){if(s=r.getTagnameFromStartTagPlaceholderName(i)){var o=this.parseIdCountFromName(i);t.addStartTag(s,o)}}else if(i.startsWith("CLOSE_")){(s=r.getTagnameFromCloseTagPlaceholderName(i))&&t.addEndTag(s)}else if(r.isEmptyTagPlaceholderName(i)){var s;if(s=r.getTagnameFromEmptyTagPlaceholderName(i)){o=this.parseIdCountFromName(i);t.addEmptyTag(s,o)}}}return!0},t.prototype.processEndElement=function(e,t){},t.prototype.parsePlaceholderIndexFromId=function(e){var t="";return t="INTERPOLATION"===e?"0":e.substring("INTERPOLATION_".length),Number.parseInt(t,10)},t.prototype.parseICUMessageRefIndexFromId=function(e){var t="";return t="ICU"===e?"0":e.substring("ICU_".length),Number.parseInt(t,10)},t.prototype.addXmlRepresentationToRoot=function(e,t){var n=this;e.parts().forEach(function(e){var r;switch(e.type){case f.TEXT:r=n.createXmlRepresentationOfTextPart(e,t);break;case f.START_TAG:r=n.createXmlRepresentationOfStartTagPart(e,t);break;case f.END_TAG:r=n.createXmlRepresentationOfEndTagPart(e,t);break;case f.EMPTY_TAG:r=n.createXmlRepresentationOfEmptyTagPart(e,t);break;case f.PLACEHOLDER:r=n.createXmlRepresentationOfPlaceholderPart(e,t);break;case f.ICU_MESSAGE_REF:r=n.createXmlRepresentationOfICUMessageRefPart(e,t)}r&&t.appendChild(r)})},t.prototype.createXmlRepresentationOfStartTagPart=function(e,t){var n=t.ownerDocument.createElement("x"),r=new I,i=r.getStartTagPlaceholderName(e.tagName(),e.idCounter()),a=r.getCtypeForTag(e.tagName()),o="<"+e.tagName()+">";return n.setAttribute("id",i),n.setAttribute("ctype",a),n.setAttribute("equiv-text",o),n},t.prototype.createXmlRepresentationOfEndTagPart=function(e,t){var n=t.ownerDocument.createElement("x"),r=(new I).getCloseTagPlaceholderName(e.tagName()),i="x-"+e.tagName();return n.setAttribute("id",r),n.setAttribute("ctype",i),n},t.prototype.createXmlRepresentationOfEmptyTagPart=function(e,t){var n=t.ownerDocument.createElement("x"),r=new I,i=r.getEmptyTagPlaceholderName(e.tagName(),e.idCounter()),a=r.getCtypeForTag(e.tagName()),o="<"+e.tagName()+"/>";return n.setAttribute("id",i),n.setAttribute("ctype",a),n.setAttribute("equiv-text",o),n},t.prototype.createXmlRepresentationOfPlaceholderPart=function(e,t){var n=t.ownerDocument.createElement("x"),r="INTERPOLATION";e.index()>0&&(r="INTERPOLATION_"+e.index().toString(10));var i=e.disp();return n.setAttribute("id",r),i&&n.setAttribute("equiv-text",i),n},t.prototype.createXmlRepresentationOfICUMessageRefPart=function(e,t){var n=t.ownerDocument.createElement("x"),r="ICU";return e.index()>0&&(r="ICU_"+e.index().toString(10)),n.setAttribute("id",r),n},t}(U),R=function(e){function t(t,n,r){return e.call(this,t,n,r)||this}return o(t,e),t.prototype.sourceContent=function(){var e=l.getFirstElementByTagName(this._element,"source");return l.getXMLContent(e)},t.prototype.setSourceContent=function(e){var t=l.getFirstElementByTagName(this._element,"source");t||(t=this._element.appendChild(this._element.ownerDocument.createElement("source"))),l.replaceContentWithXMLContent(t,e)},t.prototype.messageParser=function(){return new F},t.prototype.createSourceContentNormalized=function(){var e=l.getFirstElementByTagName(this._element,"source");return e?this.messageParser().createNormalizedMessageFromXML(e,null):null},t.prototype.targetContent=function(){var e=l.getFirstElementByTagName(this._element,"target");return l.getXMLContent(e)},t.prototype.targetContentNormalized=function(){var e=l.getFirstElementByTagName(this._element,"target");return(new F).createNormalizedMessageFromXML(e,this.sourceContentNormalized())},t.prototype.nativeTargetState=function(){var e=l.getFirstElementByTagName(this._element,"target");return e?e.getAttribute("state"):null},t.prototype.setNativeTargetState=function(e){var t=l.getFirstElementByTagName(this._element,"target");t&&t.setAttribute("state",e)},t.prototype.mapStateToNativeState=function(e){switch(e){case"new":return"new";case"translated":return"translated";case"final":return"final";default:throw new Error("unknown state "+e)}},t.prototype.mapNativeStateToState=function(e){switch(e){case"new":case"needs-translation":return"new";case"translated":case"needs-adaptation":case"needs-l10n":case"needs-review-adaptation":case"needs-review-l10n":case"needs-review-translation":return"translated";case"final":case"signed-off":return"final";default:return"new"}},t.prototype.sourceReferences=function(){for(var e=this._element.getElementsByTagName("context-group"),t=[],n=0;n<e.length;n++){var r=e.item(n);if("location"===r.getAttribute("purpose")){for(var i=r.getElementsByTagName("context"),a=null,o=0,s=0;s<i.length;s++){var u=i.item(s);"sourcefile"===u.getAttribute("context-type")&&(a=l.getPCDATA(u)),"linenumber"===u.getAttribute("context-type")&&(o=Number.parseInt(l.getPCDATA(u),10))}t.push({sourcefile:a,linenumber:o})}}return t},t.prototype.setSourceReferences=function(e){var t=this;this.removeAllSourceReferences(),e.forEach(function(e){var n=t._element.ownerDocument.createElement("context-group");n.setAttribute("purpose","location");var r=t._element.ownerDocument.createElement("context");r.setAttribute("context-type","sourcefile"),r.appendChild(t._element.ownerDocument.createTextNode(e.sourcefile));var i=t._element.ownerDocument.createElement("context");i.setAttribute("context-type","linenumber"),i.appendChild(t._element.ownerDocument.createTextNode(e.linenumber.toString(10))),n.appendChild(r),n.appendChild(i),t._element.appendChild(n)})},t.prototype.removeAllSourceReferences=function(){for(var e=this._element.getElementsByTagName("context-group"),t=[],n=0;n<e.length;n++){var r=e.item(n);"location"===r.getAttribute("purpose")&&t.push(r)}t.forEach(function(e){e.parentNode.removeChild(e)})},t.prototype.description=function(){var e=this.findNoteElementWithFromAttribute("description");return e?l.getPCDATA(e):null},t.prototype.setDescription=function(e){var t=this.findNoteElementWithFromAttribute("description");e?n.isNullOrUndefined(t)?t=this.createNoteElementWithFromAttribute("description",e):l.replaceContentWithXMLContent(t,e):n.isNullOrUndefined(t)||this.removeNoteElementWithFromAttribute("description")},t.prototype.findNoteElementWithFromAttribute=function(e){for(var t=this._element.getElementsByTagName("note"),n=0;n<t.length;n++){var r=t.item(n);if(r.getAttribute("from")===e)return r}return null},t.prototype.findAllAdditionalNoteElements=function(){for(var e=this._element.getElementsByTagName("note"),t=[],n=0;n<e.length;n++){var r=e.item(n),i=r.getAttribute("from");"description"!==i&&"meaning"!==i&&t.push(r)}return t},t.prototype.createNoteElementWithFromAttribute=function(e,t){var n=this._element.ownerDocument.createElement("note");return e&&n.setAttribute("from",e),n.setAttribute("priority","1"),t&&l.replaceContentWithXMLContent(n,t),this._element.appendChild(n),n},t.prototype.removeNoteElementWithFromAttribute=function(e){var t=this.findNoteElementWithFromAttribute(e);t&&this._element.removeChild(t)},t.prototype.removeAllAdditionalNoteElements=function(){var e=this;this.findAllAdditionalNoteElements().forEach(function(t){e._element.removeChild(t)})},t.prototype.meaning=function(){var e=this.findNoteElementWithFromAttribute("meaning");return e?l.getPCDATA(e):null},t.prototype.setMeaning=function(e){var t=this.findNoteElementWithFromAttribute("meaning");e?n.isNullOrUndefined(t)?t=this.createNoteElementWithFromAttribute("meaning",e):l.replaceContentWithXMLContent(t,e):n.isNullOrUndefined(t)||this.removeNoteElementWithFromAttribute("meaning")},t.prototype.notes=function(){return this.findAllAdditionalNoteElements().map(function(e){return{from:e.getAttribute("from"),text:l.getPCDATA(e)}})},t.prototype.supportsSetNotes=function(){return!0},t.prototype.setNotes=function(e){var t=this;n.isNullOrUndefined(e)||this.checkNotes(e),this.removeAllAdditionalNoteElements(),n.isNullOrUndefined(e)||e.forEach(function(e){t.createNoteElementWithFromAttribute(e.from,e.text)})},t.prototype.translateNative=function(e){var t=l.getFirstElementByTagName(this._element,"target");if(!t){var n=l.getFirstElementByTagName(this._element,"source");t=l.createFollowingSibling("target",n)}l.replaceContentWithXMLContent(t,e),this.setTargetState("translated")},t.prototype.cloneWithSourceAsTarget=function(e,n,r){var i=new t(this._element.cloneNode(!0),this._id,r);return i.useSourceAsTarget(e,n),i},t.prototype.useSourceAsTarget=function(e,t){var n=l.getFirstElementByTagName(this._element,"source"),r=l.getFirstElementByTagName(this._element,"target");if(r||(r=l.createFollowingSibling("target",n)),e||t){var i=l.getXMLContent(n),a=i;this.isICUMessage(i)||(a=this.translationMessagesFile().getNewTransUnitTargetPraefix()+i+this.translationMessagesFile().getNewTransUnitTargetSuffix()),l.replaceContentWithXMLContent(r,a)}else l.replaceContentWithXMLContent(r,"");e?r.setAttribute("state",this.mapStateToNativeState("final")):r.setAttribute("state",this.mapStateToNativeState("new"))},t}(m),L=function(e){function t(t,n,r){var i=e.call(this)||this;return i._warnings=[],i._numberOfTransUnitsWithMissingId=0,i.initializeFromContent(t,n,r),i}return o(t,e),t.prototype.initializeFromContent=function(e,t,r){this.parseContent(e,t,r);var i=this._parsedDocument.getElementsByTagName("xliff");if(1!==i.length)throw new Error(n.format('File "%s" seems to be no xliff file (should contain an xliff element)',t));var a=i.item(0).getAttribute("version");if("1.2"!==a)throw new Error(n.format('File "%s" seems to be no xliff 1.2 file, version should be %s, found %s',t,"1.2",a));return this},t.prototype.i18nFormat=function(){return"xlf"},t.prototype.fileType=function(){return"XLIFF 1.2"},t.prototype.elementsWithMixedContent=function(){return["source","target","tool","seg-source","g","ph","bpt","ept","it","sub","mrk"]},t.prototype.initializeTransUnits=function(){this.transUnits=[];for(var e=this._parsedDocument.getElementsByTagName("trans-unit"),t=0;t<e.length;t++){var r=e.item(t),i=r.getAttribute("id");i||this._warnings.push(n.format('oops, trans-unit without "id" found in master, please check file %s',this._filename)),this.transUnits.push(new R(r,i,this))}},t.prototype.sourceLanguage=function(){var e=l.getFirstElementByTagName(this._parsedDocument,"file");return e?e.getAttribute("source-language"):null},t.prototype.setSourceLanguage=function(e){var t=l.getFirstElementByTagName(this._parsedDocument,"file");t&&t.setAttribute("source-language",e)},t.prototype.targetLanguage=function(){var e=l.getFirstElementByTagName(this._parsedDocument,"file");return e?e.getAttribute("target-language"):null},t.prototype.setTargetLanguage=function(e){var t=l.getFirstElementByTagName(this._parsedDocument,"file");t&&t.setAttribute("target-language",e)},t.prototype.importNewTransUnit=function(e,t,r,i){if(this.transUnitWithId(e.id))throw new Error(n.format("tu with id %s already exists in file, cannot import it",e.id));var a=e.cloneWithSourceAsTarget(t,r,this),o=l.getFirstElementByTagName(this._parsedDocument,"body");if(!o)throw new Error(n.format('File "%s" seems to be no xliff 1.2 file (should contain a body element)',this._filename));var s=!1,u=!1;i&&(this.transUnitWithId(i.id)&&(u=!0));if(i===undefined||i&&!u)o.appendChild(a.asXmlElement()),s=!0;else if(null===i){var p=l.getFirstElementByTagName(this._parsedDocument,"trans-unit");p?(l.insertBefore(a.asXmlElement(),p),s=!0):(o.appendChild(a.asXmlElement()),s=!0)}else{var c=l.getElementByTagNameAndId(this._parsedDocument,"trans-unit",i.id);c&&(l.insertAfter(a.asXmlElement(),c),s=!0)}return s?(this.lazyInitializeTransUnits(),this.transUnits.push(a),this.countNumbers(),a):null},t.prototype.createTranslationFileForLang=function(e,n,r,i){var a=new t(this.editedContent(),n,this.encoding());return a.setNewTransUnitTargetPraefix(this.targetPraefix),a.setNewTransUnitTargetSuffix(this.targetSuffix),a.setTargetLanguage(e),a.forEachTransUnit(function(e){e.useSourceAsTarget(r,i)}),a},t}(c),O=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return o(t,e),t.prototype.processStartElement=function(e,t){var n=e.tagName;if("ph"===n){var r=e.getAttribute("name");if(!r)return!0;if(r.startsWith("INTERPOLATION")){var i=this.parsePlaceholderIndexFromName(r);return t.addPlaceholder(i,null),!1}if(r.startsWith("START_")){var a=this.parseTagnameFromPhElement(e),o=this.parseIdCountFromName(r);return a&&t.addStartTag(a,o),!1}if(r.startsWith("CLOSE_"))return(a=this.parseTagnameFromPhElement(e))&&t.addEndTag(a),!1;if((new I).isEmptyTagPlaceholderName(r)){var s=(new I).getTagnameFromEmptyTagPlaceholderName(r);o=this.parseIdCountFromName(r);return t.addEmptyTag(s,o),!1}if(r.startsWith("ICU")){i=this.parseICUMessageIndexFromName(r);return t.addICUMessageRef(i,null),!1}}else if("source"===n)return!1;return!0},t.prototype.getICUMessageText=function(e){var t=e.childNodes;if(0===t.length)return null;var n,r=null;for(n=0;n<t.length;n++){var i=t.item(n);if(i.nodeType!==i.ELEMENT_NODE||"source"!==i.tagName){r=i;break}}if(r&&r.nodeType===r.TEXT_NODE){if(this.isICUMessageStart(r.textContent)){var a=l.getXMLContent(e);if(n>0){var o=new RegExp("<source[^>]*>.*</source>","g");return a.replace(o,"")}return a}return null}return null},t.prototype.processEndElement=function(e,t){},t.prototype.parsePlaceholderIndexFromName=function(e){var t="";return t="INTERPOLATION"===e?"0":e.substring("INTERPOLATION_".length),Number.parseInt(t,10)},t.prototype.parseICUMessageIndexFromName=function(e){var t="";return t="ICU"===e?"0":e.substring("ICU_".length),Number.parseInt(t,10)},t.prototype.parseTagnameFromPhElement=function(e){var t=l.getFirstElementByTagName(e,"ex");if(t){var n=l.getPCDATA(t);return n&&n.startsWith("<")&&n.endsWith(">")?"/"===n.charAt(1)?n.substring(2,n.length-1):n.substring(1,n.length-1):null}return null},t.prototype.addXmlRepresentationToRoot=function(e,t){var n=this;e.parts().forEach(function(e){var r=n.createXmlRepresentationOfPart(e,t);r&&t.appendChild(r)})},t.prototype.createXmlRepresentationOfPart=function(e,t){switch(e.type){case f.TEXT:return this.createXmlRepresentationOfTextPart(e,t);case f.START_TAG:return this.createXmlRepresentationOfStartTagPart(e,t);case f.END_TAG:return this.createXmlRepresentationOfEndTagPart(e,t);case f.EMPTY_TAG:return this.createXmlRepresentationOfEmptyTagPart(e,t);case f.PLACEHOLDER:return this.createXmlRepresentationOfPlaceholderPart(e,t);case f.ICU_MESSAGE_REF:return this.createXmlRepresentationOfICUMessageRefPart(e,t)}},t.prototype.createXmlRepresentationOfStartTagPart=function(e,t){var n=t.ownerDocument.createElement("ph"),r=(new I).getStartTagPlaceholderName(e.tagName(),e.idCounter());n.setAttribute("name",r);var i=t.ownerDocument.createElement("ex");return i.appendChild(t.ownerDocument.createTextNode("<"+e.tagName()+">")),n.appendChild(i),n},t.prototype.createXmlRepresentationOfEndTagPart=function(e,t){var n=t.ownerDocument.createElement("ph"),r=(new I).getCloseTagPlaceholderName(e.tagName());n.setAttribute("name",r);var i=t.ownerDocument.createElement("ex");return i.appendChild(t.ownerDocument.createTextNode("</"+e.tagName()+">")),n.appendChild(i),n},t.prototype.createXmlRepresentationOfEmptyTagPart=function(e,t){var n=t.ownerDocument.createElement("ph"),r=(new I).getEmptyTagPlaceholderName(e.tagName(),e.idCounter());n.setAttribute("name",r);var i=t.ownerDocument.createElement("ex");return i.appendChild(t.ownerDocument.createTextNode("<"+e.tagName()+">")),n.appendChild(i),n},t.prototype.createXmlRepresentationOfPlaceholderPart=function(e,t){var n=t.ownerDocument.createElement("ph"),r="INTERPOLATION";e.index()>0&&(r="INTERPOLATION_"+e.index().toString(10)),n.setAttribute("name",r);var i=t.ownerDocument.createElement("ex");return i.appendChild(t.ownerDocument.createTextNode(r)),n.appendChild(i),n},t.prototype.createXmlRepresentationOfICUMessageRefPart=function(e,t){var n=t.ownerDocument.createElement("ph"),r="ICU";e.index()>0&&(r="ICU_"+e.index().toString(10)),n.setAttribute("name",r);var i=t.ownerDocument.createElement("ex");return i.appendChild(t.ownerDocument.createTextNode(r)),n.appendChild(i),n},t}(U),P=function(e){function t(t,n,r){return e.call(this,t,n,r)||this}return o(t,e),t.parseSourceAndPos=function(e){var n=e.lastIndexOf(":");return n<0?{sourcefile:e,linenumber:0}:{sourcefile:e.substring(0,n),linenumber:t.parseLineNumber(e.substring(n+1))}},t.parseLineNumber=function(e){return Number.parseInt(e,10)},t.prototype.sourceContent=function(){var e=l.getXMLContent(this._element);return e=e.replace(/<source>.*<\/source>/g,"")},t.prototype.supportsSetSourceContent=function(){return!1},t.prototype.setSourceContent=function(e){},t.prototype.messageParser=function(){return new O},t.prototype.createSourceContentNormalized=function(){return this.messageParser().createNormalizedMessageFromXML(this._element,null)},t.prototype.targetContent=function(){return this.sourceContent()},t.prototype.targetContentNormalized=function(){return(new O).createNormalizedMessageFromXML(this._element,this.sourceContentNormalized())},t.prototype.nativeTargetState=function(){return null},t.prototype.mapStateToNativeState=function(e){return e},t.prototype.mapNativeStateToState=function(e){return e},t.prototype.setNativeTargetState=function(e){},t.prototype.sourceReferences=function(){for(var e=this._element.getElementsByTagName("source"),n=[],r=0;r<e.length;r++){var i=e.item(r),a=l.getPCDATA(i);n.push(t.parseSourceAndPos(a))}return n},t.prototype.setSourceReferences=function(e){this.removeAllSourceReferences();for(var t=this._element.childNodes.item(0),n=e.length-1;n>=0;n--){var r=e[n],i=this._element.ownerDocument.createElement("source");i.appendChild(this._element.ownerDocument.createTextNode(r.sourcefile+":"+r.linenumber.toString(10))),this._element.insertBefore(i,t),t=i}},t.prototype.removeAllSourceReferences=function(){for(var e=this._element.getElementsByTagName("source"),t=[],n=0;n<e.length;n++){var r=e.item(n);t.push(r)}t.forEach(function(e){e.parentNode.removeChild(e)})},t.prototype.description=function(){return this._element.getAttribute("desc")},t.prototype.meaning=function(){return this._element.getAttribute("meaning")},t.prototype.supportsSetDescriptionAndMeaning=function(){return!1},t.prototype.setDescription=function(e){},t.prototype.setMeaning=function(e){},t.prototype.notes=function(){return[]},t.prototype.supportsSetNotes=function(){return!1},t.prototype.setNotes=function(e){},t.prototype.cloneWithSourceAsTarget=function(e,t,n){return this},t.prototype.useSourceAsTarget=function(e,t){},t.prototype.translateNative=function(e){throw new Error("You cannot translate xmb files, use xtb instead.")},t}(m),D=function(e){function t(t,n,r,i){var a=e.call(this)||this;return a._translationMessageFileFactory=t,a._warnings=[],a._numberOfTransUnitsWithMissingId=0,a.initializeFromContent(n,r,i),a}return o(t,e),t.prototype.initializeFromContent=function(e,t,r){if(this.parseContent(e,t,r),1!==this._parsedDocument.getElementsByTagName("messagebundle").length)throw new Error(n.format('File "%s" seems to be no xmb file (should contain a messagebundle element)',t));return this},t.prototype.initializeTransUnits=function(){this.transUnits=[];for(var e=this._parsedDocument.getElementsByTagName("msg"),t=0;t<e.length;t++){var r=e.item(t),i=r.getAttribute("id");i||this._warnings.push(n.format('oops, msg without "id" found in master, please check file %s',this._filename)),this.transUnits.push(new P(r,i,this))}},t.prototype.i18nFormat=function(){return"xmb"},t.prototype.fileType=function(){return"XMB"},t.prototype.elementsWithMixedContent=function(){return["message"]},t.prototype.guessLanguageFromFilename=function(){if(this._filename){var e=this._filename.split(".");if(e.length>2&&"xmb"===e[e.length-1].toLowerCase())return e[e.length-2]}return null},t.prototype.sourceLanguage=function(){return this.guessLanguageFromFilename()},t.prototype.setSourceLanguage=function(e){},t.prototype.targetLanguage=function(){return this.guessLanguageFromFilename()},t.prototype.setTargetLanguage=function(e){},t.prototype.importNewTransUnit=function(e,t,n,r){throw Error("xmb file cannot be used to store translations, use xtb file")},t.prototype.createTranslationFileForLang=function(e,t,n,r){var i=this._translationMessageFileFactory.createFileFromFileContent("xtb",'<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE translationbundle [\n  <!ELEMENT translationbundle (translation)*>\n  <!ATTLIST translationbundle lang CDATA #REQUIRED>\n  <!ELEMENT translation (#PCDATA|ph)*>\n  <!ATTLIST translation id CDATA #REQUIRED>\n  <!ELEMENT ph EMPTY>\n  <!ATTLIST ph name CDATA #REQUIRED>\n]>\n<translationbundle>\n</translationbundle>\n',t,this.encoding(),{xmlContent:this.editedContent(),path:this.filename(),encoding:this.encoding()});return i.setNewTransUnitTargetPraefix(this.targetPraefix),i.setNewTransUnitTargetSuffix(this.targetSuffix),i.setTargetLanguage(e),i.setNewTransUnitTargetPraefix(this.getNewTransUnitTargetPraefix()),i.setNewTransUnitTargetSuffix(this.getNewTransUnitTargetSuffix()),this.forEachTransUnit(function(e){i.importNewTransUnit(e,n,r)}),i},t}(c),X=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return o(t,e),t.prototype.processStartElement=function(e,t){var n=e.tagName;if("ph"===n){var r=!1,i=!1,a=!1,o=e.getAttribute("equiv"),s=e.getAttribute("disp"),u=null,l=0,p=null;if(o)if(o.startsWith("ICU"))i=!0,u="ICU"===o?"0":o.substring("ICU_".length),l=Number.parseInt(u,10);else if(o.startsWith("INTERPOLATION"))r=!0,u="INTERPOLATION"===o?"0":o.substring("INTERPOLATION_".length),l=Number.parseInt(u,10);else{if(!(new I).isEmptyTagPlaceholderName(o))return!0;a=!0,p=(new I).getTagnameFromEmptyTagPlaceholderName(o)}else i=!0,u=e.getAttribute("id"),l=Number.parseInt(u,10);r?t.addPlaceholder(l,s):i?t.addICUMessageRef(l,s):a&&t.addEmptyTag(p,this.parseIdCountFromName(o))}else if("pc"===n){var c=this.tagNameFromPCElement(e);c&&t.addStartTag(c,this.parseIdCountFromName(e.getAttribute("equivStart")))}return!0},t.prototype.processEndElement=function(e,t){if("pc"!==e.tagName);else{var n=this.tagNameFromPCElement(e);n&&t.addEndTag(n)}},t.prototype.tagNameFromPCElement=function(e){var t=e.getAttribute("dispStart");return t.startsWith("<")&&(t=t.substring(1)),t.endsWith(">")&&(t=t.substring(0,t.length-1)),t},t.prototype.addXmlRepresentationToRoot=function(e,t){var n=this,r=[{element:t,tagName:"root"}],i=0;if(e.parts().forEach(function(e){switch(e.type){case f.TEXT:r[r.length-1].element.appendChild(n.createXmlRepresentationOfTextPart(e,t));break;case f.PLACEHOLDER:r[r.length-1].element.appendChild(n.createXmlRepresentationOfPlaceholderPart(e,t,i++));break;case f.ICU_MESSAGE_REF:r[r.length-1].element.appendChild(n.createXmlRepresentationOfICUMessageRefPart(e,t));break;case f.START_TAG:var a=n.createXmlRepresentationOfStartTagPart(e,t,i++);r[r.length-1].element.appendChild(a),r.push({element:a,tagName:e.tagName()});break;case f.END_TAG:var o=e.tagName();if(r.length<=1||r[r.length-1].tagName!==o)throw new Error("unexpected close tag "+o);r.pop();break;case f.EMPTY_TAG:var s=n.createXmlRepresentationOfEmptyTagPart(e,t,i++);r[r.length-1].element.appendChild(s)}}),1!==r.length)throw new Error("missing close tag "+r[r.length-1].tagName)},t.prototype.createXmlRepresentationOfStartTagPart=function(e,t,n){var r=new I,i=t.ownerDocument.createElement("pc"),a=e.tagName(),o=r.getStartTagPlaceholderName(a,e.idCounter()),s=r.getCloseTagPlaceholderName(a),u="<"+a+">",l="</"+a+">";return i.setAttribute("id",n.toString(10)),i.setAttribute("equivStart",o),i.setAttribute("equivEnd",s),i.setAttribute("type",this.getTypeForTag(a)),i.setAttribute("dispStart",u),i.setAttribute("dispEnd",l),i},t.prototype.createXmlRepresentationOfEndTagPart=function(e,t){return null},t.prototype.createXmlRepresentationOfEmptyTagPart=function(e,t,n){var r=new I,i=t.ownerDocument.createElement("ph"),a=e.tagName(),o=r.getEmptyTagPlaceholderName(a,e.idCounter()),s="<"+a+"/>";return i.setAttribute("id",n.toString(10)),i.setAttribute("equiv",o),i.setAttribute("type",this.getTypeForTag(a)),i.setAttribute("disp",s),i},t.prototype.getTypeForTag=function(e){switch(e.toLowerCase()){case"br":case"b":case"i":case"u":return"fmt";case"img":return"image";case"a":return"link";default:return"other"}},t.prototype.createXmlRepresentationOfPlaceholderPart=function(e,t,n){var r=t.ownerDocument.createElement("ph"),i="INTERPOLATION";e.index()>0&&(i="INTERPOLATION_"+e.index().toString(10)),r.setAttribute("id",n.toString(10)),r.setAttribute("equiv",i);var a=e.disp();return a&&r.setAttribute("disp",a),r},t.prototype.createXmlRepresentationOfICUMessageRefPart=function(e,t){var n=t.ownerDocument.createElement("ph"),r="ICU";e.index()>0&&(r="ICU_"+e.index().toString(10)),n.setAttribute("id",e.index().toString(10)),n.setAttribute("equiv",r);var i=e.disp();return i&&n.setAttribute("disp",i),n},t}(U),B=function(e){function t(t,n,r){return e.call(this,t,n,r)||this}return o(t,e),t.prototype.sourceContent=function(){var e=l.getFirstElementByTagName(this._element,"source");return l.getXMLContent(e)},t.prototype.setSourceContent=function(e){var t=l.getFirstElementByTagName(this._element,"source");t||(t=l.getFirstElementByTagName(this._element,"segment").parentNode.appendChild(this._element.ownerDocument.createElement("source")));l.replaceContentWithXMLContent(t,e)},t.prototype.messageParser=function(){return new X},t.prototype.createSourceContentNormalized=function(){var e=l.getFirstElementByTagName(this._element,"source");return e?this.messageParser().createNormalizedMessageFromXML(e,null):null},t.prototype.targetContent=function(){var e=l.getFirstElementByTagName(this._element,"target");return l.getXMLContent(e)},t.prototype.targetContentNormalized=function(){var e=l.getFirstElementByTagName(this._element,"target");return(new X).createNormalizedMessageFromXML(e,this.sourceContentNormalized())},t.prototype.nativeTargetState=function(){var e=l.getFirstElementByTagName(this._element,"segment");return e?e.getAttribute("state"):null},t.prototype.setNativeTargetState=function(e){var t=l.getFirstElementByTagName(this._element,"segment");t&&t.setAttribute("state",e)},t.prototype.mapStateToNativeState=function(e){switch(e){case"new":return"initial";case"translated":return"translated";case"final":return"final";default:throw new Error("unknown state "+e)}},t.prototype.mapNativeStateToState=function(e){switch(e){case"initial":return"new";case"translated":case"reviewed":return"translated";case"final":return"final";default:return"new"}},t.prototype.sourceReferences=function(){for(var e=this._element.getElementsByTagName("note"),t=[],n=0;n<e.length;n++){var r=e.item(n);if("location"===r.getAttribute("category")){var i=l.getPCDATA(r);t.push(this.parseSourceAndPos(i))}}return t},t.prototype.parseSourceAndPos=function(e){var t=e.lastIndexOf(":");return t<0?{sourcefile:e,linenumber:0}:{sourcefile:e.substring(0,t),linenumber:this.parseLineNumber(e.substring(t+1))}},t.prototype.parseLineNumber=function(e){return Number.parseInt(e,10)},t.prototype.setSourceReferences=function(e){var t=this;this.removeAllSourceReferences();var r=l.getFirstElementByTagName(this._element,"notes");0!==e.length||n.isNullOrUndefined(r)||0!==r.childNodes.length?(n.isNullOrUndefined(r)&&(r=this._element.ownerDocument.createElement("notes"),this._element.insertBefore(r,this._element.childNodes.item(0))),e.forEach(function(e){var n=t._element.ownerDocument.createElement("note");n.setAttribute("category","location"),n.appendChild(t._element.ownerDocument.createTextNode(e.sourcefile+":"+e.linenumber.toString(10))),r.appendChild(n)})):r.parentNode.removeChild(r)},t.prototype.removeAllSourceReferences=function(){for(var e=this._element.getElementsByTagName("note"),t=[],n=0;n<e.length;n++){var r=e.item(n);"location"===r.getAttribute("category")&&t.push(r)}t.forEach(function(e){e.parentNode.removeChild(e)})},t.prototype.description=function(){var e=this.findNoteElementWithCategoryAttribute("description");return e?l.getPCDATA(e):null},t.prototype.setDescription=function(e){var t=this.findNoteElementWithCategoryAttribute("description");e?n.isNullOrUndefined(t)?this.createNoteElementWithCategoryAttribute("description",e):l.replaceContentWithXMLContent(t,e):n.isNullOrUndefined(t)||this.removeNoteElementWithCategoryAttribute("description")},t.prototype.findNoteElementWithCategoryAttribute=function(e){for(var t=this._element.getElementsByTagName("note"),n=0;n<t.length;n++){var r=t.item(n);if(r.getAttribute("category")===e)return r}return null},t.prototype.findAllAdditionalNoteElements=function(){for(var e=this._element.getElementsByTagName("note"),t=[],n=0;n<e.length;n++){var r=e.item(n),i=r.getAttribute("category");"description"!==i&&"meaning"!==i&&t.push(r)}return t},t.prototype.createNoteElementWithCategoryAttribute=function(e,t){var r=l.getFirstElementByTagName(this._element,"notes");n.isNullOrUndefined(r)&&(r=this._element.ownerDocument.createElement("notes"),this._element.appendChild(r));var i=this._element.ownerDocument.createElement("note");return e&&i.setAttribute("category",e),t&&l.replaceContentWithXMLContent(i,t),r.appendChild(i),i},t.prototype.removeNotesElementIfEmpty=function(){var e=l.getFirstElementByTagName(this._element,"notes");e&&(l.getFirstElementByTagName(this._element,"note")||e.parentNode.removeChild(e))},t.prototype.removeNoteElementWithCategoryAttribute=function(e){var t=this.findNoteElementWithCategoryAttribute(e);t&&t.parentNode.removeChild(t),this.removeNotesElementIfEmpty()},t.prototype.removeAllAdditionalNoteElements=function(){this.findAllAdditionalNoteElements().forEach(function(e){e.parentNode.removeChild(e)}),this.removeNotesElementIfEmpty()},t.prototype.meaning=function(){var e=this.findNoteElementWithCategoryAttribute("meaning");return e?l.getPCDATA(e):null},t.prototype.setMeaning=function(e){var t=this.findNoteElementWithCategoryAttribute("meaning");e?n.isNullOrUndefined(t)?this.createNoteElementWithCategoryAttribute("meaning",e):l.replaceContentWithXMLContent(t,e):n.isNullOrUndefined(t)||this.removeNoteElementWithCategoryAttribute("meaning")},t.prototype.notes=function(){return this.findAllAdditionalNoteElements().map(function(e){return{from:e.getAttribute("category"),text:l.getPCDATA(e)}})},t.prototype.supportsSetNotes=function(){return!0},t.prototype.setNotes=function(e){var t=this;n.isNullOrUndefined(e)||this.checkNotes(e),this.removeAllAdditionalNoteElements(),n.isNullOrUndefined(e)||e.forEach(function(e){t.createNoteElementWithCategoryAttribute(e.from,e.text)})},t.prototype.translateNative=function(e){var t=l.getFirstElementByTagName(this._element,"target");t||(t=l.getFirstElementByTagName(this._element,"source").parentNode.appendChild(this._element.ownerDocument.createElement("target")));l.replaceContentWithXMLContent(t,e),this.setTargetState("translated")},t.prototype.cloneWithSourceAsTarget=function(e,n,r){var i=new t(this._element.cloneNode(!0),this._id,r);return i.useSourceAsTarget(e,n),i},t.prototype.useSourceAsTarget=function(e,t){var n=l.getFirstElementByTagName(this._element,"source"),r=l.getFirstElementByTagName(this._element,"target");if(r||(r=n.parentNode.appendChild(this._element.ownerDocument.createElement("target"))),e||t){var i=l.getXMLContent(n),a=i;this.isICUMessage(i)||(a=this.translationMessagesFile().getNewTransUnitTargetPraefix()+i+this.translationMessagesFile().getNewTransUnitTargetSuffix()),l.replaceContentWithXMLContent(r,a)}else l.replaceContentWithXMLContent(r,"");var o=l.getFirstElementByTagName(this._element,"segment");o&&(e?o.setAttribute("state",this.mapStateToNativeState("final")):o.setAttribute("state",this.mapStateToNativeState("new")))},t}(m),W=function(e){function t(t,n,r){var i=e.call(this)||this;return i._warnings=[],i._numberOfTransUnitsWithMissingId=0,i.initializeFromContent(t,n,r),i}return o(t,e),t.prototype.initializeFromContent=function(e,t,r){this.parseContent(e,t,r);var i=this._parsedDocument.getElementsByTagName("xliff");if(1!==i.length)throw new Error(n.format('File "%s" seems to be no xliff file (should contain an xliff element)',t));var a=i.item(0).getAttribute("version");if("2.0"!==a)throw new Error(n.format('File "%s" seems to be no xliff 2 file, version should be %s, found %s',t,"2.0",a));return this},t.prototype.i18nFormat=function(){return"xlf2"},t.prototype.fileType=function(){return"XLIFF 2.0"},t.prototype.elementsWithMixedContent=function(){return["skeleton","note","data","source","target","pc","mrk"]},t.prototype.initializeTransUnits=function(){this.transUnits=[];for(var e=this._parsedDocument.getElementsByTagName("unit"),t=0;t<e.length;t++){var r=e.item(t),i=r.getAttribute("id");i||this._warnings.push(n.format('oops, trans-unit without "id" found in master, please check file %s',this._filename)),this.transUnits.push(new B(r,i,this))}},t.prototype.sourceLanguage=function(){var e=l.getFirstElementByTagName(this._parsedDocument,"xliff");return e?e.getAttribute("srcLang"):null},t.prototype.setSourceLanguage=function(e){var t=l.getFirstElementByTagName(this._parsedDocument,"xliff");t&&t.setAttribute("srcLang",e)},t.prototype.targetLanguage=function(){var e=l.getFirstElementByTagName(this._parsedDocument,"xliff");return e?e.getAttribute("trgLang"):null},t.prototype.setTargetLanguage=function(e){var t=l.getFirstElementByTagName(this._parsedDocument,"xliff");t&&t.setAttribute("trgLang",e)},t.prototype.importNewTransUnit=function(e,t,r,i){if(this.transUnitWithId(e.id))throw new Error(n.format("tu with id %s already exists in file, cannot import it",e.id));var a=e.cloneWithSourceAsTarget(t,r,this),o=l.getFirstElementByTagName(this._parsedDocument,"file");if(!o)throw new Error(n.format('File "%s" seems to be no xliff 2.0 file (should contain a file element)',this._filename));var s=!1,u=!1;i&&(this.transUnitWithId(i.id)&&(u=!0));if(i===undefined||i&&!u)o.appendChild(a.asXmlElement()),s=!0;else if(null===i){var p=l.getFirstElementByTagName(this._parsedDocument,"unit");p?(l.insertBefore(a.asXmlElement(),p),s=!0):(o.appendChild(a.asXmlElement()),s=!0)}else{var c=l.getElementByTagNameAndId(this._parsedDocument,"unit",i.id);c&&(l.insertAfter(a.asXmlElement(),c),s=!0)}return s?(this.lazyInitializeTransUnits(),this.transUnits.push(a),this.countNumbers(),a):null},t.prototype.createTranslationFileForLang=function(e,n,r,i){var a=new t(this.editedContent(),n,this.encoding());return a.setNewTransUnitTargetPraefix(this.targetPraefix),a.setNewTransUnitTargetSuffix(this.targetSuffix),a.setTargetLanguage(e),a.forEachTransUnit(function(e){e.useSourceAsTarget(r,i)}),a},t}(c),z=function(e){function t(t,n,r,i){var a=e.call(this,t,n,r)||this;return a._sourceTransUnitFromMaster=i,a}return o(t,e),t.prototype.sourceContent=function(){return this._sourceTransUnitFromMaster?this._sourceTransUnitFromMaster.sourceContent():null},t.prototype.supportsSetSourceContent=function(){return!1},t.prototype.setSourceContent=function(e){},t.prototype.messageParser=function(){return new O},t.prototype.createSourceContentNormalized=function(){return this._sourceTransUnitFromMaster?this._sourceTransUnitFromMaster.createSourceContentNormalized():null},t.prototype.targetContent=function(){return l.getXMLContent(this._element)},t.prototype.targetContentNormalized=function(){return this.messageParser().createNormalizedMessageFromXML(this._element,this.sourceContentNormalized())},t.prototype.nativeTargetState=function(){if(this._sourceTransUnitFromMaster){var e=this._sourceTransUnitFromMaster.sourceContent();return e&&e!==this.targetContent()&&this.targetContent()?"final":"new"}return null},t.prototype.mapStateToNativeState=function(e){return e},t.prototype.mapNativeStateToState=function(e){return e},t.prototype.setNativeTargetState=function(e){},t.prototype.sourceReferences=function(){return this._sourceTransUnitFromMaster?this._sourceTransUnitFromMaster.sourceReferences():[]},t.prototype.supportsSetSourceReferences=function(){return!1},t.prototype.setSourceReferences=function(e){},t.prototype.description=function(){return this._sourceTransUnitFromMaster?this._sourceTransUnitFromMaster.description():null},t.prototype.meaning=function(){return this._sourceTransUnitFromMaster?this._sourceTransUnitFromMaster.meaning():null},t.prototype.supportsSetDescriptionAndMeaning=function(){return!1},t.prototype.setDescription=function(e){},t.prototype.setMeaning=function(e){},t.prototype.notes=function(){return[]},t.prototype.supportsSetNotes=function(){return!1},t.prototype.setNotes=function(e){},t.prototype.cloneWithSourceAsTarget=function(e,t,n){return this},t.prototype.useSourceAsTarget=function(e,t){},t.prototype.translateNative=function(e){var t=this._element;n.isNullOrUndefined(e)&&(e=""),l.replaceContentWithXMLContent(t,e)},t}(m),k=function(e){function t(t,n,r,i,a){var o=e.call(this)||this;return o._translationMessageFileFactory=t,o._warnings=[],o._numberOfTransUnitsWithMissingId=0,o.initializeFromContent(n,r,i,a),o}return o(t,e),t.prototype.initializeFromContent=function(e,t,r,i){if(this.parseContent(e,t,r),1!==this._parsedDocument.getElementsByTagName("translationbundle").length)throw new Error(n.format('File "%s" seems to be no xtb file (should contain a translationbundle element)',t));if(i)try{this._masterFile=this._translationMessageFileFactory.createFileFromFileContent("xmb",i.xmlContent,i.path,i.encoding);var a=this._masterFile.numberOfTransUnits(),o=this.numberOfTransUnits();a!==o&&this._warnings.push(n.format("%s trans units found in master, but this file has %s. Check if it is the correct master",a,o))}catch(s){throw new Error(n.format('File "%s" seems to be no xmb file. An xtb file needs xmb as master file.',i.path))}return this},t.prototype.initializeTransUnits=function(){this.transUnits=[];for(var e=this._parsedDocument.getElementsByTagName("translation"),t=0;t<e.length;t++){var r=e.item(t),i=r.getAttribute("id");i||this._warnings.push(n.format('oops, msg without "id" found in master, please check file %s',this._filename));var a=null;this._masterFile&&(a=this._masterFile.transUnitWithId(i)),this.transUnits.push(new z(r,i,this,a))}},t.prototype.i18nFormat=function(){return"xtb"},t.prototype.fileType=function(){return"XTB"},t.prototype.elementsWithMixedContent=function(){return["translation"]},t.prototype.sourceLanguage=function(){return this._masterFile?this._masterFile.sourceLanguage():null},t.prototype.setSourceLanguage=function(e){},t.prototype.targetLanguage=function(){var e=l.getFirstElementByTagName(this._parsedDocument,"translationbundle");return e?e.getAttribute("lang"):null},t.prototype.setTargetLanguage=function(e){var t=l.getFirstElementByTagName(this._parsedDocument,"translationbundle");t&&t.setAttribute("lang",e)},t.prototype.importNewTransUnit=function(e,t,r,i){if(this.transUnitWithId(e.id))throw new Error(n.format("tu with id %s already exists in file, cannot import it",e.id));var a=e.cloneWithSourceAsTarget(t,r,this),o=l.getFirstElementByTagName(this._parsedDocument,"translationbundle");if(!o)throw new Error(n.format('File "%s" seems to be no xtb file (should contain a translationbundle element)',this._filename));var s=o.ownerDocument.createElement("translation");s.setAttribute("id",e.id);var u=r||t?e.sourceContent():"";e.isICUMessage(u)||(u=this.getNewTransUnitTargetPraefix()+u+this.getNewTransUnitTargetSuffix()),l.replaceContentWithXMLContent(s,u);var p=new z(s,e.id,this,a),c=!1,m=!1;i&&(this.transUnitWithId(i.id)&&(m=!0));if(i===undefined||i&&!m)o.appendChild(p.asXmlElement()),c=!0;else if(null===i){var f=l.getFirstElementByTagName(this._parsedDocument,"translation");f?(l.insertBefore(p.asXmlElement(),f),c=!0):(o.appendChild(p.asXmlElement()),c=!0)}else{var h=l.getElementByTagNameAndId(this._parsedDocument,"translation",i.id);h&&(l.insertAfter(p.asXmlElement(),h),c=!0)}return c?(this.lazyInitializeTransUnits(),this.transUnits.push(p),this.countNumbers(),p):null},t.prototype.createTranslationFileForLang=function(e,t,r,i){throw new Error(n.format('File "%s", xtb files are not translatable, they are already translations',t))},t}(c),G=function(){function e(){}return e.fromFileContent=function(t,n,r,i,a){return(new e).createFileFromFileContent(t,n,r,i,a)},e.fromUnknownFormatFileContent=function(t,n,r,i){return(new e).createFileFromUnknownFormatFileContent(t,n,r,i)},e.prototype.createFileFromFileContent=function(e,t,r,i,a){if("xlf"===e)return new L(t,r,i);if("xlf2"===e)return new W(t,r,i);if("xmb"===e)return new D(this,t,r,i);if("xtb"===e)return new k(this,t,r,i,a);throw new Error(n.format('oops, unsupported format "%s"',e))},e.prototype.createFileFromUnknownFormatFileContent=function(t,r,i,a){var o=["xlf","xlf2","xmb","xtb"];r&&r.endsWith("xmb")&&(o=["xmb","xtb","xlf","xlf2"]),r&&r.endsWith("xtb")&&(o=["xtb","xmb","xlf","xlf2"]);for(var s=0;s<o.length;s++){var u=o[s];try{var l=e.fromFileContent(u,t,r,i,a);if(l)return l}catch(p){}}throw new Error(n.format("could not identify file format, it is neiter XLIFF (1.2 or 2.0) nor XMB/XTB"))},e}();e.FILETYPE_XLIFF12="XLIFF 1.2",e.FILETYPE_XLIFF20="XLIFF 2.0",e.FILETYPE_XMB="XMB",e.FILETYPE_XTB="XTB",e.FORMAT_XLIFF12="xlf",e.FORMAT_XLIFF20="xlf2",e.FORMAT_XMB="xmb",e.FORMAT_XTB="xtb",e.NORMALIZATION_FORMAT_DEFAULT="default",e.NORMALIZATION_FORMAT_NGXTRANSLATE="ngxtranslate",e.NgxI18nsupportLibModule=u,e.STATE_FINAL="final",e.STATE_NEW="new",e.STATE_TRANSLATED="translated",e.TranslationMessagesFileFactory=G,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=ngx-i18nsupport-ngx-i18nsupport-lib.umd.min.js.map