UNPKG

angular-l10n

Version:

An Angular library to translate messages, dates and numbers

259 lines 6.51 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 L10nDecimalDirective 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 {?} digits * @return {?} */ set l10nDecimal(digits) { this.digits = digits; } /** * @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.formatDecimal(key, this.digits); } } L10nDecimalDirective.decorators = [ { type: Directive, args: [{ selector: '[l10nDecimal]' },] } ]; /** @nocollapse */ L10nDecimalDirective.ctorParameters = () => [ { type: LocaleService }, { type: ElementRef }, { type: Renderer2 } ]; L10nDecimalDirective.propDecorators = { l10nDecimal: [{ type: Input }], digits: [{ type: Input }] }; if (false) { /** @type {?} */ L10nDecimalDirective.prototype.digits; /** @type {?} */ L10nDecimalDirective.prototype.locale; /** @type {?} */ L10nDecimalDirective.prototype.el; /** @type {?} */ L10nDecimalDirective.prototype.renderer; } export class L10nPercentDirective 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 {?} digits * @return {?} */ set l10nPercent(digits) { this.digits = digits; } /** * @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.formatPercent(key, this.digits); } } L10nPercentDirective.decorators = [ { type: Directive, args: [{ selector: '[l10nPercent]' },] } ]; /** @nocollapse */ L10nPercentDirective.ctorParameters = () => [ { type: LocaleService }, { type: ElementRef }, { type: Renderer2 } ]; L10nPercentDirective.propDecorators = { l10nPercent: [{ type: Input }], digits: [{ type: Input }] }; if (false) { /** @type {?} */ L10nPercentDirective.prototype.digits; /** @type {?} */ L10nPercentDirective.prototype.locale; /** @type {?} */ L10nPercentDirective.prototype.el; /** @type {?} */ L10nPercentDirective.prototype.renderer; } export class L10nCurrencyDirective 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 {?} digits * @return {?} */ set l10nCurrency(digits) { this.digits = digits; } /** * @return {?} */ setup() { this.replace(); this.locale.defaultLocaleChanged.pipe(takeUntil(this.destroy)).subscribe(() => { this.replace(); }); this.locale.currencyCodeChanged.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.formatCurrency(key, this.digits, this.currencyDisplay); } } L10nCurrencyDirective.decorators = [ { type: Directive, args: [{ selector: '[l10nCurrency]' },] } ]; /** @nocollapse */ L10nCurrencyDirective.ctorParameters = () => [ { type: LocaleService }, { type: ElementRef }, { type: Renderer2 } ]; L10nCurrencyDirective.propDecorators = { l10nCurrency: [{ type: Input }], currencyDisplay: [{ type: Input }], digits: [{ type: Input }] }; if (false) { /** @type {?} */ L10nCurrencyDirective.prototype.currencyDisplay; /** @type {?} */ L10nCurrencyDirective.prototype.digits; /** @type {?} */ L10nCurrencyDirective.prototype.locale; /** @type {?} */ L10nCurrencyDirective.prototype.el; /** @type {?} */ L10nCurrencyDirective.prototype.renderer; } //# sourceMappingURL=l10n-number.directive.js.map