Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tolgee/core

Package Overview
Dependencies
Maintainers
1
Versions
354
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tolgee/core - npm Package Compare versions

Comparing version 1.0.0-alpha.39 to 1.0.0-alpha.40

2

lib/services/TextService.d.ts

@@ -12,3 +12,3 @@ import { KeyAndParams, TranslationParams } from "../types";

constructor(properties: Properties, translationService: TranslationService);
translate(key: string, params: TranslationParams, lang?: string): Promise<string>;
translate(key: string, params: TranslationParams, lang?: string, orEmpty?: any): Promise<string>;
instant(key: string, params: TranslationParams, lang?: string, orEmpty?: any): string;

@@ -15,0 +15,0 @@ replace(text: string): Promise<ReplacedType>;

@@ -82,3 +82,3 @@ "use strict";

console.warn(e.message);
return e.translation;
return translation;
}

@@ -103,3 +103,3 @@ }

TextService_1 = TextService;
TextService.prototype.translate = function (key, params, lang) {
TextService.prototype.translate = function (key, params, lang, orEmpty) {
if (lang === void 0) { lang = this.properties.currentLanguage; }

@@ -112,3 +112,3 @@ return __awaiter(this, void 0, void 0, function () {

_a = this.format;
return [4 /*yield*/, this.translationService.getTranslation(key, lang)];
return [4 /*yield*/, this.translationService.getTranslation(key, lang, orEmpty)];
case 1: return [2 /*return*/, _a.apply(this, [_b.sent(), params])];

@@ -125,25 +125,32 @@ }

return __awaiter(this, void 0, void 0, function () {
var matchRegexp, keysAndParams, matched, translated, withoutEscapes;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
var matchRegexp, keysAndParams, matched, match, start, result, _a, fullMatch, pre, wrapped, unwrapped, index, input, translated, withoutEscapes;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
matchRegexp = new RegExp(this.rawUnWrapRegex, "gs");
return [4 /*yield*/, this.translationService.loadTranslations()];
case 1:
_a.sent();
keysAndParams = [];
matched = false;
translated = text.replace(matchRegexp, function (_, pre, wrapped, unwrapped, position) {
if (pre === "\\") {
if (!TextHelper_1.TextHelper.isCharEscaped(position, text)) {
return pre + wrapped;
}
}
var translated = _this.getTranslatedWithMetadata(unwrapped);
keysAndParams.push({ key: translated.key, params: translated.params });
matched = true;
return pre + translated.translated;
});
withoutEscapes = TextHelper_1.TextHelper.removeEscapes(translated);
start = 0;
result = "";
_b.label = 1;
case 1:
if (!((match = matchRegexp.exec(text)) !== null)) return [3 /*break*/, 3];
_a = __read(match, 4), fullMatch = _a[0], pre = _a[1], wrapped = _a[2], unwrapped = _a[3];
index = match.index, input = match.input;
result += input.substr(start, index - start);
start = index + fullMatch.length;
if (pre === "\\" && !TextHelper_1.TextHelper.isCharEscaped(index, text)) {
result += wrapped;
return [3 /*break*/, 1];
}
return [4 /*yield*/, this.getTranslatedWithMetadata(unwrapped)];
case 2:
translated = _b.sent();
keysAndParams.push({ key: translated.key, params: translated.params });
matched = true;
result += pre + translated.translated;
return [3 /*break*/, 1];
case 3:
result += text.substring(start);
withoutEscapes = TextHelper_1.TextHelper.removeEscapes(result);
if (matched) {

@@ -168,5 +175,15 @@ return [2 /*return*/, { text: withoutEscapes, keys: keysAndParams }];

TextService.prototype.getTranslatedWithMetadata = function (text) {
var _a = TextService_1.parseUnwrapped(text), key = _a.key, params = _a.params;
var translated = this.instant(key, params, undefined, false);
return { translated: translated, key: key, params: params };
return __awaiter(this, void 0, void 0, function () {
var _a, key, params, translated;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = TextService_1.parseUnwrapped(text), key = _a.key, params = _a.params;
return [4 /*yield*/, this.translate(key, params, undefined, false)];
case 1:
translated = _b.sent();
return [2 /*return*/, { translated: translated, key: key, params: params }];
}
});
});
};

@@ -173,0 +190,0 @@ TextService.parseUnwrapped = function (unWrappedString) {

@@ -15,3 +15,3 @@ import { TranslationData } from "../DTOs/TranslationData";

loadTranslations(lang?: string): Promise<void>;
getTranslation(key: string, lang?: string): Promise<string>;
getTranslation(key: string, lang?: string, orEmpty?: boolean): Promise<string>;
setTranslations(translationData: TranslationData): Promise<void>;

@@ -18,0 +18,0 @@ getFromCacheOrFallback(key: string, lang?: string, orEmpty?: boolean): string;

@@ -134,4 +134,5 @@ "use strict";

};
TranslationService.prototype.getTranslation = function (key, lang) {
TranslationService.prototype.getTranslation = function (key, lang, orEmpty) {
if (lang === void 0) { lang = this.properties.currentLanguage; }
if (orEmpty === void 0) { orEmpty = false; }
return __awaiter(this, void 0, void 0, function () {

@@ -156,3 +157,3 @@ var message;

_a.label = 3;
case 3: return [2 /*return*/, TranslationService_1.translationByValue(message, key, false)];
case 3: return [2 /*return*/, TranslationService_1.translationByValue(message, key, orEmpty)];
}

@@ -159,0 +160,0 @@ });

{
"name": "@tolgee/core",
"version": "1.0.0-alpha.39",
"version": "1.0.0-alpha.40",
"description": "Library providing ability to translate messages directly in context of developed application.",

@@ -65,3 +65,3 @@ "main": "dist/tolgee.umd.js",

},
"gitHead": "235c759336edd619c0350eb4c130a0fb532672bb",
"gitHead": "83c9bceaffb54c726a2c4f8498ba7b4e55041bb2",
"publishConfig": {

@@ -68,0 +68,0 @@ "access": "public"

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc