UNPKG

angular-l10n

Version:

An Angular library to translate messages, dates and numbers

94 lines 2.46 kB
/** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ import { Directive, ElementRef, Input, Renderer2 } from '@angular/core'; import { takeUntil } from 'rxjs/operators'; import { LocaleService } from '../services/locale.service'; import { BaseDirective } from '../models/base-directive'; export class L10nTimeAgoDirective extends BaseDirective { /** * @param {?} locale * @param {?} el * @param {?} renderer */ constructor(locale, el, renderer) { super(el, renderer); this.locale = locale; this.el = el; this.renderer = renderer; } /** * @param {?} format * @return {?} */ set l10nTimeAgo(format) { this.format = format; } /** * @return {?} */ setup() { this.replace(); this.locale.defaultLocaleChanged.pipe(takeUntil(this.destroy)).subscribe(() => { this.replace(); }); } /** * @return {?} */ replace() { this.replaceText(); this.replaceAttributes(); } /** * @return {?} */ replaceText() { if (!!this.key) { this.setText(this.getValue(this.key)); } } /** * @return {?} */ replaceAttributes() { if (this.attributes.length > 0) { this.setAttributes(this.getAttributesData()); } } /** * @param {?} key * @return {?} */ getValue(key) { return this.locale.formatRelativeTime(key, this.unit, this.format); } } L10nTimeAgoDirective.decorators = [ { type: Directive, args: [{ selector: '[l10nTimeAgo]' },] } ]; /** @nocollapse */ L10nTimeAgoDirective.ctorParameters = () => [ { type: LocaleService }, { type: ElementRef }, { type: Renderer2 } ]; L10nTimeAgoDirective.propDecorators = { l10nTimeAgo: [{ type: Input }], unit: [{ type: Input }], format: [{ type: Input }] }; if (false) { /** @type {?} */ L10nTimeAgoDirective.prototype.unit; /** @type {?} */ L10nTimeAgoDirective.prototype.format; /** @type {?} */ L10nTimeAgoDirective.prototype.locale; /** @type {?} */ L10nTimeAgoDirective.prototype.el; /** @type {?} */ L10nTimeAgoDirective.prototype.renderer; } //# sourceMappingURL=l10n-time-ago.directive.js.map