angular-l10n
Version:
An Angular library to translate messages, dates and numbers
109 lines • 3.82 kB
JavaScript
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
import * as tslib_1 from "tslib";
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.
*/
var Translation = /** @class */ (function () {
function Translation(changeDetectorRef) {
var _this = this;
this.changeDetectorRef = changeDetectorRef;
this.lang = '';
/** @type {?} */
var translation = InjectorRef.get(TranslationService);
translation.latestTranslation().pipe(takeUntilDestroyed(this)).subscribe(function (language) {
_this.lang = language;
// OnPush Change Detection strategy.
if (_this.changeDetectorRef) {
_this.changeDetectorRef.markForCheck();
}
});
}
/**
* @return {?}
*/
Translation.prototype.ngOnDestroy = /**
* @return {?}
*/
function () { };
Translation.decorators = [
{ type: Injectable }
];
/** @nocollapse */
Translation.ctorParameters = function () { return [
{ type: ChangeDetectorRef }
]; };
return Translation;
}());
export { Translation };
if (false) {
/** @type {?} */
Translation.prototype.lang;
/** @type {?} */
Translation.prototype.changeDetectorRef;
}
/**
* Provides 'lang' to translate pipe,
* 'defaultLocale', 'currency', 'timezone' to l10nDate, l10nDecimal, l10nPercent & l10nCurrency pipes.
*/
var Localization = /** @class */ (function (_super) {
tslib_1.__extends(Localization, _super);
function Localization(changeDetectorRef) {
var _this = _super.call(this) || this;
_this.changeDetectorRef = changeDetectorRef;
_this.defaultLocale = '';
_this.currency = '';
_this.timezone = '';
/** @type {?} */
var locale = InjectorRef.get(LocaleService);
_this.defaultLocale = locale.getDefaultLocale();
locale.defaultLocaleChanged.pipe(takeUntilDestroyed(_this)).subscribe(function (defaultLocale) {
_this.defaultLocale = defaultLocale;
if (_this.changeDetectorRef) {
_this.changeDetectorRef.markForCheck();
}
});
_this.currency = locale.getCurrentCurrency();
locale.currencyCodeChanged.pipe(takeUntilDestroyed(_this)).subscribe(function (currency) {
_this.currency = currency;
if (_this.changeDetectorRef) {
_this.changeDetectorRef.markForCheck();
}
});
_this.timezone = locale.getCurrentTimezone();
locale.timezoneChanged.pipe(takeUntilDestroyed(_this)).subscribe(function (zoneName) {
_this.timezone = zoneName;
if (_this.changeDetectorRef) {
_this.changeDetectorRef.markForCheck();
}
});
return _this;
}
Localization.decorators = [
{ type: Injectable }
];
/** @nocollapse */
Localization.ctorParameters = function () { return [
{ type: ChangeDetectorRef }
]; };
return Localization;
}(Translation));
export { Localization };
if (false) {
/** @type {?} */
Localization.prototype.defaultLocale;
/** @type {?} */
Localization.prototype.currency;
/** @type {?} */
Localization.prototype.timezone;
/** @type {?} */
Localization.prototype.changeDetectorRef;
}
//# sourceMappingURL=extensions.js.map