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