1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs'), require('rxjs/operators')) :
|
3 | typeof define === 'function' && define.amd ? define('@ngx-translate/core', ['exports', '@angular/core', 'rxjs', 'rxjs/operators'], factory) :
|
4 | (global = global || self, factory((global['ngx-translate'] = global['ngx-translate'] || {}, global['ngx-translate'].core = {}), global.ng.core, global.rxjs, global.rxjs.operators));
|
5 | }(this, (function (exports, core, rxjs, operators) { 'use strict';
|
6 |
|
7 | /*! *****************************************************************************
|
8 | Copyright (c) Microsoft Corporation. All rights reserved.
|
9 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
10 | this file except in compliance with the License. You may obtain a copy of the
|
11 | License at http://www.apache.org/licenses/LICENSE-2.0
|
12 |
|
13 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
15 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
16 | MERCHANTABLITY OR NON-INFRINGEMENT.
|
17 |
|
18 | See the Apache Version 2.0 License for specific language governing permissions
|
19 | and limitations under the License.
|
20 | ***************************************************************************** */
|
21 | /* global Reflect, Promise */
|
22 |
|
23 | var extendStatics = function(d, b) {
|
24 | extendStatics = Object.setPrototypeOf ||
|
25 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
26 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
27 | return extendStatics(d, b);
|
28 | };
|
29 |
|
30 | function __extends(d, b) {
|
31 | extendStatics(d, b);
|
32 | function __() { this.constructor = d; }
|
33 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
34 | }
|
35 |
|
36 | var __assign = function() {
|
37 | __assign = Object.assign || function __assign(t) {
|
38 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
39 | s = arguments[i];
|
40 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
41 | }
|
42 | return t;
|
43 | };
|
44 | return __assign.apply(this, arguments);
|
45 | };
|
46 |
|
47 | function __rest(s, e) {
|
48 | var t = {};
|
49 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
50 | t[p] = s[p];
|
51 | if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
52 | for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
53 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
54 | t[p[i]] = s[p[i]];
|
55 | }
|
56 | return t;
|
57 | }
|
58 |
|
59 | function __decorate(decorators, target, key, desc) {
|
60 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
61 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
62 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
63 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
64 | }
|
65 |
|
66 | function __param(paramIndex, decorator) {
|
67 | return function (target, key) { decorator(target, key, paramIndex); }
|
68 | }
|
69 |
|
70 | function __metadata(metadataKey, metadataValue) {
|
71 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
72 | }
|
73 |
|
74 | function __awaiter(thisArg, _arguments, P, generator) {
|
75 | return new (P || (P = Promise))(function (resolve, reject) {
|
76 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
77 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
78 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
79 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
80 | });
|
81 | }
|
82 |
|
83 | function __generator(thisArg, body) {
|
84 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
85 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
86 | function verb(n) { return function (v) { return step([n, v]); }; }
|
87 | function step(op) {
|
88 | if (f) throw new TypeError("Generator is already executing.");
|
89 | while (_) try {
|
90 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
91 | if (y = 0, t) op = [op[0] & 2, t.value];
|
92 | switch (op[0]) {
|
93 | case 0: case 1: t = op; break;
|
94 | case 4: _.label++; return { value: op[1], done: false };
|
95 | case 5: _.label++; y = op[1]; op = [0]; continue;
|
96 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
97 | default:
|
98 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
99 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
100 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
101 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
102 | if (t[2]) _.ops.pop();
|
103 | _.trys.pop(); continue;
|
104 | }
|
105 | op = body.call(thisArg, _);
|
106 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
107 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
108 | }
|
109 | }
|
110 |
|
111 | function __exportStar(m, exports) {
|
112 | for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
113 | }
|
114 |
|
115 | function __values(o) {
|
116 | var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
|
117 | if (m) return m.call(o);
|
118 | return {
|
119 | next: function () {
|
120 | if (o && i >= o.length) o = void 0;
|
121 | return { value: o && o[i++], done: !o };
|
122 | }
|
123 | };
|
124 | }
|
125 |
|
126 | function __read(o, n) {
|
127 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
128 | if (!m) return o;
|
129 | var i = m.call(o), r, ar = [], e;
|
130 | try {
|
131 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
132 | }
|
133 | catch (error) { e = { error: error }; }
|
134 | finally {
|
135 | try {
|
136 | if (r && !r.done && (m = i["return"])) m.call(i);
|
137 | }
|
138 | finally { if (e) throw e.error; }
|
139 | }
|
140 | return ar;
|
141 | }
|
142 |
|
143 | function __spread() {
|
144 | for (var ar = [], i = 0; i < arguments.length; i++)
|
145 | ar = ar.concat(__read(arguments[i]));
|
146 | return ar;
|
147 | }
|
148 |
|
149 | function __spreadArrays() {
|
150 | for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
151 | for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
152 | for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
153 | r[k] = a[j];
|
154 | return r;
|
155 | };
|
156 |
|
157 | function __await(v) {
|
158 | return this instanceof __await ? (this.v = v, this) : new __await(v);
|
159 | }
|
160 |
|
161 | function __asyncGenerator(thisArg, _arguments, generator) {
|
162 | if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
163 | var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
164 | return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
165 | function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
166 | function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
167 | function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
168 | function fulfill(value) { resume("next", value); }
|
169 | function reject(value) { resume("throw", value); }
|
170 | function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
171 | }
|
172 |
|
173 | function __asyncDelegator(o) {
|
174 | var i, p;
|
175 | return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
176 | function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
|
177 | }
|
178 |
|
179 | function __asyncValues(o) {
|
180 | if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
181 | var m = o[Symbol.asyncIterator], i;
|
182 | return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
183 | function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
184 | function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
185 | }
|
186 |
|
187 | function __makeTemplateObject(cooked, raw) {
|
188 | if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
189 | return cooked;
|
190 | };
|
191 |
|
192 | function __importStar(mod) {
|
193 | if (mod && mod.__esModule) return mod;
|
194 | var result = {};
|
195 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
196 | result.default = mod;
|
197 | return result;
|
198 | }
|
199 |
|
200 | function __importDefault(mod) {
|
201 | return (mod && mod.__esModule) ? mod : { default: mod };
|
202 | }
|
203 |
|
204 | /**
|
205 | * @fileoverview added by tsickle
|
206 | * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
207 | */
|
208 | /**
|
209 | * @abstract
|
210 | */
|
211 | var /**
|
212 | * @abstract
|
213 | */
|
214 | TranslateLoader = /** @class */ (function () {
|
215 | function TranslateLoader() {
|
216 | }
|
217 | return TranslateLoader;
|
218 | }());
|
219 | if (false) {
|
220 | /**
|
221 | * @abstract
|
222 | * @param {?} lang
|
223 | * @return {?}
|
224 | */
|
225 | TranslateLoader.prototype.getTranslation = function (lang) { };
|
226 | }
|
227 | /**
|
228 | * This loader is just a placeholder that does nothing, in case you don't need a loader at all
|
229 | */
|
230 | var TranslateFakeLoader = /** @class */ (function (_super) {
|
231 | __extends(TranslateFakeLoader, _super);
|
232 | function TranslateFakeLoader() {
|
233 | return _super !== null && _super.apply(this, arguments) || this;
|
234 | }
|
235 | /**
|
236 | * @param {?} lang
|
237 | * @return {?}
|
238 | */
|
239 | TranslateFakeLoader.prototype.getTranslation = /**
|
240 | * @param {?} lang
|
241 | * @return {?}
|
242 | */
|
243 | function (lang) {
|
244 | return rxjs.of({});
|
245 | };
|
246 | TranslateFakeLoader.decorators = [
|
247 | { type: core.Injectable }
|
248 | ];
|
249 | return TranslateFakeLoader;
|
250 | }(TranslateLoader));
|
251 |
|
252 | /**
|
253 | * @fileoverview added by tsickle
|
254 | * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
255 | */
|
256 | /**
|
257 | * @record
|
258 | */
|
259 | function MissingTranslationHandlerParams() { }
|
260 | if (false) {
|
261 | /**
|
262 | * the key that's missing in translation files
|
263 | * @type {?}
|
264 | */
|
265 | MissingTranslationHandlerParams.prototype.key;
|
266 | /**
|
267 | * an instance of the service that was unable to translate the key.
|
268 | * @type {?}
|
269 | */
|
270 | MissingTranslationHandlerParams.prototype.translateService;
|
271 | /**
|
272 | * interpolation params that were passed along for translating the given key.
|
273 | * @type {?|undefined}
|
274 | */
|
275 | MissingTranslationHandlerParams.prototype.interpolateParams;
|
276 | }
|
277 | /**
|
278 | * @abstract
|
279 | */
|
280 | var /**
|
281 | * @abstract
|
282 | */
|
283 | MissingTranslationHandler = /** @class */ (function () {
|
284 | function MissingTranslationHandler() {
|
285 | }
|
286 | return MissingTranslationHandler;
|
287 | }());
|
288 | if (false) {
|
289 | /**
|
290 | * A function that handles missing translations.
|
291 | *
|
292 | * @abstract
|
293 | * @param {?} params context for resolving a missing translation
|
294 | * @return {?} a value or an observable
|
295 | * If it returns a value, then this value is used.
|
296 | * If it return an observable, the value returned by this observable will be used (except if the method was "instant").
|
297 | * If it doesn't return then the key will be used as a value
|
298 | */
|
299 | MissingTranslationHandler.prototype.handle = function (params) { };
|
300 | }
|
301 | /**
|
302 | * This handler is just a placeholder that does nothing, in case you don't need a missing translation handler at all
|
303 | */
|
304 | var FakeMissingTranslationHandler = /** @class */ (function () {
|
305 | function FakeMissingTranslationHandler() {
|
306 | }
|
307 | /**
|
308 | * @param {?} params
|
309 | * @return {?}
|
310 | */
|
311 | FakeMissingTranslationHandler.prototype.handle = /**
|
312 | * @param {?} params
|
313 | * @return {?}
|
314 | */
|
315 | function (params) {
|
316 | return params.key;
|
317 | };
|
318 | FakeMissingTranslationHandler.decorators = [
|
319 | { type: core.Injectable }
|
320 | ];
|
321 | return FakeMissingTranslationHandler;
|
322 | }());
|
323 |
|
324 | /**
|
325 | * @fileoverview added by tsickle
|
326 | * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
327 | */
|
328 | /* tslint:disable */
|
329 | /**
|
330 | * Determines if two objects or two values are equivalent.
|
331 | *
|
332 | * Two objects or values are considered equivalent if at least one of the following is true:
|
333 | *
|
334 | * * Both objects or values pass `===` comparison.
|
335 | * * Both objects or values are of the same type and all of their properties are equal by
|
336 | * comparing them with `equals`.
|
337 | *
|
338 | * @param {?} o1 Object or value to compare.
|
339 | * @param {?} o2 Object or value to compare.
|
340 | * @return {?} true if arguments are equal.
|
341 | */
|
342 | function equals(o1, o2) {
|
343 | if (o1 === o2)
|
344 | return true;
|
345 | if (o1 === null || o2 === null)
|
346 | return false;
|
347 | if (o1 !== o1 && o2 !== o2)
|
348 | return true; // NaN === NaN
|
349 | // NaN === NaN
|
350 | /** @type {?} */
|
351 | var t1 = typeof o1;
|
352 | /** @type {?} */
|
353 | var t2 = typeof o2;
|
354 | /** @type {?} */
|
355 | var length;
|
356 | /** @type {?} */
|
357 | var key;
|
358 | /** @type {?} */
|
359 | var keySet;
|
360 | if (t1 == t2 && t1 == 'object') {
|
361 | if (Array.isArray(o1)) {
|
362 | if (!Array.isArray(o2))
|
363 | return false;
|
364 | if ((length = o1.length) == o2.length) {
|
365 | for (key = 0; key < length; key++) {
|
366 | if (!equals(o1[key], o2[key]))
|
367 | return false;
|
368 | }
|
369 | return true;
|
370 | }
|
371 | }
|
372 | else {
|
373 | if (Array.isArray(o2)) {
|
374 | return false;
|
375 | }
|
376 | keySet = Object.create(null);
|
377 | for (key in o1) {
|
378 | if (!equals(o1[key], o2[key])) {
|
379 | return false;
|
380 | }
|
381 | keySet[key] = true;
|
382 | }
|
383 | for (key in o2) {
|
384 | if (!(key in keySet) && typeof o2[key] !== 'undefined') {
|
385 | return false;
|
386 | }
|
387 | }
|
388 | return true;
|
389 | }
|
390 | }
|
391 | return false;
|
392 | }
|
393 | /* tslint:enable */
|
394 | /**
|
395 | * @param {?} value
|
396 | * @return {?}
|
397 | */
|
398 | function isDefined(value) {
|
399 | return typeof value !== 'undefined' && value !== null;
|
400 | }
|
401 | /**
|
402 | * @param {?} item
|
403 | * @return {?}
|
404 | */
|
405 | function isObject(item) {
|
406 | return (item && typeof item === 'object' && !Array.isArray(item));
|
407 | }
|
408 | /**
|
409 | * @param {?} target
|
410 | * @param {?} source
|
411 | * @return {?}
|
412 | */
|
413 | function mergeDeep(target, source) {
|
414 | /** @type {?} */
|
415 | var output = Object.assign({}, target);
|
416 | if (isObject(target) && isObject(source)) {
|
417 | Object.keys(source).forEach((/**
|
418 | * @param {?} key
|
419 | * @return {?}
|
420 | */
|
421 | function (key) {
|
422 | var _a, _b;
|
423 | if (isObject(source[key])) {
|
424 | if (!(key in target)) {
|
425 | Object.assign(output, (_a = {}, _a[key] = source[key], _a));
|
426 | }
|
427 | else {
|
428 | output[key] = mergeDeep(target[key], source[key]);
|
429 | }
|
430 | }
|
431 | else {
|
432 | Object.assign(output, (_b = {}, _b[key] = source[key], _b));
|
433 | }
|
434 | }));
|
435 | }
|
436 | return output;
|
437 | }
|
438 |
|
439 | /**
|
440 | * @fileoverview added by tsickle
|
441 | * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
442 | */
|
443 | /**
|
444 | * @abstract
|
445 | */
|
446 | var /**
|
447 | * @abstract
|
448 | */
|
449 | TranslateParser = /** @class */ (function () {
|
450 | function TranslateParser() {
|
451 | }
|
452 | return TranslateParser;
|
453 | }());
|
454 | if (false) {
|
455 | /**
|
456 | * Interpolates a string to replace parameters
|
457 | * "This is a {{ key }}" ==> "This is a value", with params = { key: "value" }
|
458 | * @abstract
|
459 | * @param {?} expr
|
460 | * @param {?=} params
|
461 | * @return {?}
|
462 | */
|
463 | TranslateParser.prototype.interpolate = function (expr, params) { };
|
464 | /**
|
465 | * Gets a value from an object by composed key
|
466 | * parser.getValue({ key1: { keyA: 'valueI' }}, 'key1.keyA') ==> 'valueI'
|
467 | * @abstract
|
468 | * @param {?} target
|
469 | * @param {?} key
|
470 | * @return {?}
|
471 | */
|
472 | TranslateParser.prototype.getValue = function (target, key) { };
|
473 | }
|
474 | var TranslateDefaultParser = /** @class */ (function (_super) {
|
475 | __extends(TranslateDefaultParser, _super);
|
476 | function TranslateDefaultParser() {
|
477 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
478 | _this.templateMatcher = /{{\s?([^{}\s]*)\s?}}/g;
|
479 | return _this;
|
480 | }
|
481 | /**
|
482 | * @param {?} expr
|
483 | * @param {?=} params
|
484 | * @return {?}
|
485 | */
|
486 | TranslateDefaultParser.prototype.interpolate = /**
|
487 | * @param {?} expr
|
488 | * @param {?=} params
|
489 | * @return {?}
|
490 | */
|
491 | function (expr, params) {
|
492 | /** @type {?} */
|
493 | var result;
|
494 | if (typeof expr === 'string') {
|
495 | result = this.interpolateString(expr, params);
|
496 | }
|
497 | else if (typeof expr === 'function') {
|
498 | result = this.interpolateFunction(expr, params);
|
499 | }
|
500 | else {
|
501 | // this should not happen, but an unrelated TranslateService test depends on it
|
502 | result = (/** @type {?} */ (expr));
|
503 | }
|
504 | return result;
|
505 | };
|
506 | /**
|
507 | * @param {?} target
|
508 | * @param {?} key
|
509 | * @return {?}
|
510 | */
|
511 | TranslateDefaultParser.prototype.getValue = /**
|
512 | * @param {?} target
|
513 | * @param {?} key
|
514 | * @return {?}
|
515 | */
|
516 | function (target, key) {
|
517 | /** @type {?} */
|
518 | var keys = typeof key === 'string' ? key.split('.') : [key];
|
519 | key = '';
|
520 | do {
|
521 | key += keys.shift();
|
522 | if (isDefined(target) && isDefined(target[key]) && (typeof target[key] === 'object' || !keys.length)) {
|
523 | target = target[key];
|
524 | key = '';
|
525 | }
|
526 | else if (!keys.length) {
|
527 | target = undefined;
|
528 | }
|
529 | else {
|
530 | key += '.';
|
531 | }
|
532 | } while (keys.length);
|
533 | return target;
|
534 | };
|
535 | /**
|
536 | * @private
|
537 | * @param {?} fn
|
538 | * @param {?=} params
|
539 | * @return {?}
|
540 | */
|
541 | TranslateDefaultParser.prototype.interpolateFunction = /**
|
542 | * @private
|
543 | * @param {?} fn
|
544 | * @param {?=} params
|
545 | * @return {?}
|
546 | */
|
547 | function (fn, params) {
|
548 | return fn(params);
|
549 | };
|
550 | /**
|
551 | * @private
|
552 | * @param {?} expr
|
553 | * @param {?=} params
|
554 | * @return {?}
|
555 | */
|
556 | TranslateDefaultParser.prototype.interpolateString = /**
|
557 | * @private
|
558 | * @param {?} expr
|
559 | * @param {?=} params
|
560 | * @return {?}
|
561 | */
|
562 | function (expr, params) {
|
563 | var _this = this;
|
564 | if (!params) {
|
565 | return expr;
|
566 | }
|
567 | return expr.replace(this.templateMatcher, (/**
|
568 | * @param {?} substring
|
569 | * @param {?} b
|
570 | * @return {?}
|
571 | */
|
572 | function (substring, b) {
|
573 | /** @type {?} */
|
574 | var r = _this.getValue(params, b);
|
575 | return isDefined(r) ? r : substring;
|
576 | }));
|
577 | };
|
578 | TranslateDefaultParser.decorators = [
|
579 | { type: core.Injectable }
|
580 | ];
|
581 | return TranslateDefaultParser;
|
582 | }(TranslateParser));
|
583 | if (false) {
|
584 | /** @type {?} */
|
585 | TranslateDefaultParser.prototype.templateMatcher;
|
586 | }
|
587 |
|
588 | /**
|
589 | * @fileoverview added by tsickle
|
590 | * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
591 | */
|
592 | /**
|
593 | * @abstract
|
594 | */
|
595 | var /**
|
596 | * @abstract
|
597 | */
|
598 | TranslateCompiler = /** @class */ (function () {
|
599 | function TranslateCompiler() {
|
600 | }
|
601 | return TranslateCompiler;
|
602 | }());
|
603 | if (false) {
|
604 | /**
|
605 | * @abstract
|
606 | * @param {?} value
|
607 | * @param {?} lang
|
608 | * @return {?}
|
609 | */
|
610 | TranslateCompiler.prototype.compile = function (value, lang) { };
|
611 | /**
|
612 | * @abstract
|
613 | * @param {?} translations
|
614 | * @param {?} lang
|
615 | * @return {?}
|
616 | */
|
617 | TranslateCompiler.prototype.compileTranslations = function (translations, lang) { };
|
618 | }
|
619 | /**
|
620 | * This compiler is just a placeholder that does nothing, in case you don't need a compiler at all
|
621 | */
|
622 | var TranslateFakeCompiler = /** @class */ (function (_super) {
|
623 | __extends(TranslateFakeCompiler, _super);
|
624 | function TranslateFakeCompiler() {
|
625 | return _super !== null && _super.apply(this, arguments) || this;
|
626 | }
|
627 | /**
|
628 | * @param {?} value
|
629 | * @param {?} lang
|
630 | * @return {?}
|
631 | */
|
632 | TranslateFakeCompiler.prototype.compile = /**
|
633 | * @param {?} value
|
634 | * @param {?} lang
|
635 | * @return {?}
|
636 | */
|
637 | function (value, lang) {
|
638 | return value;
|
639 | };
|
640 | /**
|
641 | * @param {?} translations
|
642 | * @param {?} lang
|
643 | * @return {?}
|
644 | */
|
645 | TranslateFakeCompiler.prototype.compileTranslations = /**
|
646 | * @param {?} translations
|
647 | * @param {?} lang
|
648 | * @return {?}
|
649 | */
|
650 | function (translations, lang) {
|
651 | return translations;
|
652 | };
|
653 | TranslateFakeCompiler.decorators = [
|
654 | { type: core.Injectable }
|
655 | ];
|
656 | return TranslateFakeCompiler;
|
657 | }(TranslateCompiler));
|
658 |
|
659 | /**
|
660 | * @fileoverview added by tsickle
|
661 | * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
662 | */
|
663 | var TranslateStore = /** @class */ (function () {
|
664 | function TranslateStore() {
|
665 | /**
|
666 | * The lang currently used
|
667 | */
|
668 | this.currentLang = this.defaultLang;
|
669 | /**
|
670 | * a list of translations per lang
|
671 | */
|
672 | this.translations = {};
|
673 | /**
|
674 | * an array of langs
|
675 | */
|
676 | this.langs = [];
|
677 | /**
|
678 | * An EventEmitter to listen to translation change events
|
679 | * onTranslationChange.subscribe((params: TranslationChangeEvent) => {
|
680 | * // do something
|
681 | * });
|
682 | */
|
683 | this.onTranslationChange = new core.EventEmitter();
|
684 | /**
|
685 | * An EventEmitter to listen to lang change events
|
686 | * onLangChange.subscribe((params: LangChangeEvent) => {
|
687 | * // do something
|
688 | * });
|
689 | */
|
690 | this.onLangChange = new core.EventEmitter();
|
691 | /**
|
692 | * An EventEmitter to listen to default lang change events
|
693 | * onDefaultLangChange.subscribe((params: DefaultLangChangeEvent) => {
|
694 | * // do something
|
695 | * });
|
696 | */
|
697 | this.onDefaultLangChange = new core.EventEmitter();
|
698 | }
|
699 | return TranslateStore;
|
700 | }());
|
701 | if (false) {
|
702 | /**
|
703 | * The default lang to fallback when translations are missing on the current lang
|
704 | * @type {?}
|
705 | */
|
706 | TranslateStore.prototype.defaultLang;
|
707 | /**
|
708 | * The lang currently used
|
709 | * @type {?}
|
710 | */
|
711 | TranslateStore.prototype.currentLang;
|
712 | /**
|
713 | * a list of translations per lang
|
714 | * @type {?}
|
715 | */
|
716 | TranslateStore.prototype.translations;
|
717 | /**
|
718 | * an array of langs
|
719 | * @type {?}
|
720 | */
|
721 | TranslateStore.prototype.langs;
|
722 | /**
|
723 | * An EventEmitter to listen to translation change events
|
724 | * onTranslationChange.subscribe((params: TranslationChangeEvent) => {
|
725 | * // do something
|
726 | * });
|
727 | * @type {?}
|
728 | */
|
729 | TranslateStore.prototype.onTranslationChange;
|
730 | /**
|
731 | * An EventEmitter to listen to lang change events
|
732 | * onLangChange.subscribe((params: LangChangeEvent) => {
|
733 | * // do something
|
734 | * });
|
735 | * @type {?}
|
736 | */
|
737 | TranslateStore.prototype.onLangChange;
|
738 | /**
|
739 | * An EventEmitter to listen to default lang change events
|
740 | * onDefaultLangChange.subscribe((params: DefaultLangChangeEvent) => {
|
741 | * // do something
|
742 | * });
|
743 | * @type {?}
|
744 | */
|
745 | TranslateStore.prototype.onDefaultLangChange;
|
746 | }
|
747 |
|
748 | /**
|
749 | * @fileoverview added by tsickle
|
750 | * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
751 | */
|
752 | /** @type {?} */
|
753 | var USE_STORE = new core.InjectionToken('USE_STORE');
|
754 | /** @type {?} */
|
755 | var USE_DEFAULT_LANG = new core.InjectionToken('USE_DEFAULT_LANG');
|
756 | /** @type {?} */
|
757 | var DEFAULT_LANGUAGE = new core.InjectionToken('DEFAULT_LANGUAGE');
|
758 | /** @type {?} */
|
759 | var USE_EXTEND = new core.InjectionToken('USE_EXTEND');
|
760 | /**
|
761 | * @record
|
762 | */
|
763 | function TranslationChangeEvent() { }
|
764 | if (false) {
|
765 | /** @type {?} */
|
766 | TranslationChangeEvent.prototype.translations;
|
767 | /** @type {?} */
|
768 | TranslationChangeEvent.prototype.lang;
|
769 | }
|
770 | /**
|
771 | * @record
|
772 | */
|
773 | function LangChangeEvent() { }
|
774 | if (false) {
|
775 | /** @type {?} */
|
776 | LangChangeEvent.prototype.lang;
|
777 | /** @type {?} */
|
778 | LangChangeEvent.prototype.translations;
|
779 | }
|
780 | /**
|
781 | * @record
|
782 | */
|
783 | function DefaultLangChangeEvent() { }
|
784 | if (false) {
|
785 | /** @type {?} */
|
786 | DefaultLangChangeEvent.prototype.lang;
|
787 | /** @type {?} */
|
788 | DefaultLangChangeEvent.prototype.translations;
|
789 | }
|
790 | var TranslateService = /** @class */ (function () {
|
791 | /**
|
792 | *
|
793 | * @param store an instance of the store (that is supposed to be unique)
|
794 | * @param currentLoader An instance of the loader currently used
|
795 | * @param compiler An instance of the compiler currently used
|
796 | * @param parser An instance of the parser currently used
|
797 | * @param missingTranslationHandler A handler for missing translations.
|
798 | * @param useDefaultLang whether we should use default language translation when current language translation is missing.
|
799 | * @param isolate whether this service should use the store or not
|
800 | * @param extend To make a child module extend (and use) translations from parent modules.
|
801 | * @param defaultLanguage Set the default language using configuration
|
802 | */
|
803 | function TranslateService(store, currentLoader, compiler, parser, missingTranslationHandler, useDefaultLang, isolate, extend, defaultLanguage) {
|
804 | if (useDefaultLang === void 0) { useDefaultLang = true; }
|
805 | if (isolate === void 0) { isolate = false; }
|
806 | if (extend === void 0) { extend = false; }
|
807 | this.store = store;
|
808 | this.currentLoader = currentLoader;
|
809 | this.compiler = compiler;
|
810 | this.parser = parser;
|
811 | this.missingTranslationHandler = missingTranslationHandler;
|
812 | this.useDefaultLang = useDefaultLang;
|
813 | this.isolate = isolate;
|
814 | this.extend = extend;
|
815 | this.pending = false;
|
816 | this._onTranslationChange = new core.EventEmitter();
|
817 | this._onLangChange = new core.EventEmitter();
|
818 | this._onDefaultLangChange = new core.EventEmitter();
|
819 | this._langs = [];
|
820 | this._translations = {};
|
821 | this._translationRequests = {};
|
822 | /** set the default language from configuration */
|
823 | if (defaultLanguage) {
|
824 | this.setDefaultLang(defaultLanguage);
|
825 | }
|
826 | }
|
827 | Object.defineProperty(TranslateService.prototype, "onTranslationChange", {
|
828 | /**
|
829 | * An EventEmitter to listen to translation change events
|
830 | * onTranslationChange.subscribe((params: TranslationChangeEvent) => {
|
831 | * // do something
|
832 | * });
|
833 | */
|
834 | get: /**
|
835 | * An EventEmitter to listen to translation change events
|
836 | * onTranslationChange.subscribe((params: TranslationChangeEvent) => {
|
837 | * // do something
|
838 | * });
|
839 | * @return {?}
|
840 | */
|
841 | function () {
|
842 | return this.isolate ? this._onTranslationChange : this.store.onTranslationChange;
|
843 | },
|
844 | enumerable: true,
|
845 | configurable: true
|
846 | });
|
847 | Object.defineProperty(TranslateService.prototype, "onLangChange", {
|
848 | /**
|
849 | * An EventEmitter to listen to lang change events
|
850 | * onLangChange.subscribe((params: LangChangeEvent) => {
|
851 | * // do something
|
852 | * });
|
853 | */
|
854 | get: /**
|
855 | * An EventEmitter to listen to lang change events
|
856 | * onLangChange.subscribe((params: LangChangeEvent) => {
|
857 | * // do something
|
858 | * });
|
859 | * @return {?}
|
860 | */
|
861 | function () {
|
862 | return this.isolate ? this._onLangChange : this.store.onLangChange;
|
863 | },
|
864 | enumerable: true,
|
865 | configurable: true
|
866 | });
|
867 | Object.defineProperty(TranslateService.prototype, "onDefaultLangChange", {
|
868 | /**
|
869 | * An EventEmitter to listen to default lang change events
|
870 | * onDefaultLangChange.subscribe((params: DefaultLangChangeEvent) => {
|
871 | * // do something
|
872 | * });
|
873 | */
|
874 | get: /**
|
875 | * An EventEmitter to listen to default lang change events
|
876 | * onDefaultLangChange.subscribe((params: DefaultLangChangeEvent) => {
|
877 | * // do something
|
878 | * });
|
879 | * @return {?}
|
880 | */
|
881 | function () {
|
882 | return this.isolate ? this._onDefaultLangChange : this.store.onDefaultLangChange;
|
883 | },
|
884 | enumerable: true,
|
885 | configurable: true
|
886 | });
|
887 | Object.defineProperty(TranslateService.prototype, "defaultLang", {
|
888 | /**
|
889 | * The default lang to fallback when translations are missing on the current lang
|
890 | */
|
891 | get: /**
|
892 | * The default lang to fallback when translations are missing on the current lang
|
893 | * @return {?}
|
894 | */
|
895 | function () {
|
896 | return this.isolate ? this._defaultLang : this.store.defaultLang;
|
897 | },
|
898 | set: /**
|
899 | * @param {?} defaultLang
|
900 | * @return {?}
|
901 | */
|
902 | function (defaultLang) {
|
903 | if (this.isolate) {
|
904 | this._defaultLang = defaultLang;
|
905 | }
|
906 | else {
|
907 | this.store.defaultLang = defaultLang;
|
908 | }
|
909 | },
|
910 | enumerable: true,
|
911 | configurable: true
|
912 | });
|
913 | Object.defineProperty(TranslateService.prototype, "currentLang", {
|
914 | /**
|
915 | * The lang currently used
|
916 | */
|
917 | get: /**
|
918 | * The lang currently used
|
919 | * @return {?}
|
920 | */
|
921 | function () {
|
922 | return this.isolate ? this._currentLang : this.store.currentLang;
|
923 | },
|
924 | set: /**
|
925 | * @param {?} currentLang
|
926 | * @return {?}
|
927 | */
|
928 | function (currentLang) {
|
929 | if (this.isolate) {
|
930 | this._currentLang = currentLang;
|
931 | }
|
932 | else {
|
933 | this.store.currentLang = currentLang;
|
934 | }
|
935 | },
|
936 | enumerable: true,
|
937 | configurable: true
|
938 | });
|
939 | Object.defineProperty(TranslateService.prototype, "langs", {
|
940 | /**
|
941 | * an array of langs
|
942 | */
|
943 | get: /**
|
944 | * an array of langs
|
945 | * @return {?}
|
946 | */
|
947 | function () {
|
948 | return this.isolate ? this._langs : this.store.langs;
|
949 | },
|
950 | set: /**
|
951 | * @param {?} langs
|
952 | * @return {?}
|
953 | */
|
954 | function (langs) {
|
955 | if (this.isolate) {
|
956 | this._langs = langs;
|
957 | }
|
958 | else {
|
959 | this.store.langs = langs;
|
960 | }
|
961 | },
|
962 | enumerable: true,
|
963 | configurable: true
|
964 | });
|
965 | Object.defineProperty(TranslateService.prototype, "translations", {
|
966 | /**
|
967 | * a list of translations per lang
|
968 | */
|
969 | get: /**
|
970 | * a list of translations per lang
|
971 | * @return {?}
|
972 | */
|
973 | function () {
|
974 | return this.isolate ? this._translations : this.store.translations;
|
975 | },
|
976 | set: /**
|
977 | * @param {?} translations
|
978 | * @return {?}
|
979 | */
|
980 | function (translations) {
|
981 | if (this.isolate) {
|
982 | this._translations = translations;
|
983 | }
|
984 | else {
|
985 | this.store.translations = translations;
|
986 | }
|
987 | },
|
988 | enumerable: true,
|
989 | configurable: true
|
990 | });
|
991 | /**
|
992 | * Sets the default language to use as a fallback
|
993 | */
|
994 | /**
|
995 | * Sets the default language to use as a fallback
|
996 | * @param {?} lang
|
997 | * @return {?}
|
998 | */
|
999 | TranslateService.prototype.setDefaultLang = /**
|
1000 | * Sets the default language to use as a fallback
|
1001 | * @param {?} lang
|
1002 | * @return {?}
|
1003 | */
|
1004 | function (lang) {
|
1005 | var _this = this;
|
1006 | if (lang === this.defaultLang) {
|
1007 | return;
|
1008 | }
|
1009 | /** @type {?} */
|
1010 | var pending = this.retrieveTranslations(lang);
|
1011 | if (typeof pending !== "undefined") {
|
1012 | // on init set the defaultLang immediately
|
1013 | if (this.defaultLang == null) {
|
1014 | this.defaultLang = lang;
|
1015 | }
|
1016 | pending.pipe(operators.take(1))
|
1017 | .subscribe((/**
|
1018 | * @param {?} res
|
1019 | * @return {?}
|
1020 | */
|
1021 | function (res) {
|
1022 | _this.changeDefaultLang(lang);
|
1023 | }));
|
1024 | }
|
1025 | else { // we already have this language
|
1026 | this.changeDefaultLang(lang);
|
1027 | }
|
1028 | };
|
1029 | /**
|
1030 | * Gets the default language used
|
1031 | */
|
1032 | /**
|
1033 | * Gets the default language used
|
1034 | * @return {?}
|
1035 | */
|
1036 | TranslateService.prototype.getDefaultLang = /**
|
1037 | * Gets the default language used
|
1038 | * @return {?}
|
1039 | */
|
1040 | function () {
|
1041 | return this.defaultLang;
|
1042 | };
|
1043 | /**
|
1044 | * Changes the lang currently used
|
1045 | */
|
1046 | /**
|
1047 | * Changes the lang currently used
|
1048 | * @param {?} lang
|
1049 | * @return {?}
|
1050 | */
|
1051 | TranslateService.prototype.use = /**
|
1052 | * Changes the lang currently used
|
1053 | * @param {?} lang
|
1054 | * @return {?}
|
1055 | */
|
1056 | function (lang) {
|
1057 | var _this = this;
|
1058 | // don't change the language if the language given is already selected
|
1059 | if (lang === this.currentLang) {
|
1060 | return rxjs.of(this.translations[lang]);
|
1061 | }
|
1062 | /** @type {?} */
|
1063 | var pending = this.retrieveTranslations(lang);
|
1064 | if (typeof pending !== "undefined") {
|
1065 | // on init set the currentLang immediately
|
1066 | if (!this.currentLang) {
|
1067 | this.currentLang = lang;
|
1068 | }
|
1069 | pending.pipe(operators.take(1))
|
1070 | .subscribe((/**
|
1071 | * @param {?} res
|
1072 | * @return {?}
|
1073 | */
|
1074 | function (res) {
|
1075 | _this.changeLang(lang);
|
1076 | }));
|
1077 | return pending;
|
1078 | }
|
1079 | else { // we have this language, return an Observable
|
1080 | this.changeLang(lang);
|
1081 | return rxjs.of(this.translations[lang]);
|
1082 | }
|
1083 | };
|
1084 | /**
|
1085 | * Retrieves the given translations
|
1086 | */
|
1087 | /**
|
1088 | * Retrieves the given translations
|
1089 | * @private
|
1090 | * @param {?} lang
|
1091 | * @return {?}
|
1092 | */
|
1093 | TranslateService.prototype.retrieveTranslations = /**
|
1094 | * Retrieves the given translations
|
1095 | * @private
|
1096 | * @param {?} lang
|
1097 | * @return {?}
|
1098 | */
|
1099 | function (lang) {
|
1100 | /** @type {?} */
|
1101 | var pending;
|
1102 | // if this language is unavailable or extend is true, ask for it
|
1103 | if (typeof this.translations[lang] === "undefined" || this.extend) {
|
1104 | this._translationRequests[lang] = this._translationRequests[lang] || this.getTranslation(lang);
|
1105 | pending = this._translationRequests[lang];
|
1106 | }
|
1107 | return pending;
|
1108 | };
|
1109 | /**
|
1110 | * Gets an object of translations for a given language with the current loader
|
1111 | * and passes it through the compiler
|
1112 | */
|
1113 | /**
|
1114 | * Gets an object of translations for a given language with the current loader
|
1115 | * and passes it through the compiler
|
1116 | * @param {?} lang
|
1117 | * @return {?}
|
1118 | */
|
1119 | TranslateService.prototype.getTranslation = /**
|
1120 | * Gets an object of translations for a given language with the current loader
|
1121 | * and passes it through the compiler
|
1122 | * @param {?} lang
|
1123 | * @return {?}
|
1124 | */
|
1125 | function (lang) {
|
1126 | var _this = this;
|
1127 | this.pending = true;
|
1128 | /** @type {?} */
|
1129 | var loadingTranslations = this.currentLoader.getTranslation(lang).pipe(operators.shareReplay(1), operators.take(1));
|
1130 | this.loadingTranslations = loadingTranslations.pipe(operators.map((/**
|
1131 | * @param {?} res
|
1132 | * @return {?}
|
1133 | */
|
1134 | function (res) { return _this.compiler.compileTranslations(res, lang); })), operators.shareReplay(1), operators.take(1));
|
1135 | this.loadingTranslations
|
1136 | .subscribe({
|
1137 | next: (/**
|
1138 | * @param {?} res
|
1139 | * @return {?}
|
1140 | */
|
1141 | function (res) {
|
1142 | _this.translations[lang] = _this.extend && _this.translations[lang] ? __assign(__assign({}, res), _this.translations[lang]) : res;
|
1143 | _this.updateLangs();
|
1144 | _this.pending = false;
|
1145 | }),
|
1146 | error: (/**
|
1147 | * @param {?} err
|
1148 | * @return {?}
|
1149 | */
|
1150 | function (err) {
|
1151 | _this.pending = false;
|
1152 | })
|
1153 | });
|
1154 | return loadingTranslations;
|
1155 | };
|
1156 | /**
|
1157 | * Manually sets an object of translations for a given language
|
1158 | * after passing it through the compiler
|
1159 | */
|
1160 | /**
|
1161 | * Manually sets an object of translations for a given language
|
1162 | * after passing it through the compiler
|
1163 | * @param {?} lang
|
1164 | * @param {?} translations
|
1165 | * @param {?=} shouldMerge
|
1166 | * @return {?}
|
1167 | */
|
1168 | TranslateService.prototype.setTranslation = /**
|
1169 | * Manually sets an object of translations for a given language
|
1170 | * after passing it through the compiler
|
1171 | * @param {?} lang
|
1172 | * @param {?} translations
|
1173 | * @param {?=} shouldMerge
|
1174 | * @return {?}
|
1175 | */
|
1176 | function (lang, translations, shouldMerge) {
|
1177 | if (shouldMerge === void 0) { shouldMerge = false; }
|
1178 | translations = this.compiler.compileTranslations(translations, lang);
|
1179 | if ((shouldMerge || this.extend) && this.translations[lang]) {
|
1180 | this.translations[lang] = mergeDeep(this.translations[lang], translations);
|
1181 | }
|
1182 | else {
|
1183 | this.translations[lang] = translations;
|
1184 | }
|
1185 | this.updateLangs();
|
1186 | this.onTranslationChange.emit({ lang: lang, translations: this.translations[lang] });
|
1187 | };
|
1188 | /**
|
1189 | * Returns an array of currently available langs
|
1190 | */
|
1191 | /**
|
1192 | * Returns an array of currently available langs
|
1193 | * @return {?}
|
1194 | */
|
1195 | TranslateService.prototype.getLangs = /**
|
1196 | * Returns an array of currently available langs
|
1197 | * @return {?}
|
1198 | */
|
1199 | function () {
|
1200 | return this.langs;
|
1201 | };
|
1202 | /**
|
1203 | * Add available langs
|
1204 | */
|
1205 | /**
|
1206 | * Add available langs
|
1207 | * @param {?} langs
|
1208 | * @return {?}
|
1209 | */
|
1210 | TranslateService.prototype.addLangs = /**
|
1211 | * Add available langs
|
1212 | * @param {?} langs
|
1213 | * @return {?}
|
1214 | */
|
1215 | function (langs) {
|
1216 | var _this = this;
|
1217 | langs.forEach((/**
|
1218 | * @param {?} lang
|
1219 | * @return {?}
|
1220 | */
|
1221 | function (lang) {
|
1222 | if (_this.langs.indexOf(lang) === -1) {
|
1223 | _this.langs.push(lang);
|
1224 | }
|
1225 | }));
|
1226 | };
|
1227 | /**
|
1228 | * Update the list of available langs
|
1229 | */
|
1230 | /**
|
1231 | * Update the list of available langs
|
1232 | * @private
|
1233 | * @return {?}
|
1234 | */
|
1235 | TranslateService.prototype.updateLangs = /**
|
1236 | * Update the list of available langs
|
1237 | * @private
|
1238 | * @return {?}
|
1239 | */
|
1240 | function () {
|
1241 | this.addLangs(Object.keys(this.translations));
|
1242 | };
|
1243 | /**
|
1244 | * Returns the parsed result of the translations
|
1245 | */
|
1246 | /**
|
1247 | * Returns the parsed result of the translations
|
1248 | * @param {?} translations
|
1249 | * @param {?} key
|
1250 | * @param {?=} interpolateParams
|
1251 | * @return {?}
|
1252 | */
|
1253 | TranslateService.prototype.getParsedResult = /**
|
1254 | * Returns the parsed result of the translations
|
1255 | * @param {?} translations
|
1256 | * @param {?} key
|
1257 | * @param {?=} interpolateParams
|
1258 | * @return {?}
|
1259 | */
|
1260 | function (translations, key, interpolateParams) {
|
1261 | var e_1, _a;
|
1262 | /** @type {?} */
|
1263 | var res;
|
1264 | if (key instanceof Array) {
|
1265 | /** @type {?} */
|
1266 | var result_1 = {};
|
1267 | /** @type {?} */
|
1268 | var observables = false;
|
1269 | try {
|
1270 | for (var key_1 = __values(key), key_1_1 = key_1.next(); !key_1_1.done; key_1_1 = key_1.next()) {
|
1271 | var k = key_1_1.value;
|
1272 | result_1[k] = this.getParsedResult(translations, k, interpolateParams);
|
1273 | if (rxjs.isObservable(result_1[k])) {
|
1274 | observables = true;
|
1275 | }
|
1276 | }
|
1277 | }
|
1278 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
1279 | finally {
|
1280 | try {
|
1281 | if (key_1_1 && !key_1_1.done && (_a = key_1.return)) _a.call(key_1);
|
1282 | }
|
1283 | finally { if (e_1) throw e_1.error; }
|
1284 | }
|
1285 | if (observables) {
|
1286 | /** @type {?} */
|
1287 | var sources = key.map((/**
|
1288 | * @param {?} k
|
1289 | * @return {?}
|
1290 | */
|
1291 | function (k) { return rxjs.isObservable(result_1[k]) ? result_1[k] : rxjs.of((/** @type {?} */ (result_1[k]))); }));
|
1292 | return rxjs.forkJoin(sources).pipe(operators.map((/**
|
1293 | * @param {?} arr
|
1294 | * @return {?}
|
1295 | */
|
1296 | function (arr) {
|
1297 | /** @type {?} */
|
1298 | var obj = {};
|
1299 | arr.forEach((/**
|
1300 | * @param {?} value
|
1301 | * @param {?} index
|
1302 | * @return {?}
|
1303 | */
|
1304 | function (value, index) {
|
1305 | obj[key[index]] = value;
|
1306 | }));
|
1307 | return obj;
|
1308 | })));
|
1309 | }
|
1310 | return result_1;
|
1311 | }
|
1312 | if (translations) {
|
1313 | res = this.parser.interpolate(this.parser.getValue(translations, key), interpolateParams);
|
1314 | }
|
1315 | if (typeof res === "undefined" && this.defaultLang != null && this.defaultLang !== this.currentLang && this.useDefaultLang) {
|
1316 | res = this.parser.interpolate(this.parser.getValue(this.translations[this.defaultLang], key), interpolateParams);
|
1317 | }
|
1318 | if (typeof res === "undefined") {
|
1319 | /** @type {?} */
|
1320 | var params = { key: key, translateService: this };
|
1321 | if (typeof interpolateParams !== 'undefined') {
|
1322 | params.interpolateParams = interpolateParams;
|
1323 | }
|
1324 | res = this.missingTranslationHandler.handle(params);
|
1325 | }
|
1326 | return typeof res !== "undefined" ? res : key;
|
1327 | };
|
1328 | /**
|
1329 | * Gets the translated value of a key (or an array of keys)
|
1330 | * @returns the translated key, or an object of translated keys
|
1331 | */
|
1332 | /**
|
1333 | * Gets the translated value of a key (or an array of keys)
|
1334 | * @param {?} key
|
1335 | * @param {?=} interpolateParams
|
1336 | * @return {?} the translated key, or an object of translated keys
|
1337 | */
|
1338 | TranslateService.prototype.get = /**
|
1339 | * Gets the translated value of a key (or an array of keys)
|
1340 | * @param {?} key
|
1341 | * @param {?=} interpolateParams
|
1342 | * @return {?} the translated key, or an object of translated keys
|
1343 | */
|
1344 | function (key, interpolateParams) {
|
1345 | var _this = this;
|
1346 | if (!isDefined(key) || !key.length) {
|
1347 | throw new Error("Parameter \"key\" required");
|
1348 | }
|
1349 | // check if we are loading a new translation to use
|
1350 | if (this.pending) {
|
1351 | return this.loadingTranslations.pipe(operators.concatMap((/**
|
1352 | * @param {?} res
|
1353 | * @return {?}
|
1354 | */
|
1355 | function (res) {
|
1356 | res = _this.getParsedResult(res, key, interpolateParams);
|
1357 | return rxjs.isObservable(res) ? res : rxjs.of(res);
|
1358 | })));
|
1359 | }
|
1360 | else {
|
1361 | /** @type {?} */
|
1362 | var res = this.getParsedResult(this.translations[this.currentLang], key, interpolateParams);
|
1363 | return rxjs.isObservable(res) ? res : rxjs.of(res);
|
1364 | }
|
1365 | };
|
1366 | /**
|
1367 | * Returns a stream of translated values of a key (or an array of keys) which updates
|
1368 | * whenever the translation changes.
|
1369 | * @returns A stream of the translated key, or an object of translated keys
|
1370 | */
|
1371 | /**
|
1372 | * Returns a stream of translated values of a key (or an array of keys) which updates
|
1373 | * whenever the translation changes.
|
1374 | * @param {?} key
|
1375 | * @param {?=} interpolateParams
|
1376 | * @return {?} A stream of the translated key, or an object of translated keys
|
1377 | */
|
1378 | TranslateService.prototype.getStreamOnTranslationChange = /**
|
1379 | * Returns a stream of translated values of a key (or an array of keys) which updates
|
1380 | * whenever the translation changes.
|
1381 | * @param {?} key
|
1382 | * @param {?=} interpolateParams
|
1383 | * @return {?} A stream of the translated key, or an object of translated keys
|
1384 | */
|
1385 | function (key, interpolateParams) {
|
1386 | var _this = this;
|
1387 | if (!isDefined(key) || !key.length) {
|
1388 | throw new Error("Parameter \"key\" required");
|
1389 | }
|
1390 | return rxjs.concat(rxjs.defer((/**
|
1391 | * @return {?}
|
1392 | */
|
1393 | function () { return _this.get(key, interpolateParams); })), this.onTranslationChange.pipe(operators.switchMap((/**
|
1394 | * @param {?} event
|
1395 | * @return {?}
|
1396 | */
|
1397 | function (event) {
|
1398 | /** @type {?} */
|
1399 | var res = _this.getParsedResult(event.translations, key, interpolateParams);
|
1400 | if (typeof res.subscribe === 'function') {
|
1401 | return res;
|
1402 | }
|
1403 | else {
|
1404 | return rxjs.of(res);
|
1405 | }
|
1406 | }))));
|
1407 | };
|
1408 | /**
|
1409 | * Returns a stream of translated values of a key (or an array of keys) which updates
|
1410 | * whenever the language changes.
|
1411 | * @returns A stream of the translated key, or an object of translated keys
|
1412 | */
|
1413 | /**
|
1414 | * Returns a stream of translated values of a key (or an array of keys) which updates
|
1415 | * whenever the language changes.
|
1416 | * @param {?} key
|
1417 | * @param {?=} interpolateParams
|
1418 | * @return {?} A stream of the translated key, or an object of translated keys
|
1419 | */
|
1420 | TranslateService.prototype.stream = /**
|
1421 | * Returns a stream of translated values of a key (or an array of keys) which updates
|
1422 | * whenever the language changes.
|
1423 | * @param {?} key
|
1424 | * @param {?=} interpolateParams
|
1425 | * @return {?} A stream of the translated key, or an object of translated keys
|
1426 | */
|
1427 | function (key, interpolateParams) {
|
1428 | var _this = this;
|
1429 | if (!isDefined(key) || !key.length) {
|
1430 | throw new Error("Parameter \"key\" required");
|
1431 | }
|
1432 | return rxjs.concat(rxjs.defer((/**
|
1433 | * @return {?}
|
1434 | */
|
1435 | function () { return _this.get(key, interpolateParams); })), this.onLangChange.pipe(operators.switchMap((/**
|
1436 | * @param {?} event
|
1437 | * @return {?}
|
1438 | */
|
1439 | function (event) {
|
1440 | /** @type {?} */
|
1441 | var res = _this.getParsedResult(event.translations, key, interpolateParams);
|
1442 | return rxjs.isObservable(res) ? res : rxjs.of(res);
|
1443 | }))));
|
1444 | };
|
1445 | /**
|
1446 | * Returns a translation instantly from the internal state of loaded translation.
|
1447 | * All rules regarding the current language, the preferred language of even fallback languages will be used except any promise handling.
|
1448 | */
|
1449 | /**
|
1450 | * Returns a translation instantly from the internal state of loaded translation.
|
1451 | * All rules regarding the current language, the preferred language of even fallback languages will be used except any promise handling.
|
1452 | * @param {?} key
|
1453 | * @param {?=} interpolateParams
|
1454 | * @return {?}
|
1455 | */
|
1456 | TranslateService.prototype.instant = /**
|
1457 | * Returns a translation instantly from the internal state of loaded translation.
|
1458 | * All rules regarding the current language, the preferred language of even fallback languages will be used except any promise handling.
|
1459 | * @param {?} key
|
1460 | * @param {?=} interpolateParams
|
1461 | * @return {?}
|
1462 | */
|
1463 | function (key, interpolateParams) {
|
1464 | if (!isDefined(key) || !key.length) {
|
1465 | throw new Error("Parameter \"key\" required");
|
1466 | }
|
1467 | /** @type {?} */
|
1468 | var res = this.getParsedResult(this.translations[this.currentLang], key, interpolateParams);
|
1469 | if (rxjs.isObservable(res)) {
|
1470 | if (key instanceof Array) {
|
1471 | /** @type {?} */
|
1472 | var obj_1 = {};
|
1473 | key.forEach((/**
|
1474 | * @param {?} value
|
1475 | * @param {?} index
|
1476 | * @return {?}
|
1477 | */
|
1478 | function (value, index) {
|
1479 | obj_1[key[index]] = key[index];
|
1480 | }));
|
1481 | return obj_1;
|
1482 | }
|
1483 | return key;
|
1484 | }
|
1485 | else {
|
1486 | return res;
|
1487 | }
|
1488 | };
|
1489 | /**
|
1490 | * Sets the translated value of a key, after compiling it
|
1491 | */
|
1492 | /**
|
1493 | * Sets the translated value of a key, after compiling it
|
1494 | * @param {?} key
|
1495 | * @param {?} value
|
1496 | * @param {?=} lang
|
1497 | * @return {?}
|
1498 | */
|
1499 | TranslateService.prototype.set = /**
|
1500 | * Sets the translated value of a key, after compiling it
|
1501 | * @param {?} key
|
1502 | * @param {?} value
|
1503 | * @param {?=} lang
|
1504 | * @return {?}
|
1505 | */
|
1506 | function (key, value, lang) {
|
1507 | if (lang === void 0) { lang = this.currentLang; }
|
1508 | this.translations[lang][key] = this.compiler.compile(value, lang);
|
1509 | this.updateLangs();
|
1510 | this.onTranslationChange.emit({ lang: lang, translations: this.translations[lang] });
|
1511 | };
|
1512 | /**
|
1513 | * Changes the current lang
|
1514 | */
|
1515 | /**
|
1516 | * Changes the current lang
|
1517 | * @private
|
1518 | * @param {?} lang
|
1519 | * @return {?}
|
1520 | */
|
1521 | TranslateService.prototype.changeLang = /**
|
1522 | * Changes the current lang
|
1523 | * @private
|
1524 | * @param {?} lang
|
1525 | * @return {?}
|
1526 | */
|
1527 | function (lang) {
|
1528 | this.currentLang = lang;
|
1529 | this.onLangChange.emit({ lang: lang, translations: this.translations[lang] });
|
1530 | // if there is no default lang, use the one that we just set
|
1531 | if (this.defaultLang == null) {
|
1532 | this.changeDefaultLang(lang);
|
1533 | }
|
1534 | };
|
1535 | /**
|
1536 | * Changes the default lang
|
1537 | */
|
1538 | /**
|
1539 | * Changes the default lang
|
1540 | * @private
|
1541 | * @param {?} lang
|
1542 | * @return {?}
|
1543 | */
|
1544 | TranslateService.prototype.changeDefaultLang = /**
|
1545 | * Changes the default lang
|
1546 | * @private
|
1547 | * @param {?} lang
|
1548 | * @return {?}
|
1549 | */
|
1550 | function (lang) {
|
1551 | this.defaultLang = lang;
|
1552 | this.onDefaultLangChange.emit({ lang: lang, translations: this.translations[lang] });
|
1553 | };
|
1554 | /**
|
1555 | * Allows to reload the lang file from the file
|
1556 | */
|
1557 | /**
|
1558 | * Allows to reload the lang file from the file
|
1559 | * @param {?} lang
|
1560 | * @return {?}
|
1561 | */
|
1562 | TranslateService.prototype.reloadLang = /**
|
1563 | * Allows to reload the lang file from the file
|
1564 | * @param {?} lang
|
1565 | * @return {?}
|
1566 | */
|
1567 | function (lang) {
|
1568 | this.resetLang(lang);
|
1569 | return this.getTranslation(lang);
|
1570 | };
|
1571 | /**
|
1572 | * Deletes inner translation
|
1573 | */
|
1574 | /**
|
1575 | * Deletes inner translation
|
1576 | * @param {?} lang
|
1577 | * @return {?}
|
1578 | */
|
1579 | TranslateService.prototype.resetLang = /**
|
1580 | * Deletes inner translation
|
1581 | * @param {?} lang
|
1582 | * @return {?}
|
1583 | */
|
1584 | function (lang) {
|
1585 | this._translationRequests[lang] = undefined;
|
1586 | this.translations[lang] = undefined;
|
1587 | };
|
1588 | /**
|
1589 | * Returns the language code name from the browser, e.g. "de"
|
1590 | */
|
1591 | /**
|
1592 | * Returns the language code name from the browser, e.g. "de"
|
1593 | * @return {?}
|
1594 | */
|
1595 | TranslateService.prototype.getBrowserLang = /**
|
1596 | * Returns the language code name from the browser, e.g. "de"
|
1597 | * @return {?}
|
1598 | */
|
1599 | function () {
|
1600 | if (typeof window === 'undefined' || typeof window.navigator === 'undefined') {
|
1601 | return undefined;
|
1602 | }
|
1603 | /** @type {?} */
|
1604 | var browserLang = window.navigator.languages ? window.navigator.languages[0] : null;
|
1605 | browserLang = browserLang || window.navigator.language || window.navigator.browserLanguage || window.navigator.userLanguage;
|
1606 | if (typeof browserLang === 'undefined') {
|
1607 | return undefined;
|
1608 | }
|
1609 | if (browserLang.indexOf('-') !== -1) {
|
1610 | browserLang = browserLang.split('-')[0];
|
1611 | }
|
1612 | if (browserLang.indexOf('_') !== -1) {
|
1613 | browserLang = browserLang.split('_')[0];
|
1614 | }
|
1615 | return browserLang;
|
1616 | };
|
1617 | /**
|
1618 | * Returns the culture language code name from the browser, e.g. "de-DE"
|
1619 | */
|
1620 | /**
|
1621 | * Returns the culture language code name from the browser, e.g. "de-DE"
|
1622 | * @return {?}
|
1623 | */
|
1624 | TranslateService.prototype.getBrowserCultureLang = /**
|
1625 | * Returns the culture language code name from the browser, e.g. "de-DE"
|
1626 | * @return {?}
|
1627 | */
|
1628 | function () {
|
1629 | if (typeof window === 'undefined' || typeof window.navigator === 'undefined') {
|
1630 | return undefined;
|
1631 | }
|
1632 | /** @type {?} */
|
1633 | var browserCultureLang = window.navigator.languages ? window.navigator.languages[0] : null;
|
1634 | browserCultureLang = browserCultureLang || window.navigator.language || window.navigator.browserLanguage || window.navigator.userLanguage;
|
1635 | return browserCultureLang;
|
1636 | };
|
1637 | TranslateService.decorators = [
|
1638 | { type: core.Injectable }
|
1639 | ];
|
1640 | /** @nocollapse */
|
1641 | TranslateService.ctorParameters = function () { return [
|
1642 | { type: TranslateStore },
|
1643 | { type: TranslateLoader },
|
1644 | { type: TranslateCompiler },
|
1645 | { type: TranslateParser },
|
1646 | { type: MissingTranslationHandler },
|
1647 | { type: Boolean, decorators: [{ type: core.Inject, args: [USE_DEFAULT_LANG,] }] },
|
1648 | { type: Boolean, decorators: [{ type: core.Inject, args: [USE_STORE,] }] },
|
1649 | { type: Boolean, decorators: [{ type: core.Inject, args: [USE_EXTEND,] }] },
|
1650 | { type: String, decorators: [{ type: core.Inject, args: [DEFAULT_LANGUAGE,] }] }
|
1651 | ]; };
|
1652 | return TranslateService;
|
1653 | }());
|
1654 | if (false) {
|
1655 | /**
|
1656 | * @type {?}
|
1657 | * @private
|
1658 | */
|
1659 | TranslateService.prototype.loadingTranslations;
|
1660 | /**
|
1661 | * @type {?}
|
1662 | * @private
|
1663 | */
|
1664 | TranslateService.prototype.pending;
|
1665 | /**
|
1666 | * @type {?}
|
1667 | * @private
|
1668 | */
|
1669 | TranslateService.prototype._onTranslationChange;
|
1670 | /**
|
1671 | * @type {?}
|
1672 | * @private
|
1673 | */
|
1674 | TranslateService.prototype._onLangChange;
|
1675 | /**
|
1676 | * @type {?}
|
1677 | * @private
|
1678 | */
|
1679 | TranslateService.prototype._onDefaultLangChange;
|
1680 | /**
|
1681 | * @type {?}
|
1682 | * @private
|
1683 | */
|
1684 | TranslateService.prototype._defaultLang;
|
1685 | /**
|
1686 | * @type {?}
|
1687 | * @private
|
1688 | */
|
1689 | TranslateService.prototype._currentLang;
|
1690 | /**
|
1691 | * @type {?}
|
1692 | * @private
|
1693 | */
|
1694 | TranslateService.prototype._langs;
|
1695 | /**
|
1696 | * @type {?}
|
1697 | * @private
|
1698 | */
|
1699 | TranslateService.prototype._translations;
|
1700 | /**
|
1701 | * @type {?}
|
1702 | * @private
|
1703 | */
|
1704 | TranslateService.prototype._translationRequests;
|
1705 | /** @type {?} */
|
1706 | TranslateService.prototype.store;
|
1707 | /** @type {?} */
|
1708 | TranslateService.prototype.currentLoader;
|
1709 | /** @type {?} */
|
1710 | TranslateService.prototype.compiler;
|
1711 | /** @type {?} */
|
1712 | TranslateService.prototype.parser;
|
1713 | /** @type {?} */
|
1714 | TranslateService.prototype.missingTranslationHandler;
|
1715 | /**
|
1716 | * @type {?}
|
1717 | * @private
|
1718 | */
|
1719 | TranslateService.prototype.useDefaultLang;
|
1720 | /**
|
1721 | * @type {?}
|
1722 | * @private
|
1723 | */
|
1724 | TranslateService.prototype.isolate;
|
1725 | /**
|
1726 | * @type {?}
|
1727 | * @private
|
1728 | */
|
1729 | TranslateService.prototype.extend;
|
1730 | }
|
1731 |
|
1732 | /**
|
1733 | * @fileoverview added by tsickle
|
1734 | * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
1735 | */
|
1736 | var TranslateDirective = /** @class */ (function () {
|
1737 | function TranslateDirective(translateService, element, _ref) {
|
1738 | var _this = this;
|
1739 | this.translateService = translateService;
|
1740 | this.element = element;
|
1741 | this._ref = _ref;
|
1742 | // subscribe to onTranslationChange event, in case the translations of the current lang change
|
1743 | if (!this.onTranslationChangeSub) {
|
1744 | this.onTranslationChangeSub = this.translateService.onTranslationChange.subscribe((/**
|
1745 | * @param {?} event
|
1746 | * @return {?}
|
1747 | */
|
1748 | function (event) {
|
1749 | if (event.lang === _this.translateService.currentLang) {
|
1750 | _this.checkNodes(true, event.translations);
|
1751 | }
|
1752 | }));
|
1753 | }
|
1754 | // subscribe to onLangChange event, in case the language changes
|
1755 | if (!this.onLangChangeSub) {
|
1756 | this.onLangChangeSub = this.translateService.onLangChange.subscribe((/**
|
1757 | * @param {?} event
|
1758 | * @return {?}
|
1759 | */
|
1760 | function (event) {
|
1761 | _this.checkNodes(true, event.translations);
|
1762 | }));
|
1763 | }
|
1764 | // subscribe to onDefaultLangChange event, in case the default language changes
|
1765 | if (!this.onDefaultLangChangeSub) {
|
1766 | this.onDefaultLangChangeSub = this.translateService.onDefaultLangChange.subscribe((/**
|
1767 | * @param {?} event
|
1768 | * @return {?}
|
1769 | */
|
1770 | function (event) {
|
1771 | _this.checkNodes(true);
|
1772 | }));
|
1773 | }
|
1774 | }
|
1775 | Object.defineProperty(TranslateDirective.prototype, "translate", {
|
1776 | set: /**
|
1777 | * @param {?} key
|
1778 | * @return {?}
|
1779 | */
|
1780 | function (key) {
|
1781 | if (key) {
|
1782 | this.key = key;
|
1783 | this.checkNodes();
|
1784 | }
|
1785 | },
|
1786 | enumerable: true,
|
1787 | configurable: true
|
1788 | });
|
1789 | Object.defineProperty(TranslateDirective.prototype, "translateParams", {
|
1790 | set: /**
|
1791 | * @param {?} params
|
1792 | * @return {?}
|
1793 | */
|
1794 | function (params) {
|
1795 | if (!equals(this.currentParams, params)) {
|
1796 | this.currentParams = params;
|
1797 | this.checkNodes(true);
|
1798 | }
|
1799 | },
|
1800 | enumerable: true,
|
1801 | configurable: true
|
1802 | });
|
1803 | /**
|
1804 | * @return {?}
|
1805 | */
|
1806 | TranslateDirective.prototype.ngAfterViewChecked = /**
|
1807 | * @return {?}
|
1808 | */
|
1809 | function () {
|
1810 | this.checkNodes();
|
1811 | };
|
1812 | /**
|
1813 | * @param {?=} forceUpdate
|
1814 | * @param {?=} translations
|
1815 | * @return {?}
|
1816 | */
|
1817 | TranslateDirective.prototype.checkNodes = /**
|
1818 | * @param {?=} forceUpdate
|
1819 | * @param {?=} translations
|
1820 | * @return {?}
|
1821 | */
|
1822 | function (forceUpdate, translations) {
|
1823 | if (forceUpdate === void 0) { forceUpdate = false; }
|
1824 | /** @type {?} */
|
1825 | var nodes = this.element.nativeElement.childNodes;
|
1826 | // if the element is empty
|
1827 | if (!nodes.length) {
|
1828 | // we add the key as content
|
1829 | this.setContent(this.element.nativeElement, this.key);
|
1830 | nodes = this.element.nativeElement.childNodes;
|
1831 | }
|
1832 | for (var i = 0; i < nodes.length; ++i) {
|
1833 | /** @type {?} */
|
1834 | var node = nodes[i];
|
1835 | if (node.nodeType === 3) { // node type 3 is a text node
|
1836 | // node type 3 is a text node
|
1837 | /** @type {?} */
|
1838 | var key = void 0;
|
1839 | if (forceUpdate) {
|
1840 | node.lastKey = null;
|
1841 | }
|
1842 | if (isDefined(node.lookupKey)) {
|
1843 | key = node.lookupKey;
|
1844 | }
|
1845 | else if (this.key) {
|
1846 | key = this.key;
|
1847 | }
|
1848 | else {
|
1849 | /** @type {?} */
|
1850 | var content = this.getContent(node);
|
1851 | /** @type {?} */
|
1852 | var trimmedContent = content.trim();
|
1853 | if (trimmedContent.length) {
|
1854 | node.lookupKey = trimmedContent;
|
1855 | // we want to use the content as a key, not the translation value
|
1856 | if (content !== node.currentValue) {
|
1857 | key = trimmedContent;
|
1858 | // the content was changed from the user, we'll use it as a reference if needed
|
1859 | node.originalContent = content || node.originalContent;
|
1860 | }
|
1861 | else if (node.originalContent) { // the content seems ok, but the lang has changed
|
1862 | // the current content is the translation, not the key, use the last real content as key
|
1863 | key = node.originalContent.trim();
|
1864 | }
|
1865 | else if (content !== node.currentValue) {
|
1866 | // we want to use the content as a key, not the translation value
|
1867 | key = trimmedContent;
|
1868 | // the content was changed from the user, we'll use it as a reference if needed
|
1869 | node.originalContent = content || node.originalContent;
|
1870 | }
|
1871 | }
|
1872 | }
|
1873 | this.updateValue(key, node, translations);
|
1874 | }
|
1875 | }
|
1876 | };
|
1877 | /**
|
1878 | * @param {?} key
|
1879 | * @param {?} node
|
1880 | * @param {?} translations
|
1881 | * @return {?}
|
1882 | */
|
1883 | TranslateDirective.prototype.updateValue = /**
|
1884 | * @param {?} key
|
1885 | * @param {?} node
|
1886 | * @param {?} translations
|
1887 | * @return {?}
|
1888 | */
|
1889 | function (key, node, translations) {
|
1890 | var _this = this;
|
1891 | if (key) {
|
1892 | if (node.lastKey === key && this.lastParams === this.currentParams) {
|
1893 | return;
|
1894 | }
|
1895 | this.lastParams = this.currentParams;
|
1896 | /** @type {?} */
|
1897 | var onTranslation = (/**
|
1898 | * @param {?} res
|
1899 | * @return {?}
|
1900 | */
|
1901 | function (res) {
|
1902 | if (res !== key) {
|
1903 | node.lastKey = key;
|
1904 | }
|
1905 | if (!node.originalContent) {
|
1906 | node.originalContent = _this.getContent(node);
|
1907 | }
|
1908 | node.currentValue = isDefined(res) ? res : (node.originalContent || key);
|
1909 | // we replace in the original content to preserve spaces that we might have trimmed
|
1910 | _this.setContent(node, _this.key ? node.currentValue : node.originalContent.replace(key, node.currentValue));
|
1911 | _this._ref.markForCheck();
|
1912 | });
|
1913 | if (isDefined(translations)) {
|
1914 | /** @type {?} */
|
1915 | var res = this.translateService.getParsedResult(translations, key, this.currentParams);
|
1916 | if (rxjs.isObservable(res)) {
|
1917 | res.subscribe(onTranslation);
|
1918 | }
|
1919 | else {
|
1920 | onTranslation(res);
|
1921 | }
|
1922 | }
|
1923 | else {
|
1924 | this.translateService.get(key, this.currentParams).subscribe(onTranslation);
|
1925 | }
|
1926 | }
|
1927 | };
|
1928 | /**
|
1929 | * @param {?} node
|
1930 | * @return {?}
|
1931 | */
|
1932 | TranslateDirective.prototype.getContent = /**
|
1933 | * @param {?} node
|
1934 | * @return {?}
|
1935 | */
|
1936 | function (node) {
|
1937 | return isDefined(node.textContent) ? node.textContent : node.data;
|
1938 | };
|
1939 | /**
|
1940 | * @param {?} node
|
1941 | * @param {?} content
|
1942 | * @return {?}
|
1943 | */
|
1944 | TranslateDirective.prototype.setContent = /**
|
1945 | * @param {?} node
|
1946 | * @param {?} content
|
1947 | * @return {?}
|
1948 | */
|
1949 | function (node, content) {
|
1950 | if (isDefined(node.textContent)) {
|
1951 | node.textContent = content;
|
1952 | }
|
1953 | else {
|
1954 | node.data = content;
|
1955 | }
|
1956 | };
|
1957 | /**
|
1958 | * @return {?}
|
1959 | */
|
1960 | TranslateDirective.prototype.ngOnDestroy = /**
|
1961 | * @return {?}
|
1962 | */
|
1963 | function () {
|
1964 | if (this.onLangChangeSub) {
|
1965 | this.onLangChangeSub.unsubscribe();
|
1966 | }
|
1967 | if (this.onDefaultLangChangeSub) {
|
1968 | this.onDefaultLangChangeSub.unsubscribe();
|
1969 | }
|
1970 | if (this.onTranslationChangeSub) {
|
1971 | this.onTranslationChangeSub.unsubscribe();
|
1972 | }
|
1973 | };
|
1974 | TranslateDirective.decorators = [
|
1975 | { type: core.Directive, args: [{
|
1976 | selector: '[translate],[ngx-translate]'
|
1977 | },] }
|
1978 | ];
|
1979 | /** @nocollapse */
|
1980 | TranslateDirective.ctorParameters = function () { return [
|
1981 | { type: TranslateService },
|
1982 | { type: core.ElementRef },
|
1983 | { type: core.ChangeDetectorRef }
|
1984 | ]; };
|
1985 | TranslateDirective.propDecorators = {
|
1986 | translate: [{ type: core.Input }],
|
1987 | translateParams: [{ type: core.Input }]
|
1988 | };
|
1989 | return TranslateDirective;
|
1990 | }());
|
1991 | if (false) {
|
1992 | /** @type {?} */
|
1993 | TranslateDirective.prototype.key;
|
1994 | /** @type {?} */
|
1995 | TranslateDirective.prototype.lastParams;
|
1996 | /** @type {?} */
|
1997 | TranslateDirective.prototype.currentParams;
|
1998 | /** @type {?} */
|
1999 | TranslateDirective.prototype.onLangChangeSub;
|
2000 | /** @type {?} */
|
2001 | TranslateDirective.prototype.onDefaultLangChangeSub;
|
2002 | /** @type {?} */
|
2003 | TranslateDirective.prototype.onTranslationChangeSub;
|
2004 | /**
|
2005 | * @type {?}
|
2006 | * @private
|
2007 | */
|
2008 | TranslateDirective.prototype.translateService;
|
2009 | /**
|
2010 | * @type {?}
|
2011 | * @private
|
2012 | */
|
2013 | TranslateDirective.prototype.element;
|
2014 | /**
|
2015 | * @type {?}
|
2016 | * @private
|
2017 | */
|
2018 | TranslateDirective.prototype._ref;
|
2019 | }
|
2020 |
|
2021 | /**
|
2022 | * @fileoverview added by tsickle
|
2023 | * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
2024 | */
|
2025 | var TranslatePipe = /** @class */ (function () {
|
2026 | function TranslatePipe(translate, _ref) {
|
2027 | this.translate = translate;
|
2028 | this._ref = _ref;
|
2029 | this.value = '';
|
2030 | }
|
2031 | /**
|
2032 | * @param {?} key
|
2033 | * @param {?=} interpolateParams
|
2034 | * @param {?=} translations
|
2035 | * @return {?}
|
2036 | */
|
2037 | TranslatePipe.prototype.updateValue = /**
|
2038 | * @param {?} key
|
2039 | * @param {?=} interpolateParams
|
2040 | * @param {?=} translations
|
2041 | * @return {?}
|
2042 | */
|
2043 | function (key, interpolateParams, translations) {
|
2044 | var _this = this;
|
2045 | /** @type {?} */
|
2046 | var onTranslation = (/**
|
2047 | * @param {?} res
|
2048 | * @return {?}
|
2049 | */
|
2050 | function (res) {
|
2051 | _this.value = res !== undefined ? res : key;
|
2052 | _this.lastKey = key;
|
2053 | _this._ref.markForCheck();
|
2054 | });
|
2055 | if (translations) {
|
2056 | /** @type {?} */
|
2057 | var res = this.translate.getParsedResult(translations, key, interpolateParams);
|
2058 | if (rxjs.isObservable(res.subscribe)) {
|
2059 | res.subscribe(onTranslation);
|
2060 | }
|
2061 | else {
|
2062 | onTranslation(res);
|
2063 | }
|
2064 | }
|
2065 | this.translate.get(key, interpolateParams).subscribe(onTranslation);
|
2066 | };
|
2067 | /**
|
2068 | * @param {?} query
|
2069 | * @param {...?} args
|
2070 | * @return {?}
|
2071 | */
|
2072 | TranslatePipe.prototype.transform = /**
|
2073 | * @param {?} query
|
2074 | * @param {...?} args
|
2075 | * @return {?}
|
2076 | */
|
2077 | function (query) {
|
2078 | var _this = this;
|
2079 | var args = [];
|
2080 | for (var _i = 1; _i < arguments.length; _i++) {
|
2081 | args[_i - 1] = arguments[_i];
|
2082 | }
|
2083 | if (!query || !query.length) {
|
2084 | return query;
|
2085 | }
|
2086 | // if we ask another time for the same key, return the last value
|
2087 | if (equals(query, this.lastKey) && equals(args, this.lastParams)) {
|
2088 | return this.value;
|
2089 | }
|
2090 | /** @type {?} */
|
2091 | var interpolateParams;
|
2092 | if (isDefined(args[0]) && args.length) {
|
2093 | if (typeof args[0] === 'string' && args[0].length) {
|
2094 | // we accept objects written in the template such as {n:1}, {'n':1}, {n:'v'}
|
2095 | // which is why we might need to change it to real JSON objects such as {"n":1} or {"n":"v"}
|
2096 | /** @type {?} */
|
2097 | var validArgs = args[0]
|
2098 | .replace(/(\')?([a-zA-Z0-9_]+)(\')?(\s)?:/g, '"$2":')
|
2099 | .replace(/:(\s)?(\')(.*?)(\')/g, ':"$3"');
|
2100 | try {
|
2101 | interpolateParams = JSON.parse(validArgs);
|
2102 | }
|
2103 | catch (e) {
|
2104 | throw new SyntaxError("Wrong parameter in TranslatePipe. Expected a valid Object, received: " + args[0]);
|
2105 | }
|
2106 | }
|
2107 | else if (typeof args[0] === 'object' && !Array.isArray(args[0])) {
|
2108 | interpolateParams = args[0];
|
2109 | }
|
2110 | }
|
2111 | // store the query, in case it changes
|
2112 | this.lastKey = query;
|
2113 | // store the params, in case they change
|
2114 | this.lastParams = args;
|
2115 | // set the value
|
2116 | this.updateValue(query, interpolateParams);
|
2117 | // if there is a subscription to onLangChange, clean it
|
2118 | this._dispose();
|
2119 | // subscribe to onTranslationChange event, in case the translations change
|
2120 | if (!this.onTranslationChange) {
|
2121 | this.onTranslationChange = this.translate.onTranslationChange.subscribe((/**
|
2122 | * @param {?} event
|
2123 | * @return {?}
|
2124 | */
|
2125 | function (event) {
|
2126 | if (_this.lastKey && event.lang === _this.translate.currentLang) {
|
2127 | _this.lastKey = null;
|
2128 | _this.updateValue(query, interpolateParams, event.translations);
|
2129 | }
|
2130 | }));
|
2131 | }
|
2132 | // subscribe to onLangChange event, in case the language changes
|
2133 | if (!this.onLangChange) {
|
2134 | this.onLangChange = this.translate.onLangChange.subscribe((/**
|
2135 | * @param {?} event
|
2136 | * @return {?}
|
2137 | */
|
2138 | function (event) {
|
2139 | if (_this.lastKey) {
|
2140 | _this.lastKey = null; // we want to make sure it doesn't return the same value until it's been updated
|
2141 | _this.updateValue(query, interpolateParams, event.translations);
|
2142 | }
|
2143 | }));
|
2144 | }
|
2145 | // subscribe to onDefaultLangChange event, in case the default language changes
|
2146 | if (!this.onDefaultLangChange) {
|
2147 | this.onDefaultLangChange = this.translate.onDefaultLangChange.subscribe((/**
|
2148 | * @return {?}
|
2149 | */
|
2150 | function () {
|
2151 | if (_this.lastKey) {
|
2152 | _this.lastKey = null; // we want to make sure it doesn't return the same value until it's been updated
|
2153 | _this.updateValue(query, interpolateParams);
|
2154 | }
|
2155 | }));
|
2156 | }
|
2157 | return this.value;
|
2158 | };
|
2159 | /**
|
2160 | * Clean any existing subscription to change events
|
2161 | */
|
2162 | /**
|
2163 | * Clean any existing subscription to change events
|
2164 | * @private
|
2165 | * @return {?}
|
2166 | */
|
2167 | TranslatePipe.prototype._dispose = /**
|
2168 | * Clean any existing subscription to change events
|
2169 | * @private
|
2170 | * @return {?}
|
2171 | */
|
2172 | function () {
|
2173 | if (typeof this.onTranslationChange !== 'undefined') {
|
2174 | this.onTranslationChange.unsubscribe();
|
2175 | this.onTranslationChange = undefined;
|
2176 | }
|
2177 | if (typeof this.onLangChange !== 'undefined') {
|
2178 | this.onLangChange.unsubscribe();
|
2179 | this.onLangChange = undefined;
|
2180 | }
|
2181 | if (typeof this.onDefaultLangChange !== 'undefined') {
|
2182 | this.onDefaultLangChange.unsubscribe();
|
2183 | this.onDefaultLangChange = undefined;
|
2184 | }
|
2185 | };
|
2186 | /**
|
2187 | * @return {?}
|
2188 | */
|
2189 | TranslatePipe.prototype.ngOnDestroy = /**
|
2190 | * @return {?}
|
2191 | */
|
2192 | function () {
|
2193 | this._dispose();
|
2194 | };
|
2195 | TranslatePipe.decorators = [
|
2196 | { type: core.Injectable },
|
2197 | { type: core.Pipe, args: [{
|
2198 | name: 'translate',
|
2199 | pure: false // required to update the value when the promise is resolved
|
2200 | },] }
|
2201 | ];
|
2202 | /** @nocollapse */
|
2203 | TranslatePipe.ctorParameters = function () { return [
|
2204 | { type: TranslateService },
|
2205 | { type: core.ChangeDetectorRef }
|
2206 | ]; };
|
2207 | return TranslatePipe;
|
2208 | }());
|
2209 | if (false) {
|
2210 | /** @type {?} */
|
2211 | TranslatePipe.prototype.value;
|
2212 | /** @type {?} */
|
2213 | TranslatePipe.prototype.lastKey;
|
2214 | /** @type {?} */
|
2215 | TranslatePipe.prototype.lastParams;
|
2216 | /** @type {?} */
|
2217 | TranslatePipe.prototype.onTranslationChange;
|
2218 | /** @type {?} */
|
2219 | TranslatePipe.prototype.onLangChange;
|
2220 | /** @type {?} */
|
2221 | TranslatePipe.prototype.onDefaultLangChange;
|
2222 | /**
|
2223 | * @type {?}
|
2224 | * @private
|
2225 | */
|
2226 | TranslatePipe.prototype.translate;
|
2227 | /**
|
2228 | * @type {?}
|
2229 | * @private
|
2230 | */
|
2231 | TranslatePipe.prototype._ref;
|
2232 | }
|
2233 |
|
2234 | /**
|
2235 | * @fileoverview added by tsickle
|
2236 | * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
2237 | */
|
2238 | /**
|
2239 | * @record
|
2240 | */
|
2241 | function TranslateModuleConfig() { }
|
2242 | if (false) {
|
2243 | /** @type {?|undefined} */
|
2244 | TranslateModuleConfig.prototype.loader;
|
2245 | /** @type {?|undefined} */
|
2246 | TranslateModuleConfig.prototype.compiler;
|
2247 | /** @type {?|undefined} */
|
2248 | TranslateModuleConfig.prototype.parser;
|
2249 | /** @type {?|undefined} */
|
2250 | TranslateModuleConfig.prototype.missingTranslationHandler;
|
2251 | /** @type {?|undefined} */
|
2252 | TranslateModuleConfig.prototype.isolate;
|
2253 | /** @type {?|undefined} */
|
2254 | TranslateModuleConfig.prototype.extend;
|
2255 | /** @type {?|undefined} */
|
2256 | TranslateModuleConfig.prototype.useDefaultLang;
|
2257 | /** @type {?|undefined} */
|
2258 | TranslateModuleConfig.prototype.defaultLanguage;
|
2259 | }
|
2260 | var TranslateModule = /** @class */ (function () {
|
2261 | function TranslateModule() {
|
2262 | }
|
2263 | /**
|
2264 | * Use this method in your root module to provide the TranslateService
|
2265 | */
|
2266 | /**
|
2267 | * Use this method in your root module to provide the TranslateService
|
2268 | * @param {?=} config
|
2269 | * @return {?}
|
2270 | */
|
2271 | TranslateModule.forRoot = /**
|
2272 | * Use this method in your root module to provide the TranslateService
|
2273 | * @param {?=} config
|
2274 | * @return {?}
|
2275 | */
|
2276 | function (config) {
|
2277 | if (config === void 0) { config = {}; }
|
2278 | return {
|
2279 | ngModule: TranslateModule,
|
2280 | providers: [
|
2281 | config.loader || { provide: TranslateLoader, useClass: TranslateFakeLoader },
|
2282 | config.compiler || { provide: TranslateCompiler, useClass: TranslateFakeCompiler },
|
2283 | config.parser || { provide: TranslateParser, useClass: TranslateDefaultParser },
|
2284 | config.missingTranslationHandler || { provide: MissingTranslationHandler, useClass: FakeMissingTranslationHandler },
|
2285 | TranslateStore,
|
2286 | { provide: USE_STORE, useValue: config.isolate },
|
2287 | { provide: USE_DEFAULT_LANG, useValue: config.useDefaultLang },
|
2288 | { provide: USE_EXTEND, useValue: config.extend },
|
2289 | { provide: DEFAULT_LANGUAGE, useValue: config.defaultLanguage },
|
2290 | TranslateService
|
2291 | ]
|
2292 | };
|
2293 | };
|
2294 | /**
|
2295 | * Use this method in your other (non root) modules to import the directive/pipe
|
2296 | */
|
2297 | /**
|
2298 | * Use this method in your other (non root) modules to import the directive/pipe
|
2299 | * @param {?=} config
|
2300 | * @return {?}
|
2301 | */
|
2302 | TranslateModule.forChild = /**
|
2303 | * Use this method in your other (non root) modules to import the directive/pipe
|
2304 | * @param {?=} config
|
2305 | * @return {?}
|
2306 | */
|
2307 | function (config) {
|
2308 | if (config === void 0) { config = {}; }
|
2309 | return {
|
2310 | ngModule: TranslateModule,
|
2311 | providers: [
|
2312 | config.loader || { provide: TranslateLoader, useClass: TranslateFakeLoader },
|
2313 | config.compiler || { provide: TranslateCompiler, useClass: TranslateFakeCompiler },
|
2314 | config.parser || { provide: TranslateParser, useClass: TranslateDefaultParser },
|
2315 | config.missingTranslationHandler || { provide: MissingTranslationHandler, useClass: FakeMissingTranslationHandler },
|
2316 | { provide: USE_STORE, useValue: config.isolate },
|
2317 | { provide: USE_DEFAULT_LANG, useValue: config.useDefaultLang },
|
2318 | { provide: USE_EXTEND, useValue: config.extend },
|
2319 | { provide: DEFAULT_LANGUAGE, useValue: config.defaultLanguage },
|
2320 | TranslateService
|
2321 | ]
|
2322 | };
|
2323 | };
|
2324 | TranslateModule.decorators = [
|
2325 | { type: core.NgModule, args: [{
|
2326 | declarations: [
|
2327 | TranslatePipe,
|
2328 | TranslateDirective
|
2329 | ],
|
2330 | exports: [
|
2331 | TranslatePipe,
|
2332 | TranslateDirective
|
2333 | ]
|
2334 | },] }
|
2335 | ];
|
2336 | return TranslateModule;
|
2337 | }());
|
2338 |
|
2339 | exports.DEFAULT_LANGUAGE = DEFAULT_LANGUAGE;
|
2340 | exports.FakeMissingTranslationHandler = FakeMissingTranslationHandler;
|
2341 | exports.MissingTranslationHandler = MissingTranslationHandler;
|
2342 | exports.TranslateCompiler = TranslateCompiler;
|
2343 | exports.TranslateDefaultParser = TranslateDefaultParser;
|
2344 | exports.TranslateDirective = TranslateDirective;
|
2345 | exports.TranslateFakeCompiler = TranslateFakeCompiler;
|
2346 | exports.TranslateFakeLoader = TranslateFakeLoader;
|
2347 | exports.TranslateLoader = TranslateLoader;
|
2348 | exports.TranslateModule = TranslateModule;
|
2349 | exports.TranslateParser = TranslateParser;
|
2350 | exports.TranslatePipe = TranslatePipe;
|
2351 | exports.TranslateService = TranslateService;
|
2352 | exports.TranslateStore = TranslateStore;
|
2353 | exports.USE_DEFAULT_LANG = USE_DEFAULT_LANG;
|
2354 | exports.USE_EXTEND = USE_EXTEND;
|
2355 | exports.USE_STORE = USE_STORE;
|
2356 |
|
2357 | Object.defineProperty(exports, '__esModule', { value: true });
|
2358 |
|
2359 | })));
|
2360 | //# sourceMappingURL=ngx-translate-core.umd.js.map
|