1 | var __extends = (this && this.__extends) || function (d, b) {
|
2 | for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
3 | function __() { this.constructor = d; }
|
4 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
5 | };
|
6 | import { Injectable } from "@angular/core";
|
7 | import { isDefined } from "./util";
|
8 | export var TranslateParser = (function () {
|
9 | function TranslateParser() {
|
10 | }
|
11 | return TranslateParser;
|
12 | }());
|
13 | export var DefaultTranslateParser = (function (_super) {
|
14 | __extends(DefaultTranslateParser, _super);
|
15 | function DefaultTranslateParser() {
|
16 | _super.apply(this, arguments);
|
17 | this.templateMatcher = /{{\s?([^{}\s]*)\s?}}/g;
|
18 | }
|
19 | DefaultTranslateParser.prototype.interpolate = function (expr, params) {
|
20 | var _this = this;
|
21 | if (typeof expr !== 'string' || !params) {
|
22 | return expr;
|
23 | }
|
24 | return expr.replace(this.templateMatcher, function (substring, b) {
|
25 | var r = _this.getValue(params, b);
|
26 | return isDefined(r) ? r : substring;
|
27 | });
|
28 | };
|
29 | DefaultTranslateParser.prototype.getValue = function (target, key) {
|
30 | var keys = key.split('.');
|
31 | key = '';
|
32 | do {
|
33 | key += keys.shift();
|
34 | if (isDefined(target) && isDefined(target[key]) && (typeof target[key] === 'object' || !keys.length)) {
|
35 | target = target[key];
|
36 | key = '';
|
37 | }
|
38 | else if (!keys.length) {
|
39 | target = undefined;
|
40 | }
|
41 | else {
|
42 | key += '.';
|
43 | }
|
44 | } while (keys.length);
|
45 | return target;
|
46 | };
|
47 | DefaultTranslateParser.decorators = [
|
48 | { type: Injectable },
|
49 | ];
|
50 |
|
51 | DefaultTranslateParser.ctorParameters = function () { return []; };
|
52 | return DefaultTranslateParser;
|
53 | }(TranslateParser));
|