angular-l10n
Version:
An Angular library to translate messages, dates and numbers
104 lines • 3.4 kB
JavaScript
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
import { Injectable, ChangeDetectorRef } from '@angular/core';
import { LocaleService } from './locale.service';
import { TranslationService } from './translation.service';
import { InjectorRef } from '../models/injector-ref';
import { takeUntilDestroyed } from '../models/take-until-destroyed';
/**
* Provides 'lang' to translate pipe.
*/
export class Translation {
/**
* @param {?=} changeDetectorRef
*/
constructor(changeDetectorRef) {
this.changeDetectorRef = changeDetectorRef;
this.lang = '';
/** @type {?} */
const translation = InjectorRef.get(TranslationService);
translation.latestTranslation().pipe(takeUntilDestroyed(this)).subscribe((language) => {
this.lang = language;
// OnPush Change Detection strategy.
if (this.changeDetectorRef) {
this.changeDetectorRef.markForCheck();
}
});
}
/**
* @return {?}
*/
ngOnDestroy() { }
}
Translation.decorators = [
{ type: Injectable }
];
/** @nocollapse */
Translation.ctorParameters = () => [
{ type: ChangeDetectorRef }
];
if (false) {
/** @type {?} */
Translation.prototype.lang;
/** @type {?} */
Translation.prototype.changeDetectorRef;
}
/**
* Provides 'lang' to translate pipe,
* 'defaultLocale', 'currency', 'timezone' to l10nDate, l10nDecimal, l10nPercent & l10nCurrency pipes.
*/
export class Localization extends Translation {
/**
* @param {?=} changeDetectorRef
*/
constructor(changeDetectorRef) {
super();
this.changeDetectorRef = changeDetectorRef;
this.defaultLocale = '';
this.currency = '';
this.timezone = '';
/** @type {?} */
const locale = InjectorRef.get(LocaleService);
this.defaultLocale = locale.getDefaultLocale();
locale.defaultLocaleChanged.pipe(takeUntilDestroyed(this)).subscribe((defaultLocale) => {
this.defaultLocale = defaultLocale;
if (this.changeDetectorRef) {
this.changeDetectorRef.markForCheck();
}
});
this.currency = locale.getCurrentCurrency();
locale.currencyCodeChanged.pipe(takeUntilDestroyed(this)).subscribe((currency) => {
this.currency = currency;
if (this.changeDetectorRef) {
this.changeDetectorRef.markForCheck();
}
});
this.timezone = locale.getCurrentTimezone();
locale.timezoneChanged.pipe(takeUntilDestroyed(this)).subscribe((zoneName) => {
this.timezone = zoneName;
if (this.changeDetectorRef) {
this.changeDetectorRef.markForCheck();
}
});
}
}
Localization.decorators = [
{ type: Injectable }
];
/** @nocollapse */
Localization.ctorParameters = () => [
{ type: ChangeDetectorRef }
];
if (false) {
/** @type {?} */
Localization.prototype.defaultLocale;
/** @type {?} */
Localization.prototype.currency;
/** @type {?} */
Localization.prototype.timezone;
/** @type {?} */
Localization.prototype.changeDetectorRef;
}
//# sourceMappingURL=extensions.js.map