UNPKG

angular-l10n

Version:

An Angular library to translate messages, dates and numbers

110 lines 3.77 kB
/** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ export class DefaultLocale { /** * @return {?} */ get value() { return this.formattedValue; } /** * @param {?} defaultLocale * @return {?} */ set value(defaultLocale) { this.formattedValue = defaultLocale; this.parseValue(); } /** * @param {?} languageCode * @param {?=} countryCode * @param {?=} scriptCode * @param {?=} numberingSystem * @param {?=} calendar * @return {?} */ build(languageCode, countryCode, scriptCode, numberingSystem, calendar) { this.languageCode = languageCode; this.scriptCode = scriptCode; this.countryCode = countryCode; this.numberingSystem = numberingSystem; this.calendar = calendar; /** @type {?} */ let value = languageCode; value += !!scriptCode ? "-" + scriptCode : ""; value += !!countryCode ? "-" + countryCode : ""; // Adds the 'u' (Unicode) extension. value += (!!numberingSystem || !!calendar) ? "-u" : ""; value += !!numberingSystem ? "-nu-" + numberingSystem : ""; value += !!calendar ? "-ca-" + calendar : ""; this.formattedValue = value; } /** * @return {?} */ parseValue() { if (!!this.value) { /** @type {?} */ let value = this.value; // Looks for the 'u' (Unicode) extension. /** @type {?} */ const index = value.search("-u"); if (index != -1) { /** @type {?} */ const extensions = value.substring(index + 1).split("-"); switch (extensions.length) { case 3: if (extensions[1] == "nu") { this.numberingSystem = extensions[2]; this.calendar = undefined; } else if (extensions[1] == "ca") { this.numberingSystem = undefined; this.calendar = extensions[2]; } break; default: this.numberingSystem = extensions[2]; this.calendar = extensions[4]; } // Extracts the codes. value = value.substring(0, index); } /** @type {?} */ const codes = value.split("-"); switch (codes.length) { case 1: this.languageCode = codes[0]; this.scriptCode = undefined; this.countryCode = undefined; break; case 2: this.languageCode = codes[0]; this.scriptCode = undefined; this.countryCode = codes[1]; break; default: this.languageCode = codes[0]; this.scriptCode = codes[1]; this.countryCode = codes[2]; } } } } if (false) { /** @type {?} */ DefaultLocale.prototype.languageCode; /** @type {?} */ DefaultLocale.prototype.scriptCode; /** @type {?} */ DefaultLocale.prototype.countryCode; /** @type {?} */ DefaultLocale.prototype.numberingSystem; /** @type {?} */ DefaultLocale.prototype.calendar; /** @type {?} */ DefaultLocale.prototype.formattedValue; } //# sourceMappingURL=default-locale.js.map