UNPKG

angular-l10n

Version:

An Angular library to translate messages, dates and numbers

112 lines 3.53 kB
/** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ import { Injectable, Inject } from '@angular/core'; import { L10N_CONFIG } from "../models/l10n-config"; /** * Implement this class-interface to create a custom handler for translated values. * @abstract */ var TranslationHandler = /** @class */ (function () { function TranslationHandler() { } TranslationHandler.decorators = [ { type: Injectable } ]; return TranslationHandler; }()); export { TranslationHandler }; if (false) { /** * This method must contain the logic to parse the translated value. * @abstract * @param {?} path The path of the key * @param {?} key The key that has been requested * @param {?} value The translated value * @param {?} args The parameters passed along with the key * @param {?} lang The current language * @return {?} The parsed value */ TranslationHandler.prototype.parseValue = function (path, key, value, args, lang) { }; } var L10nTranslationHandler = /** @class */ (function () { function L10nTranslationHandler(configuration) { this.configuration = configuration; } /** * @param {?} path * @param {?} key * @param {?} value * @param {?} args * @param {?} lang * @return {?} */ L10nTranslationHandler.prototype.parseValue = /** * @param {?} path * @param {?} key * @param {?} value * @param {?} args * @param {?} lang * @return {?} */ function (path, key, value, args, lang) { if (value == null) { return this.handleMissingValue(path); } else if (args) { return this.handleArgs(value, args); } return value; }; /** * @param {?} path * @return {?} */ L10nTranslationHandler.prototype.handleMissingValue = /** * @param {?} path * @return {?} */ function (path) { if (this.configuration.translation.missingValue != null) { return typeof this.configuration.translation.missingValue === "function" ? this.configuration.translation.missingValue(path) : this.configuration.translation.missingValue; } // The same path is returned. return path; }; /** * @param {?} value * @param {?} args * @return {?} */ L10nTranslationHandler.prototype.handleArgs = /** * @param {?} value * @param {?} args * @return {?} */ function (value, args) { /** @type {?} */ var TEMPLATE_REGEXP = /{{\s?([^{}\s]*)\s?}}/g; return value.replace(TEMPLATE_REGEXP, function (substring, parsedKey) { /** @type {?} */ var replacer = (/** @type {?} */ (args[parsedKey])); return typeof replacer !== "undefined" ? replacer : substring; }); }; L10nTranslationHandler.decorators = [ { type: Injectable } ]; /** @nocollapse */ L10nTranslationHandler.ctorParameters = function () { return [ { type: undefined, decorators: [{ type: Inject, args: [L10N_CONFIG,] }] } ]; }; return L10nTranslationHandler; }()); export { L10nTranslationHandler }; if (false) { /** @type {?} */ L10nTranslationHandler.prototype.configuration; } //# sourceMappingURL=translation-handler.js.map