UNPKG

@fabioguelfi/angular-translate

Version:

A lightweight internationalization library for Angular applications

66 lines 2.05 kB
/** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ import { Pipe } from '@angular/core'; import { TranslateService } from './translate.service'; import { Subject } from 'rxjs'; import { filter, takeUntil } from 'rxjs/operators'; export class TranslatePipe { /** * @param {?} translateService */ constructor(translateService) { this.translateService = translateService; this.translation = ''; this.unsubscribe = new Subject(); this.translationLoaded$ = translateService.translationsLoaded.pipe(filter(Boolean), takeUntil(this.unsubscribe)); } /** * @param {?} val * @param {?} args * @return {?} */ transform(val, args) { this.translationLoaded$.subscribe(() => { const /** @type {?} */ readValue = val ? this.translateService.read(val, args) : ''; this.translation = readValue === val ? this.translation : readValue; }); return this.translation; } /** * @return {?} */ ngOnDestroy() { this.unsubscribe.next(); this.unsubscribe.complete(); } } TranslatePipe.decorators = [ { type: Pipe, args: [{ name: 'translate', pure: false },] } ]; /** @nocollapse */ TranslatePipe.ctorParameters = () => [ { type: TranslateService, }, ]; function TranslatePipe_tsickle_Closure_declarations() { /** @type {!Array<{type: !Function, args: (undefined|!Array<?>)}>} */ TranslatePipe.decorators; /** * @nocollapse * @type {function(): !Array<(null|{type: ?, decorators: (undefined|!Array<{type: !Function, args: (undefined|!Array<?>)}>)})>} */ TranslatePipe.ctorParameters; /** @type {?} */ TranslatePipe.prototype.translation; /** @type {?} */ TranslatePipe.prototype.translationLoaded$; /** @type {?} */ TranslatePipe.prototype.unsubscribe; /** @type {?} */ TranslatePipe.prototype.translateService; } //# sourceMappingURL=translate.pipe.js.map