UNPKG

angular-l10n

Version:

An Angular library to translate messages, dates and numbers

59 lines 2.17 kB
/** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ import { TranslationService } from '../services/translation.service'; import { InjectorRef } from '../models/injector-ref'; import { takeUntilDestroyed } from '../models/take-until-destroyed'; import { Logger } from '../models/logger'; /** * Property decorator for components to provide the parameter to translate pipe. * @return {?} */ export function Language() { /** * @param {?} target * @param {?=} propertyKey * @return {?} */ function DecoratorFactory(target, propertyKey) { /** @type {?} */ var targetNgOnInit = target.ngOnInit; if (typeof targetNgOnInit === "undefined") { Logger.log(target.constructor ? target.constructor.name : 'Language decorator', 'missingOnInit'); } /** * @this {?} * @return {?} */ function ngOnInit() { var _this = this; /** @type {?} */ var translation = InjectorRef.get(TranslationService); if (typeof propertyKey !== "undefined") { translation.latestTranslation().pipe(takeUntilDestroyed(this)).subscribe(function (language) { _this[propertyKey] = language; // OnPush Change Detection strategy. /** @type {?} */ var cdr = Object.keys(_this) .find(function (key) { return _this[key] && _this[key]['markForCheck'] !== undefined; }); if (cdr) { _this[cdr].markForCheck(); } }); } if (targetNgOnInit) { targetNgOnInit.apply(this); } } target.ngOnInit = ngOnInit; if (typeof propertyKey !== "undefined") { Object.defineProperty(target, propertyKey, { writable: true, value: '' }); } } return DecoratorFactory; } //# sourceMappingURL=language.decorator.js.map