@tolgee/core 3.0.1 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/tolgee.cjs.js +198 -167
- package/dist/tolgee.cjs.js.map +1 -1
- package/dist/tolgee.cjs.min.js +1 -1
- package/dist/tolgee.cjs.min.js.map +1 -1
- package/dist/tolgee.esm.js +1 -1
- package/dist/tolgee.esm.js.map +1 -1
- package/dist/tolgee.umd.js +198 -167
- package/dist/tolgee.umd.js.map +1 -1
- package/dist/tolgee.umd.min.js +1 -1
- package/dist/tolgee.umd.min.js.map +1 -1
- package/lib/Tolgee.d.ts +37 -8
- package/lib/Tolgee.js +90 -66
- package/lib/Tolgee.js.map +1 -1
- package/lib/services/CoreService.d.ts +1 -0
- package/lib/services/CoreService.js +18 -0
- package/lib/services/CoreService.js.map +1 -1
- package/lib/services/TranslationService.d.ts +3 -1
- package/lib/services/TranslationService.js +38 -22
- package/lib/services/TranslationService.js.map +1 -1
- package/lib/wrappers/AbstractWrapper.d.ts +1 -1
- package/lib/wrappers/invisible/Coder.d.ts +1 -1
- package/lib/wrappers/invisible/Coder.js +18 -59
- package/lib/wrappers/invisible/Coder.js.map +1 -1
- package/lib/wrappers/invisible/InvisibleWrapper.d.ts +1 -1
- package/lib/wrappers/text/Coder.d.ts +1 -1
- package/lib/wrappers/text/Coder.js +34 -92
- package/lib/wrappers/text/Coder.js.map +1 -1
- package/lib/wrappers/text/TextWrapper.d.ts +1 -1
- package/package.json +10 -9
package/dist/tolgee.umd.js
CHANGED
|
@@ -400,6 +400,9 @@
|
|
|
400
400
|
this.eventService = eventService;
|
|
401
401
|
this.translationsCache = new Map();
|
|
402
402
|
this.fetchPromises = {};
|
|
403
|
+
// we need to distinguish which languages are in cache initially
|
|
404
|
+
// because we need to refetch them in dev mode
|
|
405
|
+
this.fetchedDev = {};
|
|
403
406
|
this.updateTranslationInCache = function (data) { return __awaiter(_this, void 0, void 0, function () {
|
|
404
407
|
var result;
|
|
405
408
|
var _this = this;
|
|
@@ -492,8 +495,7 @@
|
|
|
492
495
|
TranslationService.prototype.initStatic = function () {
|
|
493
496
|
var _this = this;
|
|
494
497
|
var _a;
|
|
495
|
-
if (this.properties.config.
|
|
496
|
-
typeof ((_a = this.properties.config) === null || _a === void 0 ? void 0 : _a.staticData) === 'object') {
|
|
498
|
+
if (typeof ((_a = this.properties.config) === null || _a === void 0 ? void 0 : _a.staticData) === 'object') {
|
|
497
499
|
Object.entries(this.properties.config.staticData).forEach(function (_a) {
|
|
498
500
|
var _b = __read(_a, 2), language = _b[0], data = _b[1];
|
|
499
501
|
//if not provider or promise then it is raw data
|
|
@@ -512,7 +514,7 @@
|
|
|
512
514
|
return __generator(this, function (_a) {
|
|
513
515
|
switch (_a.label) {
|
|
514
516
|
case 0:
|
|
515
|
-
if (!
|
|
517
|
+
if (!this.isFetchNeeded(lang)) return [3 /*break*/, 2];
|
|
516
518
|
if (!(this.fetchPromises[lang] instanceof Promise)) {
|
|
517
519
|
this.fetchPromises[lang] = this.fetchTranslations(lang);
|
|
518
520
|
}
|
|
@@ -523,7 +525,7 @@
|
|
|
523
525
|
_a.label = 2;
|
|
524
526
|
case 2:
|
|
525
527
|
this.fetchPromises[lang] = undefined;
|
|
526
|
-
return [2 /*return
|
|
528
|
+
return [2 /*return*/, this.translationsCache.get(lang)];
|
|
527
529
|
}
|
|
528
530
|
});
|
|
529
531
|
});
|
|
@@ -531,25 +533,28 @@
|
|
|
531
533
|
TranslationService.prototype.getTranslation = function (key, lang, defaultValue) {
|
|
532
534
|
if (lang === void 0) { lang = this.properties.currentLanguage; }
|
|
533
535
|
return __awaiter(this, void 0, void 0, function () {
|
|
534
|
-
var message;
|
|
536
|
+
var message, fallbackLang;
|
|
535
537
|
return __generator(this, function (_a) {
|
|
536
538
|
switch (_a.label) {
|
|
537
539
|
case 0:
|
|
538
|
-
|
|
539
|
-
if (!!message) return [3 /*break*/, 3];
|
|
540
|
+
if (!this.isFetchNeeded(lang)) return [3 /*break*/, 2];
|
|
540
541
|
return [4 /*yield*/, this.loadTranslations(lang)];
|
|
541
542
|
case 1:
|
|
542
543
|
_a.sent();
|
|
544
|
+
_a.label = 2;
|
|
545
|
+
case 2:
|
|
543
546
|
message = this.getFromCache(key, lang);
|
|
544
|
-
if (!!message) return [3 /*break*/,
|
|
545
|
-
|
|
546
|
-
if (
|
|
547
|
+
if (!!message) return [3 /*break*/, 5];
|
|
548
|
+
fallbackLang = this.properties.config.fallbackLanguage;
|
|
549
|
+
if (!this.isFetchNeeded(fallbackLang)) return [3 /*break*/, 4];
|
|
547
550
|
return [4 /*yield*/, this.loadTranslations(this.properties.config.fallbackLanguage)];
|
|
548
|
-
case
|
|
551
|
+
case 3:
|
|
549
552
|
_a.sent();
|
|
553
|
+
_a.label = 4;
|
|
554
|
+
case 4:
|
|
550
555
|
message = this.getFromCache(key, this.properties.config.fallbackLanguage);
|
|
551
|
-
_a.label =
|
|
552
|
-
case
|
|
556
|
+
_a.label = 5;
|
|
557
|
+
case 5: return [2 /*return*/, TranslationService.translationByValue(message, defaultValue)];
|
|
553
558
|
}
|
|
554
559
|
});
|
|
555
560
|
});
|
|
@@ -684,12 +689,20 @@
|
|
|
684
689
|
this.getFromCache(key, this.properties.config.fallbackLanguage);
|
|
685
690
|
return TranslationService.translationByValue(message, defaultValue);
|
|
686
691
|
};
|
|
692
|
+
TranslationService.prototype.isFetchNeeded = function (lang) {
|
|
693
|
+
var isDevMode = this.properties.config.mode === 'development';
|
|
694
|
+
var dataPresent = this.translationsCache.get(lang) !== undefined;
|
|
695
|
+
var devFetched = Boolean(this.fetchedDev[lang]);
|
|
696
|
+
return (isDevMode && !devFetched) || !dataPresent;
|
|
697
|
+
};
|
|
687
698
|
TranslationService.prototype.fetchTranslations = function (lang) {
|
|
688
699
|
return __awaiter(this, void 0, void 0, function () {
|
|
700
|
+
var isDevMode;
|
|
689
701
|
return __generator(this, function (_a) {
|
|
690
702
|
switch (_a.label) {
|
|
691
703
|
case 0:
|
|
692
|
-
|
|
704
|
+
isDevMode = this.properties.config.mode === 'development';
|
|
705
|
+
if (!isDevMode) return [3 /*break*/, 2];
|
|
693
706
|
return [4 /*yield*/, this.fetchTranslationsDevelopment(lang)];
|
|
694
707
|
case 1: return [2 /*return*/, _a.sent()];
|
|
695
708
|
case 2: return [4 /*yield*/, this.fetchTranslationsProduction(lang)];
|
|
@@ -764,23 +777,26 @@
|
|
|
764
777
|
var data, e_4;
|
|
765
778
|
return __generator(this, function (_a) {
|
|
766
779
|
switch (_a.label) {
|
|
767
|
-
case 0:
|
|
768
|
-
this.coreService.checkScope('translations.view');
|
|
769
|
-
_a.label = 1;
|
|
780
|
+
case 0: return [4 /*yield*/, this.coreService.loadApiKeyDetails()];
|
|
770
781
|
case 1:
|
|
771
|
-
_a.
|
|
772
|
-
|
|
782
|
+
_a.sent();
|
|
783
|
+
this.coreService.checkScope('translations.view');
|
|
784
|
+
_a.label = 2;
|
|
773
785
|
case 2:
|
|
786
|
+
_a.trys.push([2, 4, , 5]);
|
|
787
|
+
return [4 /*yield*/, this.apiHttpService.fetchJson("v2/projects/translations/".concat(language))];
|
|
788
|
+
case 3:
|
|
774
789
|
data = _a.sent();
|
|
790
|
+
this.fetchedDev[language] = true;
|
|
775
791
|
this.setLanguageData(language, data[language] || {});
|
|
776
|
-
return [3 /*break*/,
|
|
777
|
-
case
|
|
792
|
+
return [3 /*break*/, 5];
|
|
793
|
+
case 4:
|
|
778
794
|
e_4 = _a.sent();
|
|
779
795
|
// eslint-disable-next-line no-console
|
|
780
796
|
console.error('Error while fetching localization data from API.', e_4);
|
|
781
797
|
this.setEmptyLanguageData(language);
|
|
782
798
|
return [2 /*return*/];
|
|
783
|
-
case
|
|
799
|
+
case 5: return [2 /*return*/];
|
|
784
800
|
}
|
|
785
801
|
});
|
|
786
802
|
});
|
|
@@ -1577,6 +1593,24 @@
|
|
|
1577
1593
|
throw new Error("Api key not permitted to do this, please add 'translations.view' scope.");
|
|
1578
1594
|
}
|
|
1579
1595
|
};
|
|
1596
|
+
CoreService.prototype.loadApiKeyDetails = function () {
|
|
1597
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1598
|
+
var details;
|
|
1599
|
+
return __generator(this, function (_a) {
|
|
1600
|
+
switch (_a.label) {
|
|
1601
|
+
case 0:
|
|
1602
|
+
if (!(this.properties.scopes === undefined)) return [3 /*break*/, 2];
|
|
1603
|
+
return [4 /*yield*/, this.getApiKeyDetails()];
|
|
1604
|
+
case 1:
|
|
1605
|
+
details = _a.sent();
|
|
1606
|
+
this.properties.scopes = details.scopes;
|
|
1607
|
+
this.properties.projectId = details.projectId;
|
|
1608
|
+
_a.label = 2;
|
|
1609
|
+
case 2: return [2 /*return*/];
|
|
1610
|
+
}
|
|
1611
|
+
});
|
|
1612
|
+
});
|
|
1613
|
+
};
|
|
1580
1614
|
return CoreService;
|
|
1581
1615
|
}());
|
|
1582
1616
|
|
|
@@ -2226,51 +2260,39 @@
|
|
|
2226
2260
|
return result;
|
|
2227
2261
|
};
|
|
2228
2262
|
Coder.prototype.unwrap = function (text) {
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
result += input.substr(start, index - start);
|
|
2246
|
-
start = index + fullMatch.length;
|
|
2247
|
-
if (pre === '\\') {
|
|
2248
|
-
if (!TextHelper.isCharEscaped(index, text)) {
|
|
2249
|
-
result += wrapped;
|
|
2250
|
-
return [3 /*break*/, 1];
|
|
2251
|
-
}
|
|
2252
|
-
pre = '';
|
|
2253
|
-
}
|
|
2254
|
-
return [4 /*yield*/, this.getTranslatedWithMetadata(unwrapped)];
|
|
2255
|
-
case 2:
|
|
2256
|
-
translated = _b.sent();
|
|
2257
|
-
keysAndParams.push({
|
|
2258
|
-
key: translated.key,
|
|
2259
|
-
params: translated.params,
|
|
2260
|
-
defaultValue: translated.defaultValue,
|
|
2261
|
-
});
|
|
2262
|
-
matched = true;
|
|
2263
|
-
result += pre + translated.translated;
|
|
2264
|
-
return [3 /*break*/, 1];
|
|
2265
|
-
case 3:
|
|
2266
|
-
result += text.substring(start);
|
|
2267
|
-
if (matched) {
|
|
2268
|
-
return [2 /*return*/, { text: result, keys: keysAndParams }];
|
|
2269
|
-
}
|
|
2270
|
-
return [2 /*return*/, undefined];
|
|
2263
|
+
var matchRegexp = new RegExp(this.rawUnWrapRegex, 'gs');
|
|
2264
|
+
var keysAndParams = [];
|
|
2265
|
+
var matched = false;
|
|
2266
|
+
var match;
|
|
2267
|
+
var start = 0;
|
|
2268
|
+
var result = '';
|
|
2269
|
+
while ((match = matchRegexp.exec(text)) !== null) {
|
|
2270
|
+
var pre = match[1];
|
|
2271
|
+
var _a = __read(match, 4), fullMatch = _a[0]; _a[1]; var wrapped = _a[2], unwrapped = _a[3];
|
|
2272
|
+
var index = match.index, input = match.input;
|
|
2273
|
+
result += input.substr(start, index - start);
|
|
2274
|
+
start = index + fullMatch.length;
|
|
2275
|
+
if (pre === '\\') {
|
|
2276
|
+
if (!TextHelper.isCharEscaped(index, text)) {
|
|
2277
|
+
result += wrapped;
|
|
2278
|
+
continue;
|
|
2271
2279
|
}
|
|
2280
|
+
pre = '';
|
|
2281
|
+
}
|
|
2282
|
+
var translated = this.getTranslatedWithMetadata(unwrapped);
|
|
2283
|
+
keysAndParams.push({
|
|
2284
|
+
key: translated.key,
|
|
2285
|
+
params: translated.params,
|
|
2286
|
+
defaultValue: translated.defaultValue,
|
|
2272
2287
|
});
|
|
2273
|
-
|
|
2288
|
+
matched = true;
|
|
2289
|
+
result += pre + translated.translated;
|
|
2290
|
+
}
|
|
2291
|
+
result += text.substring(start);
|
|
2292
|
+
if (matched) {
|
|
2293
|
+
return { text: result, keys: keysAndParams };
|
|
2294
|
+
}
|
|
2295
|
+
return undefined;
|
|
2274
2296
|
};
|
|
2275
2297
|
Coder.prototype.wrap = function (key, params, defaultValue) {
|
|
2276
2298
|
var _this = this;
|
|
@@ -2287,19 +2309,9 @@
|
|
|
2287
2309
|
return "".concat(this.properties.config.inputPrefix).concat(this.escapeParam(key)).concat(defaultString).concat(paramString).concat(this.properties.config.inputSuffix);
|
|
2288
2310
|
};
|
|
2289
2311
|
Coder.prototype.getTranslatedWithMetadata = function (text) {
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
switch (_b.label) {
|
|
2294
|
-
case 0:
|
|
2295
|
-
_a = Coder.parseUnwrapped(text), key = _a.key, params = _a.params, defaultValue = _a.defaultValue;
|
|
2296
|
-
return [4 /*yield*/, this.textService.translate(key, params, undefined, false, defaultValue)];
|
|
2297
|
-
case 1:
|
|
2298
|
-
translated = _b.sent();
|
|
2299
|
-
return [2 /*return*/, { translated: translated, key: key, params: params, defaultValue: defaultValue }];
|
|
2300
|
-
}
|
|
2301
|
-
});
|
|
2302
|
-
});
|
|
2312
|
+
var _a = Coder.parseUnwrapped(text), key = _a.key, params = _a.params, defaultValue = _a.defaultValue;
|
|
2313
|
+
var translated = this.textService.instant(key, params, undefined, false, defaultValue);
|
|
2314
|
+
return { translated: translated, key: key, params: params, defaultValue: defaultValue };
|
|
2303
2315
|
};
|
|
2304
2316
|
return Coder;
|
|
2305
2317
|
}());
|
|
@@ -2734,31 +2746,26 @@
|
|
|
2734
2746
|
this.defaultMemory = new ValueMemory();
|
|
2735
2747
|
}
|
|
2736
2748
|
Coder.prototype.unwrap = function (text) {
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
key: key,
|
|
2751
|
-
params: undefined,
|
|
2752
|
-
defaultValue: defaultValue,
|
|
2753
|
-
});
|
|
2754
|
-
});
|
|
2755
|
-
result = removeSecrets(text);
|
|
2756
|
-
if (keysAndParams.length) {
|
|
2757
|
-
return [2 /*return*/, { text: result, keys: keysAndParams }];
|
|
2758
|
-
}
|
|
2759
|
-
return [2 /*return*/, undefined];
|
|
2749
|
+
var _this = this;
|
|
2750
|
+
var keysAndParams = [];
|
|
2751
|
+
var messages = decodeFromText(text);
|
|
2752
|
+
messages.forEach(function (msg) {
|
|
2753
|
+
var _a = __read(stringToCodePoints(msg), 2), keyCode = _a[0], defaultCode = _a[1];
|
|
2754
|
+
var key = _this.keyMemory.numberToValue(keyCode);
|
|
2755
|
+
var defaultValue = defaultCode !== undefined
|
|
2756
|
+
? _this.defaultMemory.numberToValue(defaultCode)
|
|
2757
|
+
: undefined;
|
|
2758
|
+
keysAndParams.push({
|
|
2759
|
+
key: key,
|
|
2760
|
+
params: undefined,
|
|
2761
|
+
defaultValue: defaultValue,
|
|
2760
2762
|
});
|
|
2761
2763
|
});
|
|
2764
|
+
var result = removeSecrets(text);
|
|
2765
|
+
if (keysAndParams.length) {
|
|
2766
|
+
return { text: result, keys: keysAndParams };
|
|
2767
|
+
}
|
|
2768
|
+
return undefined;
|
|
2762
2769
|
};
|
|
2763
2770
|
Coder.prototype.wrap = function (key, _params, defaultValue, translation) {
|
|
2764
2771
|
if (defaultValue === void 0) { defaultValue = undefined; }
|
|
@@ -2906,20 +2913,6 @@
|
|
|
2906
2913
|
};
|
|
2907
2914
|
this.dependencyService = new DependencyService();
|
|
2908
2915
|
}
|
|
2909
|
-
Tolgee.use = function (module) {
|
|
2910
|
-
return new Tolgee().use(module);
|
|
2911
|
-
};
|
|
2912
|
-
Tolgee.init = function (config) {
|
|
2913
|
-
return new Tolgee().init(config);
|
|
2914
|
-
};
|
|
2915
|
-
Tolgee.prototype.use = function (module) {
|
|
2916
|
-
this.dependencyService.moduleService.addModule(module);
|
|
2917
|
-
return this;
|
|
2918
|
-
};
|
|
2919
|
-
Tolgee.prototype.init = function (config) {
|
|
2920
|
-
this.dependencyService.init(config);
|
|
2921
|
-
return this;
|
|
2922
|
-
};
|
|
2923
2916
|
Object.defineProperty(Tolgee.prototype, "properties", {
|
|
2924
2917
|
get: function () {
|
|
2925
2918
|
return this.dependencyService.properties;
|
|
@@ -2927,28 +2920,26 @@
|
|
|
2927
2920
|
enumerable: false,
|
|
2928
2921
|
configurable: true
|
|
2929
2922
|
});
|
|
2930
|
-
Object.defineProperty(Tolgee.prototype, "translationService", {
|
|
2931
|
-
get: function () {
|
|
2932
|
-
return this.dependencyService.translationService;
|
|
2933
|
-
},
|
|
2934
|
-
enumerable: false,
|
|
2935
|
-
configurable: true
|
|
2936
|
-
});
|
|
2937
|
-
Object.defineProperty(Tolgee.prototype, "coreService", {
|
|
2938
|
-
get: function () {
|
|
2939
|
-
return this.dependencyService.coreService;
|
|
2940
|
-
},
|
|
2941
|
-
enumerable: false,
|
|
2942
|
-
configurable: true
|
|
2943
|
-
});
|
|
2944
2923
|
Object.defineProperty(Tolgee.prototype, "lang", {
|
|
2945
2924
|
get: function () {
|
|
2946
2925
|
return this.properties.currentLanguage;
|
|
2947
2926
|
},
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2927
|
+
/**
|
|
2928
|
+
* This sets a new language.
|
|
2929
|
+
*
|
|
2930
|
+
* Using this setter can behave buggy when you change languages
|
|
2931
|
+
* too fast, since it changes the language property before
|
|
2932
|
+
* translations are actually loaded.
|
|
2933
|
+
* @deprecated use asynchronous changeLanguage method.
|
|
2934
|
+
*/
|
|
2935
|
+
set: function (newLanguage) {
|
|
2936
|
+
var _this = this;
|
|
2937
|
+
this.properties.currentLanguage = newLanguage;
|
|
2938
|
+
this.dependencyService.translationService
|
|
2939
|
+
.loadTranslations(newLanguage)
|
|
2940
|
+
.then(function () {
|
|
2941
|
+
_this.emitLangChangeEvent(newLanguage);
|
|
2942
|
+
});
|
|
2952
2943
|
},
|
|
2953
2944
|
enumerable: false,
|
|
2954
2945
|
configurable: true
|
|
@@ -2975,6 +2966,10 @@
|
|
|
2975
2966
|
configurable: true
|
|
2976
2967
|
});
|
|
2977
2968
|
Object.defineProperty(Tolgee.prototype, "onLangLoaded", {
|
|
2969
|
+
/**
|
|
2970
|
+
* Is emitted when language translations are loaded for the first time.
|
|
2971
|
+
* It is not emitted when language is changed and translations were loaded before.
|
|
2972
|
+
*/
|
|
2978
2973
|
get: function () {
|
|
2979
2974
|
return this.dependencyService.eventService.LANGUAGE_LOADED;
|
|
2980
2975
|
},
|
|
@@ -2989,23 +2984,63 @@
|
|
|
2989
2984
|
* fetching so initial loading is not needed at all.
|
|
2990
2985
|
*/
|
|
2991
2986
|
get: function () {
|
|
2992
|
-
var _a, _b
|
|
2993
|
-
if (((_b = (_a = this.properties) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.mode) !== 'production') {
|
|
2994
|
-
return true;
|
|
2995
|
-
}
|
|
2987
|
+
var _a, _b;
|
|
2996
2988
|
var currentLang = this.properties.currentLanguage;
|
|
2997
2989
|
var fallbackLang = this.properties.config.fallbackLanguage;
|
|
2998
2990
|
var fallbackPreloading = this.properties.config.preloadFallback;
|
|
2999
2991
|
var isStaticDataProvided = function (data) {
|
|
3000
2992
|
return data !== undefined && typeof data !== 'function';
|
|
3001
2993
|
};
|
|
3002
|
-
return (!isStaticDataProvided((
|
|
2994
|
+
return (!isStaticDataProvided((_a = this.properties.config.staticData) === null || _a === void 0 ? void 0 : _a[currentLang]) ||
|
|
3003
2995
|
(!!fallbackPreloading &&
|
|
3004
|
-
!isStaticDataProvided((
|
|
2996
|
+
!isStaticDataProvided((_b = this.properties.config.staticData) === null || _b === void 0 ? void 0 : _b[fallbackLang])));
|
|
3005
2997
|
},
|
|
3006
2998
|
enumerable: false,
|
|
3007
2999
|
configurable: true
|
|
3008
3000
|
});
|
|
3001
|
+
Object.defineProperty(Tolgee.prototype, "coreService", {
|
|
3002
|
+
get: function () {
|
|
3003
|
+
return this.dependencyService.coreService;
|
|
3004
|
+
},
|
|
3005
|
+
enumerable: false,
|
|
3006
|
+
configurable: true
|
|
3007
|
+
});
|
|
3008
|
+
Tolgee.use = function (module) {
|
|
3009
|
+
return new Tolgee().use(module);
|
|
3010
|
+
};
|
|
3011
|
+
Tolgee.init = function (config) {
|
|
3012
|
+
return new Tolgee().init(config);
|
|
3013
|
+
};
|
|
3014
|
+
/**
|
|
3015
|
+
* Sets the new language.
|
|
3016
|
+
*
|
|
3017
|
+
* Emits the onLangChange and onLangChangeAndLoad events after
|
|
3018
|
+
* the translations are loaded.
|
|
3019
|
+
*
|
|
3020
|
+
* @return Promise<void> Resolves when translations are loaded
|
|
3021
|
+
*/
|
|
3022
|
+
Tolgee.prototype.changeLanguage = function (newLanguage) {
|
|
3023
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3024
|
+
return __generator(this, function (_a) {
|
|
3025
|
+
switch (_a.label) {
|
|
3026
|
+
case 0: return [4 /*yield*/, this.dependencyService.translationService.loadTranslations(newLanguage)];
|
|
3027
|
+
case 1:
|
|
3028
|
+
_a.sent();
|
|
3029
|
+
this.properties.currentLanguage = newLanguage;
|
|
3030
|
+
this.emitLangChangeEvent(newLanguage);
|
|
3031
|
+
return [2 /*return*/];
|
|
3032
|
+
}
|
|
3033
|
+
});
|
|
3034
|
+
});
|
|
3035
|
+
};
|
|
3036
|
+
Tolgee.prototype.use = function (module) {
|
|
3037
|
+
this.dependencyService.moduleService.addModule(module);
|
|
3038
|
+
return this;
|
|
3039
|
+
};
|
|
3040
|
+
Tolgee.prototype.init = function (config) {
|
|
3041
|
+
this.dependencyService.init(config);
|
|
3042
|
+
return this;
|
|
3043
|
+
};
|
|
3009
3044
|
Tolgee.prototype.run = function () {
|
|
3010
3045
|
return __awaiter(this, void 0, void 0, function () {
|
|
3011
3046
|
return __generator(this, function (_a) {
|
|
@@ -3013,18 +3048,18 @@
|
|
|
3013
3048
|
case 0:
|
|
3014
3049
|
this.dependencyService.run();
|
|
3015
3050
|
if (!(this.properties.config.mode === 'development')) return [3 /*break*/, 2];
|
|
3016
|
-
return [4 /*yield*/, this.loadApiKeyDetails()];
|
|
3051
|
+
return [4 /*yield*/, this.coreService.loadApiKeyDetails()];
|
|
3017
3052
|
case 1:
|
|
3018
3053
|
_a.sent();
|
|
3019
3054
|
_a.label = 2;
|
|
3020
|
-
case 2: return [4 /*yield*/, this.translationService.loadTranslations()];
|
|
3055
|
+
case 2: return [4 /*yield*/, this.dependencyService.translationService.loadTranslations()];
|
|
3021
3056
|
case 3:
|
|
3022
3057
|
_a.sent();
|
|
3023
3058
|
return [4 /*yield*/, this.dependencyService.pluginManager.run()];
|
|
3024
3059
|
case 4:
|
|
3025
3060
|
_a.sent();
|
|
3026
3061
|
if (!this.properties.config.preloadFallback) return [3 /*break*/, 6];
|
|
3027
|
-
return [4 /*yield*/, this.translationService.loadTranslations(this.properties.config.fallbackLanguage)];
|
|
3062
|
+
return [4 /*yield*/, this.dependencyService.translationService.loadTranslations(this.properties.config.fallbackLanguage)];
|
|
3028
3063
|
case 5:
|
|
3029
3064
|
_a.sent();
|
|
3030
3065
|
_a.label = 6;
|
|
@@ -3067,18 +3102,15 @@
|
|
|
3067
3102
|
props.defaultValue !== undefined ? props.defaultValue : defaultValue;
|
|
3068
3103
|
orEmpty = props.orEmpty;
|
|
3069
3104
|
}
|
|
3070
|
-
|
|
3071
|
-
return [4 /*yield*/, this.loadApiKeyDetails()];
|
|
3105
|
+
return [4 /*yield*/, this.dependencyService.textService.translate(key, params, undefined, orEmpty, defaultValue)];
|
|
3072
3106
|
case 1:
|
|
3073
|
-
_a.sent();
|
|
3074
|
-
return [
|
|
3107
|
+
translation = _a.sent();
|
|
3108
|
+
if (!(this.properties.config.mode === 'development' && !noWrap)) return [3 /*break*/, 3];
|
|
3109
|
+
return [4 /*yield*/, this.coreService.loadApiKeyDetails()];
|
|
3075
3110
|
case 2:
|
|
3076
3111
|
_a.sent();
|
|
3077
|
-
return [4 /*yield*/, this.dependencyService.textService.translate(key, params, undefined, orEmpty, defaultValue)];
|
|
3078
|
-
case 3:
|
|
3079
|
-
translation = _a.sent();
|
|
3080
3112
|
return [2 /*return*/, this.dependencyService.wrapper.wrap(key, params, defaultValue, translation)];
|
|
3081
|
-
case
|
|
3113
|
+
case 3: return [2 /*return*/, translation];
|
|
3082
3114
|
}
|
|
3083
3115
|
});
|
|
3084
3116
|
});
|
|
@@ -3111,23 +3143,22 @@
|
|
|
3111
3143
|
}
|
|
3112
3144
|
return translation;
|
|
3113
3145
|
};
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
});
|
|
3146
|
+
/**
|
|
3147
|
+
* Get currently cached translations for all languages
|
|
3148
|
+
*/
|
|
3149
|
+
Tolgee.prototype.getCachedTranslations = function () {
|
|
3150
|
+
return this.dependencyService.translationService.getCachedTranslations();
|
|
3151
|
+
};
|
|
3152
|
+
/**
|
|
3153
|
+
* Loads translations for given language or returns them from cache
|
|
3154
|
+
* @returns Loaded translations
|
|
3155
|
+
*/
|
|
3156
|
+
Tolgee.prototype.loadTranslations = function (lang) {
|
|
3157
|
+
return this.dependencyService.translationService.loadTranslations(lang);
|
|
3158
|
+
};
|
|
3159
|
+
Tolgee.prototype.emitLangChangeEvent = function (value) {
|
|
3160
|
+
var langChangedEmitter = this.onLangChange;
|
|
3161
|
+
langChangedEmitter.emit(value);
|
|
3131
3162
|
};
|
|
3132
3163
|
return Tolgee;
|
|
3133
3164
|
}());
|