@ngneat/transloco
Version:
The internationalization (i18n) library for Angular
2 lines • 26 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("flat"),require("rxjs/operators"),require("@angular/core"),require("rxjs")):"function"==typeof define&&define.amd?define("@ngneat/transloco",["exports","flat","rxjs/operators","@angular/core","rxjs"],t):t((e.ngneat=e.ngneat||{},e.ngneat.transloco={}),e.flat,e.rxjs.operators,e.ng.core,e.rxjs)}(this,function(e,t,f,r,p){"use strict";t=t&&t.hasOwnProperty("default")?t["default"]:t;var i=function(e,t){return(i=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)};var h=function(){return(h=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};function L(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function b(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||0<t--)&&!(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 l=(n.prototype.getTranslation=function(e){return p.of(this.translations.get(e)||{})},n);function n(e){this.translations=e}var a=new r.InjectionToken("TRANSLOCO_LOADER");function c(e,t){return e&&e.hasOwnProperty(t)?e[t]:t.split(".").reduce(function(e,t){return e&&e[t]},e)}function u(e,t,r){e=h({},e);var n=t.split("."),i=n.length-1;return n.reduce(function(e,t,n){return e[t]=n===i?r:Array.isArray(e[t])?e[t].slice():h({},e[t]),e&&e[t]},e),e}function o(e){return e?Array.isArray(e)?e.length:d(e)?Object.keys(e).length:e?e.length:0:0}function m(e){return 0===o(e)}function s(e){return"function"==typeof e}function T(e){return"string"==typeof e}function g(e){return"number"==typeof e}function d(e){return e&&"object"==typeof e&&!Array.isArray(e)}function v(e){return e.replace(/(?:^\w|[A-Z]|\b\w)/g,function(e,t){return 0==t?e.toLowerCase():e.toUpperCase()}).replace(/\s+|_|-|\//g,"")}function y(){return"undefined"!=typeof window}function S(e){return null===e||e===undefined}function O(e){return!1===S(e)}function A(e){return e&&"string"==typeof e.scope}function C(e){return e&&d(e.loader)}function w(e){return t.unflatten(e,{safe:!0})}function j(e){return t(e,{safe:!0})}var R=new r.InjectionToken("TRANSLOCO_CONFIG",{providedIn:"root",factory:function(){return{}}}),I={defaultLang:"en",reRenderOnLangChange:!1,prodMode:!1,failedRetries:2,availableLangs:[],missingHandler:{logMissingKey:!0,useFallbackTranslation:!1,allowEmpty:!1},flatten:{aot:!1},interpolation:["{{","}}"]};function _(e){return void 0===e&&(e=I),h({},I,e)}var M=new r.InjectionToken("TRANSLOCO_TRANSPILER"),k=(N.prototype.transpile=function(e,n,r){var i=this;return void 0===n&&(n={}),T(e)?e.replace(this.interpolationMatcher,function(e,t){return t=t.trim(),O(n[t])?n[t]:O(r[t])?i.transpile(r[t],n,r):""}):(n&&(d(e)?e=this.handleObject(e,n,r):Array.isArray(e)&&(e=this.handleArray(e,n,r))),e)},N.prototype.handleObject=function(e,i,a){var o=this;void 0===i&&(i={});var s=e;return Object.keys(i).forEach(function(e){var t=c(s,e),n=c(i,e),r=o.transpile(t,n,a);s=u(s,e,r)}),s},N.prototype.handleArray=function(e,t,n){var r=this;return void 0===t&&(t={}),e.map(function(e){return r.transpile(e,t,n)})},N.ctorParameters=function(){return[{type:undefined,decorators:[{type:r.Optional},{type:r.Inject,args:[R]}]}]},N);function N(e){this.interpolationMatcher=function i(e){var t=b(e&&e.interpolation?e.interpolation:I.interpolation,2),n=t[0],r=t[1];return new RegExp(n+"(.*?)"+r,"g")}(e)}function E(e){for(var t=e?e.split(","):[],n=[],r=0;r<t.length;r++){for(var i=t[r].trim();"\\"===i[i.length-1];)r++,i=i.replace("\\",",")+t[r];n.push(i)}return n}var F,P=(function _e(e,t){function n(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(x,F=k),x.prototype.transpile=function(s,e,t){var l=this;void 0===e&&(e={});var n=s;return T(s)&&(n=s.replace(/\[\[\s*(\w+)\((.*)\)\s*]]/g,function(e,t,n){try{var r=l.injector.get(t);return r.transpile.apply(r,function a(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(b(arguments[t]));return e}(E(n)))}catch(o){var i="There is an error in: '"+s+"'. \n Check that the you used the right syntax in your translation and that the implementation of "+t+" is correct.";throw o.message.includes("NullInjectorError")&&(i="You are using the '"+t+"' function in your translation but no provider was found!"),new Error(i)}})),F.prototype.transpile.call(this,n,e,t)},x.decorators=[{type:r.Injectable}],x.ctorParameters=function(){return[{type:r.Injector}]},x);function x(e){var t=F.call(this)||this;return t.injector=e,t}var D=new r.InjectionToken("TRANSLOCO_MISSING_HANDLER"),V=(H.prototype.handle=function(e,t){if(t.missingHandler.logMissingKey&&!t.prodMode){var n="Missing translation for '"+e+"'";console.warn("%c "+n,"font-size: 12px; color: red")}return e},H);function H(){}var K=new r.InjectionToken("TRANSLOCO_INTERCEPTOR"),B=(G.prototype.preSaveTranslation=function(e,t){return e},G.prototype.preSaveTranslationKey=function(e,t,n){return t},G);function G(){}var $,z=new r.InjectionToken("TRANSLOCO_FALLBACK_STRATEGY"),J=(W.prototype.getNextLangs=function(e){var t=this.userConfig.fallbackLang;if(!t)throw new Error("When using the default fallback, a fallback language must be provided in the config!");return Array.isArray(t)?t:[t]},W.ctorParameters=function(){return[{type:undefined,decorators:[{type:r.Inject,args:[R]}]}]},W);function W(e){this.userConfig=e}function Y(e){if(!e)return"";var t=e.split("/");return t.pop(),t.join("/")}function q(e){return e?e.split("/").pop():""}function Z(e,t,n){if(void 0===n&&(n="|"),T(e)){var r=e.split(n),i=r.pop();return i===t?[!0,r.toString()]:[!1,i]}return[!1,""]}function U(e,t){return!1===b(Z(t,"static"),1)[0]&&e.config.reRenderOnLangChange}function Q(e){return e?function(e){return e}:f.take(1)}function X(e,t){return C(e)?function i(n,r){return Object.keys(n).reduce(function(e,t){return e[r+"/"+t]=n[t],e},{})}(e.loader,t):null}function ee(e){return{scope:Y(e)||null,langName:q(e),lang:e}}function te(e,t,n,r){if(n){if(!1===s(n[e]))throw"You're using an inline loader but didn't provide a loader for "+e;return n[e]().then(function(e){return e["default"]?e["default"]:e})}return t.getTranslation(e,r)}var ne=(Object.defineProperty(re.prototype,"config",{get:function(){return this.mergedConfig},enumerable:!0,configurable:!0}),re.prototype.getDefaultLang=function(){return this.defaultLang},re.prototype.setDefaultLang=function(e){this.defaultLang=e},re.prototype.getActiveLang=function(){return this.lang.getValue()},re.prototype.setActiveLang=function(e){return this.parser.onLangChanged&&this.parser.onLangChanged(e),this.lang.next(e),this},re.prototype.setAvailableLangs=function(e){this.availableLangs=e},re.prototype.getAvailableLangs=function(){return this.availableLangs},re.prototype.load=function(t,e){var n=this;if(void 0===e&&(e={}),!1===this.cache.has(t)){var r=void 0,i=this._isLangScoped(t),a=i?Y(t):null;if(this.useFallbackTranslation(t)){var o=i?a+"/"+this.firstFallbackLang:this.firstFallbackLang,s=function u(e,t,n,r,i){return[e,t].map(function(t){var e=te(t,n,r,i);return p.from(e).pipe(f.map(function(e){return{translation:e,lang:t}}))})}(t,o,this.loader,e.inlineLoader,{scope:a});r=p.forkJoin(s)}else{var l=te(t,this.loader,e.inlineLoader,{scope:a});r=p.from(l)}var c=r.pipe(f.retry(this.config.failedRetries),f.tap(function(e){Array.isArray(e)?e.forEach(function(e){n.handleSuccess(e.lang,e.translation),e.lang!==t&&n.cache.set(e.lang,p.of({}))}):n.handleSuccess(t,e)}),f.catchError(function(){return n.handleFailure(t,e)}),f.shareReplay(1));this.cache.set(t,c)}return this.cache.get(t)},re.prototype.translate=function(e,t,n){var r=this;if(void 0===t&&(t={}),void 0===n&&(n=this.getActiveLang()),!e)return e;var i=this.resolveLangAndScope(n),a=i.scope,o=i.resolveLang;if(Array.isArray(e))return e.map(function(e){return r.translate(a?a+"."+e:e,t,o)});e=a?a+"."+e:e;var s=this.getTranslation(o),l=s[e];return l?this.parser.transpile(l,t,s):this._handleMissingKey(e,l,t)},re.prototype.selectTranslate=function(n,r,e,i){var a=this;void 0===i&&(i=!1);var t=null,o=function(e,t){return a.load(e,t).pipe(f.map(function(){return i?a.translateObject(n,r,e):a.translate(n,r,e)}))};if(S(e))return this.langChanges$.pipe(f.switchMap(function(e){return o(e)}));if(A(e)){var s=e;e=s.scope,t=X(s,s.scope)}if(e=e,this.isLang(e)||this.isScopeWithLang(e))return o(e);var l=e;return this.langChanges$.pipe(f.switchMap(function(e){return o(l+"/"+e,{inlineLoader:t})}))},re.prototype.isScopeWithLang=function(e){return this.isLang(q(e))},re.prototype.translateObject=function(e,t,n){var r,i,a=this;if(void 0===n&&(n=this.getActiveLang()),T(e)||Array.isArray(e)){if(Array.isArray(e))return e.map(function(e){return a.translateObject(l?l+"."+e:e,t,s)});var o=this.resolveLangAndScope(n),s=o.resolveLang,l=o.scope,c=this.getTranslation(s);e=l?l+"."+e:e;var u=w(this.getObjectByKey(c,e));return m(u)?this.translate(e,t,n):this.parser.transpile(u,t,c)}var p=[];try{for(var h=L(this.getEntries(e)),f=h.next();!f.done;f=h.next()){var g=b(f.value,2),d=g[0],v=g[1];p.push(this.translateObject(d,v,n))}}catch(y){r={error:y}}finally{try{f&&!f.done&&(i=h["return"])&&i.call(h)}finally{if(r)throw r.error}}return p},re.prototype.selectTranslateObject=function(e,t,u){var p=this;if(T(e)||Array.isArray(e))return this.selectTranslate(e,t,u,!0);var n=b(this.getEntries(e)),r=b(n[0],2),i=r[0],a=r[1],h=n.slice(1);return this.selectTranslateObject(i,a,u).pipe(f.map(function(e){var t,n,r=[e];try{for(var i=L(h),a=i.next();!a.done;a=i.next()){var o=b(a.value,2),s=o[0],l=o[1];r.push(p.translateObject(s,l,u))}}catch(c){t={error:c}}finally{try{a&&!a.done&&(n=i["return"])&&n.call(i)}finally{if(t)throw t.error}}return r}))},re.prototype.getTranslation=function(e){if(e){if(this.isLang(e))return this.translations.get(e)||{};var t=this.resolveLangAndScope(e),n=t.scope,r=t.resolveLang,i=this.translations.get(r)||{};return this.getObjectByKey(i,n)}return this.translations},re.prototype.selectTranslation=function(t){var n=this,e=this.langChanges$;if(t){var r=q(t)!==t;e=this.isLang(t)||r?p.of(t):this.langChanges$.pipe(f.map(function(e){return t+"/"+e}))}return e.pipe(f.switchMap(function(e){return n.load(e).pipe(f.map(function(){return n.getTranslation(e)}))}))},re.prototype.setTranslation=function(e,t,n){var r;void 0===t&&(t=this.getActiveLang()),void 0===n&&(n={});var i=h({},{merge:!0,emitChange:!0},n),a=Y(t),o=e;a&&(o=j(((r={})[this.getMappedScope(a)]=e,r)));var s=a?q(t):t,l=h({},i.merge&&this.getTranslation(s),o),c=this.mergedConfig.flatten.aot?l:j(l),u=this.interceptor.preSaveTranslation(c,s);this.translations.set(s,u),i.emitChange&&this.setActiveLang(this.getActiveLang())},re.prototype.setTranslationKey=function(e,t,n,r){var i;void 0===n&&(n=this.getActiveLang()),void 0===r&&(r={});var a=this.interceptor.preSaveTranslationKey(e,t,n),o=((i={})[e]=a,i);this.setTranslation(o,n,h({},r,{merge:!0}))},re.prototype.setFallbackLangForMissingTranslation=function(e){var t=e.fallbackLang,n=Array.isArray(t)?t[0]:t;this.useFallbackTranslation(n)&&t&&(this.firstFallbackLang=n)},re.prototype._handleMissingKey=function(e,t,n){if(this.config.missingHandler.allowEmpty&&""===t)return"";if(!this.useFallbackTranslation()||this.isResolvedMissingOnce)return this.missingHandler.handle(e,this.getMissingHandlerData(),n);this.isResolvedMissingOnce=!0;var r=this.translate(e,n,this.firstFallbackLang);return this.isResolvedMissingOnce=!1,r},re.prototype._isLangScoped=function(e){return-1===this.getAvailableLangsIds().indexOf(e)},re.prototype.isLang=function(e){return-1!==this.getAvailableLangsIds().indexOf(e)},re.prototype._loadDependencies=function(e,t){var n=q(e);return this._isLangScoped(e)&&!this.isLoadedTranslation(n)?p.combineLatest(this.load(n),this.load(e,{inlineLoader:t})):this.load(e,{inlineLoader:t})},re.prototype._completeScopeWithLang=function(e){return this._isLangScoped(e)&&!this.isLang(q(e))?e+"/"+this.getActiveLang():e},re.prototype._setScopeAlias=function(e,t){this.mergedConfig.scopeMapping||(this.mergedConfig.scopeMapping={}),this.mergedConfig.scopeMapping[e]=t},re.prototype.ngOnDestroy=function(){this.subscription.unsubscribe(),this.cache.clear()},re.prototype.isLoadedTranslation=function(e){return o(this.getTranslation(e))},re.prototype.getAvailableLangsIds=function(){return T(this.getAvailableLangs()[0])?this.getAvailableLangs():this.getAvailableLangs().map(function(e){return e.id})},re.prototype.getMissingHandlerData=function(){return h({},this.config,{activeLang:this.getActiveLang(),availableLangs:this.availableLangs,defaultLang:this.defaultLang})},re.prototype.useFallbackTranslation=function(e){return this.config.missingHandler.useFallbackTranslation&&e!==this.firstFallbackLang},re.prototype.handleSuccess=function(e,t){var n=this;this.setTranslation(t,e,{emitChange:!1}),this.events.next({wasFailure:!!this.failedLangs.size,type:"translationLoadSuccess",payload:ee(e)}),this.failedLangs.forEach(function(e){return n.cache["delete"](e)}),this.failedLangs.clear()},re.prototype.handleFailure=function(e,t){S(t.failedCounter)&&(t.failedCounter=0,t.fallbackLangs||(t.fallbackLangs=this.fallbackStrategy.getNextLangs(e)));var n=e.split("/"),r=t.fallbackLangs[t.failedCounter];if(this.failedLangs.add(e),this.cache.has(r))return this.handleSuccess(r,this.getTranslation(r)),p.EMPTY;var i=r===n[n.length-1];if(!r||i){var a="Unable to load translation and all the fallback languages";throw 1<n.length&&(a+=", did you misspelled the scope name?"),new Error(a)}var o=r;return 1<n.length&&(n[n.length-1]=r,o=n.join("/")),t.failedCounter++,this.events.next({type:"translationLoadFailure",payload:ee(e)}),this.load(o,t)},re.prototype.getMappedScope=function(e){var t=this.config.scopeMapping;return(void 0===t?{}:t)[e]||v(e)},re.prototype.resolveLangAndScope=function(e){var t,n=e;if(this._isLangScoped(e)){var r=q(e),i=this.isLang(r);n=i?r:this.getActiveLang(),t=this.getMappedScope(i?Y(e):e)}return{scope:t,resolveLang:n}},re.prototype.getObjectByKey=function(e,t){var n={},r=t+".";for(var i in e)i.startsWith(r)&&(n[i.replace(r,"")]=e[i]);return n},re.prototype.getEntries=function(e){return e instanceof Map?e.entries():Object.entries(e)},re.decorators=[{type:r.Injectable,args:[{providedIn:"root"}]}],re.ctorParameters=function(){return[{type:undefined,decorators:[{type:r.Optional},{type:r.Inject,args:[a]}]},{type:undefined,decorators:[{type:r.Inject,args:[M]}]},{type:undefined,decorators:[{type:r.Inject,args:[D]}]},{type:undefined,decorators:[{type:r.Inject,args:[K]}]},{type:undefined,decorators:[{type:r.Inject,args:[R]}]},{type:undefined,decorators:[{type:r.Inject,args:[z]}]}]},re.ngInjectableDef=r.defineInjectable({factory:function(){return new re(r.inject(a,8),r.inject(M),r.inject(D),r.inject(K),r.inject(R),r.inject(z))},token:re,providedIn:"root"}),re);function re(e,t,n,r,i,a){var o=this;this.loader=e,this.parser=t,this.missingHandler=n,this.interceptor=r,this.userConfig=i,this.fallbackStrategy=a,this.translations=new Map,this.cache=new Map,this.firstFallbackLang=null,this.availableLangs=[],this.isResolvedMissingOnce=!1,this.events=new p.Subject,this.events$=this.events.asObservable(),this.failedLangs=new Set,this.loader||(this.loader=new l(this.translations)),($=this).mergedConfig=function s(e,t){return h({},e,t,{missingHandler:h({},e.missingHandler,t.missingHandler),flatten:h({},e.flatten,t.flatten)})}(I,i),this.setAvailableLangs(this.mergedConfig.availableLangs),this.setFallbackLangForMissingTranslation(this.mergedConfig),this.setDefaultLang(this.mergedConfig.defaultLang),this.lang=new p.BehaviorSubject(this.getDefaultLang()),this.langChanges$=this.lang.asObservable(),this.subscription=this.events$.subscribe(function(e){if("translationLoadSuccess"===e.type&&e.wasFailure){var t=q(e.payload.lang);o.setActiveLang(t)}})}var ie=(ae.decorators=[{type:r.Component,args:[{template:'\n <div class="transloco-loader-template" [innerHTML]="html"></div>\n '}]}],ae.propDecorators={html:[{type:r.Input}]},ae);function ae(){}var oe=(se.prototype.attachView=function(){if(this.view instanceof r.TemplateRef)this.vcr.createEmbeddedView(this.view);else if(T(this.view)){var e=this.createComponent(ie);e.instance.html=this.view,e.hostView.detectChanges()}else this.createComponent(this.view)},se.prototype.detachView=function(){this.vcr.clear()},se.prototype.createComponent=function(e){var t=this.injector.get(r.ComponentFactoryResolver).resolveComponentFactory(e);return this.vcr.createComponent(t)},se);function se(e,t){this.view=e,this.vcr=t,this.injector=this.vcr.injector}var le=new r.InjectionToken("TRANSLOCO_LANG"),ce=new r.InjectionToken("TRANSLOCO_LOADING_TEMPLATE"),ue=new r.InjectionToken("TRANSLOCO_SCOPE"),pe=(he.prototype.resolve=function(e){var t=void 0===e?{inline:undefined,provider:undefined,active:undefined}:e,n=t.inline,r=t.provider,i=t.active,a=i;if(this.initialized)return a=i;if(r){var o=b(Z(r,"static"),2);o[0],a=o[1]}if(n){var s=b(Z(n,"static"),2);s[0],a=s[1]}return this.initialized=!0,a},he.prototype.resolveLangBasedOnScope=function(e){return Y(e)?q(e):e},he.prototype.resolveLangPath=function(e,t){return t?t+"/"+e:e},he);function he(){this.initialized=!1}var fe=(ge.prototype.resolve=function(e){var t=void 0===e?{inline:undefined,provider:undefined}:e,n=t.inline,r=t.provider;if(n)return n;if(r){if(A(r)){var i=r.scope,a=r.alias,o=void 0===a?v(i):a;return this.translocoService._setScopeAlias(i,o),i}return r}return undefined},ge);function ge(e){this.translocoService=e}var de=(ve.prototype.ngOnInit=function(){var n=this,e=U(this.translocoService,this.providerLang||this.inlineLang);this.subscription=this.translocoService.langChanges$.pipe(f.switchMap(function(e){var t=n.langResolver.resolve({inline:n.inlineLang,provider:n.providerLang,active:e});return Array.isArray(n.providerScope)?p.forkJoin(n.providerScope.map(function(e){return n.resolveScope(t,e)})):n.resolveScope(t,n.providerScope)}),Q(e)).subscribe(function(){n.currentLang=n.langResolver.resolveLangBasedOnScope(n.path),null===n.tpl?n.simpleStrategy():n.structuralStrategy(n.currentLang,n.inlineRead),n.cdr.markForCheck(),n.initialized=!0});var t=this.getLoadingTpl();!this.initialized&&t&&(this.loaderTplHandler=new oe(t,this.vcr),this.loaderTplHandler.attachView())},ve.prototype.ngOnChanges=function(t){Object.keys(t).some(function(e){return!1===t[e].firstChange})&&this.simpleStrategy()},ve.prototype.simpleStrategy=function(){this.detachLoader(),this.host.nativeElement.innerText=this.translocoService.translate(this.key,this.params,this.currentLang)},ve.prototype.structuralStrategy=function(e,t){this.translationMemo={},this.view?(this.view.context.$implicit=this.getTranslateFn(e,t),this.view.context.currentLang=this.currentLang):(this.detachLoader(),this.view=this.vcr.createEmbeddedView(this.tpl,{$implicit:this.getTranslateFn(e,t),currentLang:this.currentLang}))},ve.prototype.getTranslateFn=function(i,a){var o=this;return function(e,t){var n=a?a+"."+e:e,r=t?""+n+JSON.stringify(t):n;return o.translationMemo.hasOwnProperty(r)||(o.translationMemo[r]={params:t,value:o.translocoService.translate(n,t,i)}),o.translationMemo[r].value}},ve.prototype.getLoadingTpl=function(){return this.inlineTpl||this.providedLoadingTpl},ve.prototype.ngOnDestroy=function(){this.subscription&&this.subscription.unsubscribe()},ve.prototype.detachLoader=function(){this.loaderTplHandler&&this.loaderTplHandler.detachView()},ve.prototype.resolveScope=function(e,t){var n=this.scopeResolver.resolve({inline:this.inlineScope,provider:t});this.path=this.langResolver.resolveLangPath(e,n);var r=X(t,n);return this.translocoService._loadDependencies(this.path,r)},ve.decorators=[{type:r.Directive,args:[{selector:"[transloco]"}]}],ve.ctorParameters=function(){return[{type:ne},{type:r.TemplateRef,decorators:[{type:r.Optional}]},{type:undefined,decorators:[{type:r.Optional},{type:r.Inject,args:[ue]}]},{type:undefined,decorators:[{type:r.Optional},{type:r.Inject,args:[le]}]},{type:undefined,decorators:[{type:r.Optional},{type:r.Inject,args:[ce]}]},{type:r.ViewContainerRef},{type:r.ChangeDetectorRef},{type:r.ElementRef}]},ve.propDecorators={key:[{type:r.Input,args:["transloco"]}],params:[{type:r.Input,args:["translocoParams"]}],inlineScope:[{type:r.Input,args:["translocoScope"]}],inlineRead:[{type:r.Input,args:["translocoRead"]}],inlineLang:[{type:r.Input,args:["translocoLang"]}],inlineTpl:[{type:r.Input,args:["translocoLoadingTpl"]}]},ve);function ve(e,t,n,r,i,a,o,s){this.translocoService=e,this.tpl=t,this.providerScope=n,this.providerLang=r,this.providedLoadingTpl=i,this.vcr=a,this.cdr=o,this.host=s,this.translationMemo={},this.params={},this.loaderTplHandler=null,this.initialized=!1,this.langResolver=new pe,this.scopeResolver=new fe(this.translocoService)}var ye=(Le.prototype.transform=function(e,t,n){var r=this;if(!e)return e;var i=t?""+e+JSON.stringify(t):e;return i===this.lastKey||(this.lastKey=i,this.subscription&&this.subscription.unsubscribe(),this.subscription=this.translocoService.langChanges$.pipe(f.switchMap(function(e){var t=r.langResolver.resolve({inline:n,provider:r.providerLang,active:e});return Array.isArray(r.providerScope)?p.forkJoin(r.providerScope.map(function(e){return r.resolveScope(t,e)})):r.resolveScope(t,r.providerScope)}),Q(this.listenToLangChange)).subscribe(function(){return r.updateValue(e,t)})),this.lastValue},Le.prototype.ngOnDestroy=function(){this.subscription&&this.subscription.unsubscribe()},Le.prototype.updateValue=function(e,t){var n=this.langResolver.resolveLangBasedOnScope(this.path);this.lastValue=this.translocoService.translate(e,t,n),this.cdr.markForCheck()},Le.prototype.resolveScope=function(e,t){var n=this.scopeResolver.resolve({inline:undefined,provider:t});this.path=this.langResolver.resolveLangPath(e,n);var r=X(t,n);return this.translocoService._loadDependencies(this.path,r)},Le.decorators=[{type:r.Pipe,args:[{name:"transloco",pure:!1}]}],Le.ctorParameters=function(){return[{type:ne},{type:undefined,decorators:[{type:r.Optional},{type:r.Inject,args:[ue]}]},{type:undefined,decorators:[{type:r.Optional},{type:r.Inject,args:[le]}]},{type:r.ChangeDetectorRef}]},Le);function Le(e,t,n,r){this.translocoService=e,this.providerScope=t,this.providerLang=n,this.cdr=r,this.subscription=null,this.lastValue="",this.langResolver=new pe,this.scopeResolver=new fe(this.translocoService),this.listenToLangChange=U(this.translocoService,this.providerLang)}var be=[{provide:M,useClass:k,deps:[R]},{provide:D,useClass:V},{provide:K,useClass:B},{provide:z,useClass:J,deps:[R]}],me=(Te.decorators=[{type:r.NgModule,args:[{declarations:[de,ye,ie],providers:[be],exports:[de,ye],entryComponents:[ie]}]}],Te);function Te(){}var Se=new r.InjectionToken("TRANSLOCO_TEST_LANGS - Available testing languages"),Oe=new r.InjectionToken("TRANSLOCO_TEST_OPTIONS - Testing options"),Ae=(Ce.prototype.getTranslation=function(e){return p.of(this.langs[e])},Ce.decorators=[{type:r.Injectable}],Ce.ctorParameters=function(){return[{type:undefined,decorators:[{type:r.Inject,args:[Se]}]}]},Ce);function Ce(e){this.langs=e}function we(t,e,n){void 0===e&&(e={});return function(){return n.preloadLangs?Promise.all(Object.keys(e).map(function(e){return t.load(e).toPromise()})):Promise.resolve()}}var je=(Re.forRoot=function(e){return{ngModule:Re,providers:[{provide:Se,useValue:e.langs},{provide:Oe,useValue:e},{provide:r.APP_INITIALIZER,useFactory:we,deps:[ne,Se,Oe],multi:!0},{provide:a,useClass:Ae},be,{provide:R,useValue:_(h({prodMode:!0,missingHandler:{logMissingKey:!1}},e.translocoConfig))}]}},Re.withLangs=function(e,t,n){return void 0===t&&(t={}),void 0===n&&(n={}),{ngModule:Re,providers:[{provide:Se,useValue:e},{provide:Oe,useValue:n},{provide:r.APP_INITIALIZER,useFactory:we,deps:[ne,Se,Oe],multi:!0},{provide:a,useClass:Ae},be,{provide:R,useValue:_(h({prodMode:!0,missingHandler:{logMissingKey:!1}},t))}]}},Re.decorators=[{type:r.NgModule,args:[{exports:[me]}]}],Re);function Re(){}function Ie(){if(!1===y())return undefined;var e=window.navigator,t=e.languages?e.languages[0]:null;return t=t||e.language||e.browserLanguage||e.userLanguage}e.translate=function Me(e,t,n){return void 0===t&&(t={}),$.translate(e,t,n)},e.TranslocoService=ne,e.TranslocoDirective=de,e.TranslocoPipe=ye,e.TranslocoModule=me,e.defaultProviders=be,e.TRANSLOCO_LOADER=a,e.TRANSLOCO_CONFIG=R,e.defaultConfig=I,e.provideTranslocoConfig=function ke(e){return void 0===e&&(e=I),{provide:R,useValue:h({},I,e)}},e.translocoConfig=_,e.TRANSLOCO_TRANSPILER=M,e.DefaultTranspiler=k,e.FunctionalTranspiler=P,e.getFunctionArgs=E,e.TRANSLOCO_SCOPE=ue,e.TRANSLOCO_LOADING_TEMPLATE=ce,e.TRANSLOCO_LANG=le,e.TestingLoader=Ae,e.TranslocoTestingModule=je,e.TemplateHandler=oe,e.TRANSLOCO_INTERCEPTOR=K,e.TRANSLOCO_FALLBACK_STRATEGY=z,e.DefaultFallbackStrategy=J,e.TRANSLOCO_MISSING_HANDLER=D,e.getBrowserCultureLang=Ie,e.getBrowserLang=function Ne(){var e=Ie();return!1!==y()&&e?(-1!==e.indexOf("-")&&(e=e.split("-")[0]),-1!==e.indexOf("_")&&(e=e.split("_")[0]),e):undefined},e.getPipeValue=Z,e.getLangFromScope=q,e.getScopeFromLang=Y,e.getValue=c,e.setValue=u,e.size=o,e.isEmpty=m,e.isFunction=s,e.isString=T,e.isNumber=g,e.isObject=d,e.coerceArray=function Ee(e){return Array.isArray(e)?e:[e]},e.toCamelCase=v,e.isBrowser=y,e.isNil=S,e.isDefined=O,e.toNumber=function Fe(e){return g(e)?e:T(e)&&!isNaN(Number(e)-parseFloat(e))?Number(e):null},e.isScopeObject=A,e.hasInlineLoader=C,e.unflatten=w,e.flatten=j,e.ɵd=ie,e.ɵc=V,e.ɵa=we,e.ɵb=B,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=ngneat-transloco.umd.min.js.map