{"size": 33105, "ext": "js", "max_stars_repo_path": "bundles/ngx-i18nsupport-ngx-i18nsupport.umd.min.js", "max_stars_repo_name": "NickClark/ngx-i18nsupport-v4", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "bundles/ngx-i18nsupport-ngx-i18nsupport.umd.min.js", "max_issues_repo_name": "NickClark/ngx-i18nsupport-v4", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "bundles/ngx-i18nsupport-ngx-i18nsupport.umd.min.js", "max_forks_repo_name": "NickClark/ngx-i18nsupport-v4", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 16552.5, "max_line_length": 33037, "alphanum_fraction": 0.748829482}
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("stream"),require("chalk"),require("util"),require("fs"),require("@ngx-i18nsupport/ngx-i18nsupport-lib"),require("path"),require("rxjs"),require("rxjs/operators"),require("he"),require("request")):"function"==typeof define&&define.amd?define("@ngx-i18nsupport/ngx-i18nsupport",["exports","@angular/core","stream","chalk","util","fs","@ngx-i18nsupport/ngx-i18nsupport-lib","path","rxjs","rxjs/operators","he","request"],e):e(((t=t||self)["ngx-i18nsupport"]=t["ngx-i18nsupport"]||{},t["ngx-i18nsupport"]["ngx-i18nsupport"]={}),t.ng.core,t.stream,t.chalk,t.util,t.fs,t.ngxI18nsupportLib,t.path,t.rxjs,t.rxjs.operators,t.he,t.request)}(this,function(t,e,r,n,a,i,s,o,u,l,c,p){"use strict";n=n&&n.hasOwnProperty("default")?n["default"]:n;var f=function(t,e){return(f=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};function h(t,e){function r(){this.constructor=t}f(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}function g(t){var e="function"==typeof Symbol&&t[Symbol.iterator],r=0;return e?e.call(t):{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}}}function d(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,a,i=r.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(n=i.next()).done;)s.push(n.value)}catch(o){a={error:o}}finally{try{n&&!n.done&&(r=i["return"])&&r.call(i)}finally{if(a)throw a.error}}return s}function m(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(d(arguments[e]));return t}var y=function(){function t(){}return t.decorators=[{type:e.NgModule,args:[{imports:[],declarations:[],exports:[]}]}],t}();function v(t){return t===undefined||null===t}function _(t){return Array.isArray(t)}var x=function(t){function e(){var e=t.call(this)||this;return e.resultString="",e}return h(e,t),e.prototype._write=function(t,e,r){var n;n="string"==typeof t?t:t instanceof Buffer?t.toString():Buffer.alloc(t).toString(e),this.resultString=this.resultString+n,r()},e.prototype.writtenData=function(){return this.resultString},e}(r.Writable),T={ERROR:0,WARN:1,INFO:2,DEBUG:3};T[T.ERROR]="ERROR",T[T.WARN]="WARN",T[T.INFO]="INFO",T[T.DEBUG]="DEBUG";var F=function(){function t(t){this._quiet=!1,this._verbose=!1,this.outputStream=t||process.stdout}return t.prototype.setVerbose=function(){this._verbose=!0},t.prototype.setQuiet=function(){this._quiet=!0},t.prototype.verbose=function(){return this._verbose},t.prototype.quiet=function(){return this._quiet},t.prototype.error=function(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];this.log(T.ERROR,t,e)},t.prototype.warn=function(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];this.log(T.WARN,t,e)},t.prototype.info=function(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];this.log(T.INFO,t,e)},t.prototype.debug=function(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];this.log(T.DEBUG,t,e)},t.prototype.log=function(t,e,r){if(this.isOutputEnabled(t)){var i;switch(t){case T.ERROR:i=n.red("ERROR: "+e);break;case T.WARN:i=n.magenta("WARNING: "+e);break;default:i=n.gray("* "+e)}var s=a.format.apply(void 0,m([i],r));this.outputStream.write(s+"\n")}},t.prototype.isOutputEnabled=function(t){var e,r;switch(this._quiet&&this._verbose?(e=!1,r=!1):(e=this._quiet,r=this._verbose),t){case T.ERROR:return!0;case T.WARN:return!e;case T.INFO:return r&&!e;case T.DEBUG:return r;default:return!0}},t}(),w=function(t){function e(r){var n=t.call(this,r)||this;return Object.setPrototypeOf(n,e.prototype),n}return h(e,t),e}(Error),S=function(){function t(){}return t.exists=function(t){return i.existsSync(t)},t.read=function(t,e){return i.readFileSync(t,e)},t.replaceContent=function(t,e,r){i.writeFileSync(t,e,{encoding:r})},t.copy=function(t,e){for(var r=Buffer.alloc(65536),n=i.openSync(t,"r"),a=i.openSync(e,"w"),s=1,o=0;s>0;)s=i.readSync(n,r,0,65536,o),i.writeSync(a,r,0,s),o+=s;i.closeSync(n),i.closeSync(a)},t.deleteFolderRecursive=function(e){i.existsSync(e)&&(i.readdirSync(e).forEach(function(r){var n=e+"/"+r;i.lstatSync(n).isDirectory()?t.deleteFolderRecursive(n):i.unlinkSync(n)}),i.rmdirSync(e))},t.deleteFolderContentRecursive=function(e){i.existsSync(e)&&i.readdirSync(e).forEach(function(r){var n=e+"/"+r;i.lstatSync(n).isDirectory()?t.deleteFolderRecursive(n):i.unlinkSync(n)})},t.deleteFile=function(t){i.unlinkSync(t)},t}(),b=function(){function t(t){this.extractionPatternString=t;var e=t.split("|");this._matchExplicitId=!1,this._descriptionPatterns=[];for(var r=0;r<e.length;r++){var n=e[r];if("@@"===n){if(this._matchExplicitId)throw new Error("extraction pattern must not contain @@ twice");this._matchExplicitId=!0}else{var a=this.checkValidDescriptionPattern(n);if(a)throw new Error(a);this._descriptionPatterns.push(n)}}}return t.prototype.isExplicitIdMatched=function(t){return t&&this._matchExplicitId},t.prototype.isDescriptionMatched=function(t){return this._descriptionPatterns.indexOf(t)>=0},t.prototype.checkValidDescriptionPattern=function(t){return t?/^[a-zA-Z_][a-zA-Z_-]*$/.test(t)?null:"description pattern must be an identifier containing only letters, digits, _ or -":"empty value not allowed"},t}(),O=function(){function t(t,e){this.messagesFile=t,this.extractionPattern=new b(e)}return t.checkPattern=function(t){try{if(new b(t))return null}catch(e){return e.message}return null},t.extract=function(e,r,n){new t(e,r).extractTo(n)},t.prototype.extractTo=function(t){var e=this.toNgxTranslations(this.extract());e&&Object.keys(e).length>0?S.replaceContent(t,JSON.stringify(e,null,4),"UTF-8"):S.exists(t)&&S.deleteFile(t)},t.prototype.extract=function(){var t=this,e=[];return this.messagesFile.forEachTransUnit(function(r){var n=t.ngxTranslateIdFromTU(r);if(n){var a=r.targetContentNormalized().asDisplayString(s.NORMALIZATION_FORMAT_NGXTRANSLATE);e.push({id:n,message:a})}}),e},t.prototype.ngxTranslateIdFromTU=function(t){if(this.isExplicitlySetId(t.id))return this.extractionPattern.isExplicitIdMatched(t.id)?t.id:null;var e=t.description();return e&&this.extractionPattern.isDescriptionMatched(e)?t.meaning():void 0},t.prototype.isExplicitlySetId=function(t){if(v(t))return!1;return!/^[0-9a-f]{11,}$/.test(t)},t.prototype.toNgxTranslations=function(t){var e=this,r={};return t.forEach(function(t){e.putInTranslationObject(r,t)}),r},t.prototype.putInTranslationObject=function(t,e){var r,n,a=e.id.indexOf(".");if(0===a||a===e.id.length-1)throw new Error('bad nxg-translate id "'+e.id+'"');a<0?(r=e.id,n=""):(r=e.id.substring(0,a),n=e.id.substring(a+1));var i=t[r];if(v(i)){if(""===n)return void(t[r]=e.message);i={},t[r]=i}else if(""===n)throw new Error('duplicate id praefix "'+e.id+'"');this.putInTranslationObject(i,{id:n,message:e.message})},t.DefaultExtractionPattern="@@|ngx-translate",t}(),E=["package.json",".angular-cli.json"],I=function(){function t(){this.errorsFound=[],this.warningsFound=[]}return t.createFromOptions=function(e,r){var n=new t;return n.configure(e,r),n},t.readProfileCandidate=function(t){var e;try{e=i.readFileSync(t,"UTF-8")}catch(n){return null}var r=JSON.parse(e);return r&&r.xliffmergeOptions?r:null},t.prototype.configure=function(t,e){this.errorsFound=[],this.warningsFound=[],e||(e=this.readProfile(t));var r=!!e;t.quiet&&(this._quiet=t.quiet),t.verbose&&(this._verbose=t.verbose),r&&(this.initializeFromConfig(e),t.languages&&t.languages.length>0&&(this._languages=t.languages,this._defaultLanguage||(this._defaultLanguage=this._languages[0])),this.checkParameters())},t.prototype.readProfile=function(e){var r,n,a,s=e.profilePath;if(!s){try{for(var o=g(E),u=o.next();!u.done;u=o.next()){var l=u.value,c=t.readProfileCandidate(l);if(c)return this.usedProfilePath=l,c}}catch(h){r={error:h}}finally{try{u&&!u.done&&(n=o["return"])&&n.call(o)}finally{if(r)throw r.error}}return{}}try{a=i.readFileSync(s,"UTF-8")}catch(d){return this.errorsFound.push(new w('could not read profile "'+s+'"')),null}this.usedProfilePath=s;var p=JSON.parse(a),f=p.xliffmergeOptions;return f.srcDir=this.adjustPathToProfilePath(s,f.srcDir),f.genDir=this.adjustPathToProfilePath(s,f.genDir),f.apikeyfile=this.adjustPathToProfilePath(s,f.apikeyfile),p},t.prototype.adjustPathToProfilePath=function(t,e){return!e||o.isAbsolute(e)?e:o.join(o.dirname(t),e).replace(/\\/g,"/")},t.prototype.initializeFromConfig=function(t){if(t){var e=t.xliffmergeOptions;e?(v(e.quiet)||(this._quiet=e.quiet),v(e.verbose)||(this._verbose=e.verbose),v(e.allowIdChange)||(this._allowIdChange=e.allowIdChange),e.defaultLanguage&&(this._defaultLanguage=e.defaultLanguage),e.languages&&(this._languages=e.languages),e.srcDir&&(this._srcDir=e.srcDir),e.angularCompilerOptions&&e.angularCompilerOptions.genDir&&(this._genDir=e.angularCompilerOptions.genDir),e.genDir&&(this._genDir=e.genDir),e.i18nBaseFile&&(this._i18nBaseFile=e.i18nBaseFile),e.i18nFile&&(this._i18nFile=e.i18nFile),e.i18nFormat&&(this._i18nFormat=e.i18nFormat),e.encoding&&(this._encoding=e.encoding),v(e.removeUnusedIds)||(this._removeUnusedIds=e.removeUnusedIds),v(e.supportNgxTranslate)||(this._supportNgxTranslate=e.supportNgxTranslate),v(e.ngxTranslateExtractionPattern)||(this._ngxTranslateExtractionPattern=e.ngxTranslateExtractionPattern),v(e.useSourceAsTarget)||(this._useSourceAsTarget=e.useSourceAsTarget),v(e.targetPraefix)||(this._targetPraefix=e.targetPraefix),v(e.targetSuffix)||(this._targetSuffix=e.targetSuffix),v(e.autotranslate)||(this._autotranslate=e.autotranslate),v(e.beautifyOutput)||(this._beautifyOutput=e.beautifyOutput),v(e.preserveOrder)||(this._preserveOrder=e.preserveOrder),v(e.apikey)||(this._apikey=e.apikey),v(e.apikeyfile)||(this._apikeyfile=e.apikeyfile)):this.warningsFound.push('did not find "xliffmergeOptions" in profile, using defaults')}},t.prototype.checkParameters=function(){var t,e,r=this;this.checkLanguageSyntax(this.defaultLanguage()),0===this.languages().length&&this.errorsFound.push(new w("no languages specified")),this.languages().forEach(function(t){r.checkLanguageSyntax(t)});try{t=i.statSync(this.srcDir())}catch(a){e=a}!e&&t.isDirectory()||this.errorsFound.push(new w('srcDir "'+this.srcDir()+'" is not a directory'));try{t=i.statSync(this.genDir())}catch(a){e=a}!e&&t.isDirectory()||this.errorsFound.push(new w('genDir "'+this.genDir()+'" is not a directory'));try{i.accessSync(this.i18nFile(),i.constants.R_OK)}catch(e){this.errorsFound.push(new w('i18nFile "'+this.i18nFile()+'" is not readable'))}if("xlf"!==this.i18nFormat()&&"xlf2"!==this.i18nFormat()&&"xmb"!==this.i18nFormat()&&this.errorsFound.push(new w('i18nFormat "'+this.i18nFormat()+'" invalid, must be "xlf" or "xlf2" or "xmb"')),this.autotranslate()&&!this.apikey()&&this.errorsFound.push(new w("autotranslate requires an API key, please set one")),this.autotranslatedLanguages().forEach(function(t){r.languages().indexOf(t)<0&&r.errorsFound.push(new w('autotranslate language "'+t+'" is not in list of languages')),t===r.defaultLanguage()&&r.errorsFound.push(new w('autotranslate language "'+t+'" cannot be translated, because it is the source language'))}),this.supportNgxTranslate()){var n=O.checkPattern(this.ngxTranslateExtractionPattern());v(n)||this.errorsFound.push(new w('ngxTranslateExtractionPattern "'+this.ngxTranslateExtractionPattern()+'": '+n))}this.useSourceAsTarget()||(this.targetPraefix().length>0&&this.warningsFound.push('configured targetPraefix "'+this.targetPraefix()+'" will not be used because "useSourceAsTarget" is disabled"'),this.targetSuffix().length>0&&this.warningsFound.push('configured targetSuffix "'+this.targetSuffix()+'" will not be used because "useSourceAsTarget" is disabled"'))},t.prototype.checkLanguageSyntax=function(t){/^[a-zA-Z]{1,8}([-_][a-zA-Z0-9]{1,8})*$/.test(t)||this.errorsFound.push(new w('language "'+t+'" is not valid'))},t.prototype.allowIdChange=function(){return!v(this._allowIdChange)&&this._allowIdChange},t.prototype.verbose=function(){return!v(this._verbose)&&this._verbose},t.prototype.quiet=function(){return!v(this._quiet)&&this._quiet},t.prototype.showAllParameters=function(t){var e,r;t.debug("xliffmerge Used Parameters:"),t.debug('usedProfilePath:\t"%s"',this.usedProfilePath),t.debug('defaultLanguage:\t"%s"',this.defaultLanguage()),t.debug('srcDir:\t"%s"',this.srcDir()),t.debug('genDir:\t"%s"',this.genDir()),t.debug('i18nBaseFile:\t"%s"',this.i18nBaseFile()),t.debug('i18nFile:\t"%s"',this.i18nFile()),t.debug("languages:\t%s",this.languages());try{for(var n=g(this.languages()),a=n.next();!a.done;a=n.next()){var i=a.value;t.debug("outputFile[%s]:\t%s",i,this.generatedI18nFile(i))}}catch(s){e={error:s}}finally{try{a&&!a.done&&(r=n["return"])&&r.call(n)}finally{if(e)throw e.error}}t.debug("removeUnusedIds:\t%s",this.removeUnusedIds()),t.debug("supportNgxTranslate:\t%s",this.supportNgxTranslate()),this.supportNgxTranslate()&&t.debug("ngxTranslateExtractionPattern:\t%s",this.ngxTranslateExtractionPattern()),t.debug("useSourceAsTarget:\t%s",this.useSourceAsTarget()),this.useSourceAsTarget()&&(t.debug('targetPraefix:\t"%s"',this.targetPraefix()),t.debug('targetSuffix:\t"%s"',this.targetSuffix())),t.debug("allowIdChange:\t%s",this.allowIdChange()),t.debug("beautifyOutput:\t%s",this.beautifyOutput()),t.debug("preserveOrder:\t%s",this.preserveOrder()),t.debug("autotranslate:\t%s",this.autotranslate()),this.autotranslate()&&(t.debug("autotranslated languages:\t%s",this.autotranslatedLanguages()),t.debug("apikey:\t%s",this.apikey()?"****":"NOT SET"),t.debug("apikeyfile:\t%s",this.apikeyfile()))},t.prototype.defaultLanguage=function(){return this._defaultLanguage?this._defaultLanguage:"en"},t.prototype.languages=function(){return this._languages?this._languages:[]},t.prototype.srcDir=function(){return this._srcDir?this._srcDir:"."},t.prototype.i18nBaseFile=function(){return this._i18nBaseFile?this._i18nBaseFile:"messages"},t.prototype.i18nFile=function(){return o.join(this.srcDir(),this._i18nFile?this._i18nFile:this.i18nBaseFile()+"."+this.suffixForGeneratedI18nFile()).replace(/\\/g,"/")},t.prototype.i18nFormat=function(){return this._i18nFormat?this._i18nFormat:"xlf"},t.prototype.generatedI18nFile=function(t){return o.join(this.genDir(),this.i18nBaseFile()+"."+t+"."+this.suffixForGeneratedI18nFile()).replace(/\\/g,"/")},t.prototype.suffixForGeneratedI18nFile=function(){switch(this.i18nFormat()){case"xlf":case"xlf2":return"xlf";case"xmb":return"xtb"}},t.prototype.generatedNgxTranslateFile=function(t){return o.join(this.genDir(),this.i18nBaseFile()+"."+t+".json").replace(/\\/g,"/")},t.prototype.encoding=function(){return this._encoding?this._encoding:"UTF-8"},t.prototype.genDir=function(){return this._genDir?this._genDir:this.srcDir()},t.prototype.removeUnusedIds=function(){return!!v(this._removeUnusedIds)||this._removeUnusedIds},t.prototype.supportNgxTranslate=function(){return!v(this._supportNgxTranslate)&&this._supportNgxTranslate},t.prototype.ngxTranslateExtractionPattern=function(){return v(this._ngxTranslateExtractionPattern)?O.DefaultExtractionPattern:this._ngxTranslateExtractionPattern},t.prototype.useSourceAsTarget=function(){return!!v(this._useSourceAsTarget)||this._useSourceAsTarget},t.prototype.targetPraefix=function(){return v(this._targetPraefix)?"":this._targetPraefix},t.prototype.targetSuffix=function(){return v(this._targetSuffix)?"":this._targetSuffix},t.prototype.beautifyOutput=function(){return!v(this._beautifyOutput)&&this._beautifyOutput},t.prototype.preserveOrder=function(){return!!v(this._preserveOrder)||this._preserveOrder},t.prototype.autotranslate=function(){return!v(this._autotranslate)&&(_(this._autotranslate)?this._autotranslate.length>0:this._autotranslate)},t.prototype.autotranslateLanguage=function(t){return this.autotranslatedLanguages().indexOf(t)>=0},t.prototype.autotranslatedLanguages=function(){return v(this._autotranslate)||!1===this._autotranslate?[]:_(this._autotranslate)?this._autotranslate:this.languages().slice(1)},t.prototype.apikey=function(){if(v(this._apikey)){var t=this.apikeyfile();if(this.apikeyfile()){if(i.existsSync(t))return S.read(t,"utf-8");throw new Error(a.format("api key file not found: API_KEY_FILE=%s",t))}return null}return this._apikey},t.prototype.apikeyfile=function(){return this._apikeyfile?this._apikeyfile:process.env.API_KEY_FILE?process.env.API_KEY_FILE:null},t}(),U=null;try{U=require(o.resolve(__dirname,"..","package.json"))}catch(M){try{U=require(o.resolve(__dirname,"..","..","package.json"))}catch(M){U=null}}var N=U?U.version:"unknown",A=function(){function t(){}return t.readXmlFileContent=function(e,r){r||(r=t.DEFAULT_ENCODING);var n=S.read(e,r),a=t.encodingFromXml(n);return a!==r&&(n=S.read(e,a)),{content:n,encoding:a}},t.encodingFromXml=function(t){var e=t.indexOf('encoding="');if(e<0)return this.DEFAULT_ENCODING;var r=t.indexOf('"',e+10);return t.substring(e+10,r)},t.DEFAULT_ENCODING="UTF-8",t}(),P=function(){function t(){}return t.fromFile=function(e,r,n,a){var i=A.readXmlFileContent(r,n),o=t.masterFileContent(a,n);return s.TranslationMessagesFileFactory.fromFileContent(e,i.content,r,i.encoding,o)},t.fromUnknownFormatFile=function(e,r,n){var a=A.readXmlFileContent(e,r),i=t.masterFileContent(n,r);return s.TranslationMessagesFileFactory.fromUnknownFormatFileContent(a.content,e,a.encoding,i)},t.masterFileContent=function(t,e){if(t){var r=A.readXmlFileContent(t,e);return{xmlContent:r.content,path:t,encoding:r.encoding}}return null},t.save=function(t,e){S.replaceContent(t.filename(),t.editedContent(e),t.encoding())},t}(),C=function(){function t(t){this._request=p,this._apiKey=t,this._rootUrl="https://translation.googleapis.com/"}return t.stripRegioncode=function(t){for(var e=t.toLowerCase(),r=0;r<e.length;r++){var n=e.charAt(r);if(n<"a"||n>"z")return e.substring(0,r)}return e},t.prototype.setApiKey=function(t){this._apiKey=t},t.prototype.translateMultipleStrings=function(e,r,n){var a=this;if(0===e.length)return u.of([]);if(!this._apiKey)return u.throwError("cannot autotranslate: no api key");if(!r||!n)return u.throwError("cannot autotranslate: source and target language must be set");r=t.stripRegioncode(r),n=t.stripRegioncode(n);var i=this.splitMessagesToGoogleLimit(e).map(function(t){return a.limitedTranslateMultipleStrings(t,r,n)});return u.forkJoin(i).pipe(l.map(function(t){for(var e=[],r=0;r<t.length;r++)e=e.concat(t[r]);return e}))},t.prototype.splitMessagesToGoogleLimit=function(t){if(t.length<=128)return[t];for(var e=[],r=[],n=0,a=0;a<t.length;a++)r.push(t[a]),++n>=128&&(e.push(r),r=[],n=0);return r.length>0&&e.push(r),e},t.prototype.limitedTranslateMultipleStrings=function(t,e,r){var n=this._rootUrl+"language/translate/v2?key="+this._apiKey,i={url:n,body:{q:t,target:r,source:e},json:!0};return this.post(n,i).pipe(l.map(function(t){var n=t.body;if(!n)throw new Error("no result received");if(n.error){if(400===n.error.code){if("Invalid Value"===n.error.message)throw new Error(a.format('Translation from "%s" to "%s" not supported',e,r));throw new Error(a.format("Invalid request: %s",n.error.message))}throw new Error(a.format("Error %s: %s",n.error.code,n.error.message))}return n.data.translations.map(function(t){return t.translatedText})}))},t.prototype.post=function(t,e){return this._call.apply(this,[].concat("post",t,Object.assign({},e||{})))},t.prototype._call=function(t,e,r){var n=this;return u.Observable.create(function(a){var i=[].concat(e,Object.assign({},r||{}),function(t,e,r){if(t)return a.error(t);a.next(Object.assign({},{response:e,body:r})),a.complete()});try{n._request[t].apply(n._request,i)}catch(s){a.error(s)}})},t}(),D=function(){function t(t,e){this._success=t,this._details=e}return t.prototype.success=function(){return this._success},t}(),R=function(){function t(t,e){this._from=t,this._to=e,this._total=0,this._ignored=0,this._success=0,this._failed=0}return t.prototype.setError=function(t,e){this._error=t,this._total=e,this._failed=e},t.prototype.error=function(){return this._error},t.prototype.setIgnored=function(t){this._total+=t,this._ignored=t},t.prototype.addSingleResult=function(t,e){this._total++,e.success()?this._success++:this._failed++},t.prototype.merge=function(t){this._error||(this._error=t._error),this._total+=t.total(),this._ignored+=t.ignored(),this._success+=t.success(),this._failed+=t.failed()},t.prototype.total=function(){return this._total},t.prototype.ignored=function(){return this._ignored},t.prototype.success=function(){return this._success},t.prototype.failed=function(){return this._failed},t.prototype.content=function(){return this._error?a.format('Auto translation from "%s" to "%s" failed: "%s", failed units: %s',this._from,this._to,this._error,this._failed):a.format('Auto translation from "%s" to "%s", total auto translated units: %s, ignored: %s, succesful: %s, failed: %s',this._from,this._to,this._total,this._ignored,this._success,this._failed)},t}(),k=function(){function t(t){this.autoTranslateService=new C(t)}return t.prototype.autoTranslate=function(t,e,r){return u.forkJoin(m([this.doAutoTranslateNonICUMessages(t,e,r)],this.doAutoTranslateICUMessages(t,e,r))).pipe(l.map(function(t){for(var e=t[0],r=1;r<t.length;r++)e.merge(t[r]);return e}))},t.prototype.allUntranslatedTUs=function(t){var e=[];return t.forEachTransUnit(function(t){t.targetState()===s.STATE_NEW&&e.push(t)}),e},t.prototype.doAutoTranslateNonICUMessages=function(t,e,r){var n=this,a=this.allUntranslatedTUs(r),i=a.filter(function(t){return v(t.sourceContentNormalized().getICUMessage())}),s=i.map(function(t){return t.sourceContentNormalized().asDisplayString()});return this.autoTranslateService.translateMultipleStrings(s,t,e).pipe(l.map(function(t){return t.map(function(t){return c.decode(t)})}),l.map(function(r){var s=new R(t,e);s.setIgnored(a.length-i.length);for(var o=0;o<r.length;o++){var u=i[o],l=r[o],c=n.autoTranslateNonICUUnit(u,l);s.addSingleResult(u,c)}return s}),l.catchError(function(r){var n=new R(t,e);return n.setError(r.message,s.length),u.of(n)}))},t.prototype.doAutoTranslateICUMessages=function(t,e,r){var n=this;return this.allUntranslatedTUs(r).filter(function(t){return!v(t.sourceContentNormalized().getICUMessage())}).map(function(r){return n.doAutoTranslateICUMessage(t,e,r)})},t.prototype.doAutoTranslateICUMessage=function(t,e,r){var n=this,a=r.sourceContentNormalized().getICUMessage().getCategories();if(a.find(function(t){return!v(t.getMessageNormalized().getICUMessage())})){var i=new R(t,e);return i.setIgnored(1),u.of(i)}var s=a.map(function(t){return t.getMessageNormalized().asDisplayString()});return this.autoTranslateService.translateMultipleStrings(s,t,e).pipe(l.map(function(t){return t.map(function(t){return c.decode(t)})}),l.map(function(i){for(var s=new R(t,e),o={},u=0;u<i.length;u++)o[a[u].getCategory()]=i[u];var l=n.autoTranslateICUUnit(r,o);return s.addSingleResult(r,l),s}),l.catchError(function(r){var n=new R(t,e);return n.setError(r.message,s.length),u.of(n)}))},t.prototype.autoTranslateNonICUUnit=function(t,e){return this.autoTranslateUnit(t,t.sourceContentNormalized().translate(e))},t.prototype.autoTranslateICUUnit=function(t,e){return this.autoTranslateUnit(t,t.sourceContentNormalized().translateICUMessage(e))},t.prototype.autoTranslateUnit=function(t,e){var r=e.validate(),n=e.validateWarnings();return v(r)?v(n)?(t.translate(e),new D(!0,null)):new D(!1,"warnings detected, not translated"):new D(!1,"errors detected, not translated")},t}(),L=function(){function t(t,e){this.commandOutput=t,this.options=e,this.parameters=null}return t.main=function(e){var r=t.parseArgs(e);r&&new t(new F(process.stdout),r).run(function(t){process.exit(t)})},t.parseArgs=function(e){for(var r={languages:[]},n=2;n<e.length;n++){var a=e[n];if("--version"===a||"-version"===a)console.log("xliffmerge "+N);else if("--verbose"===a||"-v"===a)r.verbose=!0;else if("--profile"===a||"-p"===a){if(++n>=e.length)return console.log("missing config file"),t.showUsage(),null;r.profilePath=e[n]}else if("--quiet"===a||"-q"===a)r.quiet=!0;else if("--help"===a||"-help"===a||"-h"===a)t.showUsage();else{if(a.length>0&&"-"===a.charAt(0))return console.log("unknown option"),null;r.languages.push(a)}}return r},t.showUsage=function(){console.log("usage: xliffmerge <option>* <language>*"),console.log("Options"),console.log("\t-p|--profile a json configuration file containing all relevant parameters."),console.log("\t\tfor details please consult the home page https://github.com/martinroob/ngx-i18nsupport"),console.log("\t-v|--verbose show some output for debugging purposes"),console.log("\t-q|--quiet only show errors, nothing else"),console.log("\t-version|--version show version string"),console.log(""),console.log('\t<language> has to be a valid language short string, e,g. "en", "de", "de-ch"')},t.createFromOptions=function(e,r,n){var a=new t(e,r);return a.parameters=I.createFromOptions(r,n),a},t.prototype.run=function(t,e){this.runAsync().subscribe(function(e){v(t)||t(e)},function(t){v(e)||e(t)})},t.prototype.runAsync=function(){var t,e,r,n,a=this;if(this.options&&this.options.quiet&&this.commandOutput.setQuiet(),this.options&&this.options.verbose&&this.commandOutput.setVerbose(),this.parameters||(this.parameters=I.createFromOptions(this.options)),this.commandOutput.info("xliffmerge version %s",N),this.parameters.verbose()&&this.parameters.showAllParameters(this.commandOutput),this.parameters.errorsFound.length>0){try{for(var i=g(this.parameters.errorsFound),s=i.next();!s.done;s=i.next()){var o=s.value;this.commandOutput.error(o.message)}}catch(d){t={error:d}}finally{try{s&&!s.done&&(e=i["return"])&&e.call(i)}finally{if(t)throw t.error}}return u.of(-1)}if(this.parameters.warningsFound.length>0)try{for(var c=g(this.parameters.warningsFound),p=c.next();!p.done;p=c.next()){var f=p.value;this.commandOutput.warn(f)}}catch(m){r={error:m}}finally{try{p&&!p.done&&(n=c["return"])&&n.call(c)}finally{if(r)throw r.error}}this.readMaster(),this.parameters.autotranslate()&&(this.autoTranslateService=new k(this.parameters.apikey()));var h=[];return this.parameters.languages().forEach(function(t){h.push(a.processLanguage(t))}),u.forkJoin(h).pipe(l.map(function(t){return a.totalRetcode(t)}))},t.prototype.totalRetcode=function(t){for(var e=0;e<t.length;e++)if(0!==t[e])return t[e];return 0},t.prototype.generatedI18nFile=function(t){return this.parameters.generatedI18nFile(t)},t.prototype.generatedNgxTranslateFile=function(t){return this.parameters.generatedNgxTranslateFile(t)},t.prototype.warnings=function(){return this.parameters.warningsFound},t.prototype.readMaster=function(){var t=this;try{this.master=P.fromFile(this.parameters.i18nFormat(),this.parameters.i18nFile(),this.parameters.encoding()),this.master.warnings().forEach(function(e){t.commandOutput.warn(e)});var e=this.master.numberOfTransUnits(),r=this.master.numberOfTransUnitsWithMissingId();this.commandOutput.info("master contains %s trans-units",e),r>0&&this.commandOutput.warn("master contains %s trans-units, but there are %s without id",e,r);var n=this.master.sourceLanguage();n&&n!==this.parameters.defaultLanguage()&&(this.commandOutput.warn('master says to have source-language="%s", should be "%s" (your defaultLanguage)',n,this.parameters.defaultLanguage()),this.master.setSourceLanguage(this.parameters.defaultLanguage()),P.save(this.master,this.parameters.beautifyOutput()),this.commandOutput.warn('changed master source-language="%s" to "%s"',n,this.parameters.defaultLanguage()))}catch(o){if(o instanceof w)return this.commandOutput.error(o.message),u.of(-1);var i=this.parameters.i18nFile(),s=i?a.format('file "%s", ',i):"";throw this.commandOutput.error(s+"oops "+o),o}},t.prototype.processLanguage=function(t){var e=this;this.commandOutput.debug("processing language %s",t);var r=this.parameters.generatedI18nFile(t),n=r;return(S.exists(r)?this.mergeMasterTo(t,r):this.createUntranslatedXliff(t,r)).pipe(l.map(function(){if(e.parameters.supportNgxTranslate()){var n=P.fromFile(e.translationFormat(e.parameters.i18nFormat()),r,e.parameters.encoding(),e.master.filename());O.extract(n,e.parameters.ngxTranslateExtractionPattern(),e.parameters.generatedNgxTranslateFile(t))}return 0}),l.catchError(function(t){if(t instanceof w)return e.commandOutput.error(t.message),u.of(-1);var r=n?a.format('file "%s", ',n):"";throw e.commandOutput.error(r+"oops "+t),t}))},t.prototype.createUntranslatedXliff=function(t,e){var r=this,n=t===this.parameters.defaultLanguage();this.master.setNewTransUnitTargetPraefix(this.parameters.targetPraefix()),this.master.setNewTransUnitTargetSuffix(this.parameters.targetSuffix());var a=this.master.createTranslationFileForLang(t,e,n,this.parameters.useSourceAsTarget());return this.autoTranslate(this.master.sourceLanguage(),t,a).pipe(l.map(function(){return P.save(a,r.parameters.beautifyOutput()),r.commandOutput.info('created new file "%s" for target-language="%s"',e,t),n||r.commandOutput.warn('please translate file "%s" to target-language="%s"',e,t),null}))},t.prototype.translationFormat=function(t){return t===s.FORMAT_XMB?s.FORMAT_XTB:t},t.prototype.mergeMasterTo=function(t,e){var r=this,n=P.fromFile(this.translationFormat(this.parameters.i18nFormat()),e,this.parameters.encoding()),a=t===this.parameters.defaultLanguage(),i=0,o=0,c=0,p=0,f=0;n.setNewTransUnitTargetPraefix(this.parameters.targetPraefix()),n.setNewTransUnitTargetSuffix(this.parameters.targetSuffix());var h=null;this.master.forEachTransUnit(function(t){var e=n.transUnitWithId(t.id);if(e){if(e.supportsSetSourceContent()&&!r.areSourcesNearlyEqual(t,e)&&(e.setSourceContent(t.sourceContent()),a?(e.translate(t.sourceContent()),e.setTargetState(s.STATE_FINAL)):e.targetState()===s.STATE_FINAL&&e.setTargetState(s.STATE_TRANSLATED),o++),e.supportsSetSourceReferences()&&!r.areSourceReferencesEqual(t.sourceReferences(),e.sourceReferences())&&(e.setSourceReferences(t.sourceReferences()),c++),e.supportsSetDescriptionAndMeaning()){var u=!1;e.description()!==t.description()&&(e.setDescription(t.description()),u=!0),e.meaning()!==t.meaning()&&(e.setMeaning(t.meaning()),u=!0),u&&p++}h=e}else{var l=void 0;r.parameters.allowIdChange()&&(l=r.processChangedIdUnit(t,n,h))?(h=l,f++):(h=n.importNewTransUnit(t,a,r.parameters.useSourceAsTarget(),r.parameters.preserveOrder()?h:undefined),i++)}}),i>0&&this.commandOutput.warn('merged %s trans-units from master to "%s"',i,t),o>0&&this.commandOutput.warn('transferred %s changed source content from master to "%s"',o,t),c>0&&this.commandOutput.warn('transferred %s source references from master to "%s"',c,t),f>0&&this.commandOutput.warn('found %s changed id\'s in "%s"',f,t),p>0&&this.commandOutput.warn('transferred %s changed descriptions/meanings from master to "%s"',p,t);var g=0;return n.forEachTransUnit(function(t){!v(r.master.transUnitWithId(t.id))||(r.parameters.removeUnusedIds()&&n.removeTransUnitWithId(t.id),g++)}),g>0&&(this.parameters.removeUnusedIds()?this.commandOutput.warn('removed %s unused trans-units in "%s"',g,t):this.commandOutput.warn('keeping %s unused trans-units in "%s", because removeUnused is disabled',g,t)),0===i&&0===g&&0===o&&0===c&&0===p?(this.commandOutput.info('file for "%s" was up to date',t),u.of(null)):this.autoTranslate(this.master.sourceLanguage(),t,n).pipe(l.map(function(){return P.save(n,r.parameters.beautifyOutput()),r.commandOutput.info('updated file "%s" for target-language="%s"',e,t),i>0&&!a&&r.commandOutput.warn('please translate file "%s" to target-language="%s"',e,t),null}))},t.prototype.processChangedIdUnit=function(t,e,r){var n=this,a=null;if(e.forEachTransUnit(function(e){n.areSourcesNearlyEqual(e,t)&&(a=e)}),!a)return null;var i=e.importNewTransUnit(t,!1,!1,this.parameters.preserveOrder()?r:undefined),o=a.targetContent();return o&&(i.translate(o),i.setTargetState(s.STATE_TRANSLATED)),i},t.prototype.areSourcesNearlyEqual=function(t,e){if(t&&!e||e&&!t)return!1;var r=t.sourceContentNormalized(),n=e.sourceContentNormalized();return r.isICUMessage()?!!n.isICUMessage()&&r.getICUMessage().asNativeString().trim()===n.getICUMessage().asNativeString().trim():r.containsICUMessageRef()?r.asNativeString().trim()===n.asNativeString().trim():r.asDisplayString(s.NORMALIZATION_FORMAT_DEFAULT).trim()===n.asDisplayString(s.NORMALIZATION_FORMAT_DEFAULT).trim()},t.prototype.areSourceReferencesEqual=function(t,e){if(v(t)&&!v(e)||v(e)&&!v(t))return!1;if(v(t)&&v(e))return!0;var r=new Set;t.forEach(function(t){r.add(t.sourcefile+":"+t.linenumber)});var n=new Set;if(e.forEach(function(t){n.add(t.sourcefile+":"+t.linenumber)}),r.size!==n.size)return!1;var a=!0;return n.forEach(function(t){r.has(t)||(a=!1)}),a},t.prototype.autoTranslate=function(t,e,r){var n=this,a=this.parameters.autotranslateLanguage(e);return(a?this.autoTranslateService.autoTranslate(t,e,r):u.of(new R(t,e))).pipe(l.map(function(t){return a&&(t.error()||t.failed()>0?n.commandOutput.error(t.content()):n.commandOutput.warn(t.content())),t}))},t}();t.CommandOutput=F,t.WriterToString=x,t.XliffMerge=L,t.XliffmergeModule=y,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=ngx-i18nsupport-ngx-i18nsupport.umd.min.js.map