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 { LocaleService } from '../services/locale.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 l10nDate, l10nDecimal, l10nPercent & l10nCurrency pipes. * @return {?} */ export function DefaultLocale() { /** * @param {?} target * @param {?=} propertyKey * @return {?} */ function DecoratorFactory(target, propertyKey) { /** @type {?} */ const targetNgOnInit = target.ngOnInit; if (typeof targetNgOnInit === "undefined") { Logger.log(target.constructor ? target.constructor.name : 'DefaultLocale decorator', 'missingOnInit'); } /** * @this {?} * @return {?} */ function ngOnInit() { /** @type {?} */ const locale = InjectorRef.get(LocaleService); if (typeof propertyKey !== "undefined") { this[propertyKey] = locale.getDefaultLocale(); locale.defaultLocaleChanged.pipe(takeUntilDestroyed(this)).subscribe((defaultLocale) => { this[propertyKey] = defaultLocale; /** @type {?} */ const cdr = Object.keys(this) .find((key) => 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=default-locale.decorator.js.map