auto-translate-json-library 1.2.7 → 1.2.9

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.
Files changed (56) hide show
  1. package/.vscode/settings.json +5 -0
  2. package/biome.json +19 -0
  3. package/build/package.json +68 -0
  4. package/build/src/README.MD +141 -0
  5. package/build/src/package.json +68 -0
  6. package/package.json +66 -66
  7. package/src/aws.ts +133 -0
  8. package/src/azure.ts +169 -0
  9. package/src/cli.ts +156 -0
  10. package/src/config.ts +40 -0
  11. package/src/deepl.ts +80 -0
  12. package/src/files.ts +82 -0
  13. package/src/folderFiles.ts +50 -0
  14. package/src/google.ts +62 -0
  15. package/src/index.ts +159 -0
  16. package/src/lib.ts +219 -0
  17. package/src/openai.ts +167 -0
  18. package/src/translate.interface.ts +13 -0
  19. package/src/util.ts +57 -0
  20. package/tests/translations/en.json +22 -0
  21. package/tests/translations/es.json +0 -0
  22. package/tests/translations/fr.json +21 -0
  23. package/tests/translations/sr.json +21 -0
  24. package/tests/translations-folder/de/common.json +9 -0
  25. package/tests/translations-folder/de/settings.json +3 -0
  26. package/tests/translations-folder/en/common.json +9 -0
  27. package/tests/translations-folder/en/settings.json +3 -0
  28. package/tsconfig.json +104 -0
  29. package/bin/cli.js +0 -2
  30. /package/{README.md → README.MD} +0 -0
  31. /package/{aws.d.ts → build/src/aws.d.ts} +0 -0
  32. /package/{aws.js → build/src/aws.js} +0 -0
  33. /package/{azure.d.ts → build/src/azure.d.ts} +0 -0
  34. /package/{azure.js → build/src/azure.js} +0 -0
  35. /package/{cli.d.ts → build/src/cli.d.ts} +0 -0
  36. /package/{cli.js → build/src/cli.js} +0 -0
  37. /package/{config.d.ts → build/src/config.d.ts} +0 -0
  38. /package/{config.js → build/src/config.js} +0 -0
  39. /package/{deepl.d.ts → build/src/deepl.d.ts} +0 -0
  40. /package/{deepl.js → build/src/deepl.js} +0 -0
  41. /package/{files.d.ts → build/src/files.d.ts} +0 -0
  42. /package/{files.js → build/src/files.js} +0 -0
  43. /package/{folderFiles.d.ts → build/src/folderFiles.d.ts} +0 -0
  44. /package/{folderFiles.js → build/src/folderFiles.js} +0 -0
  45. /package/{google.d.ts → build/src/google.d.ts} +0 -0
  46. /package/{google.js → build/src/google.js} +0 -0
  47. /package/{index.d.ts → build/src/index.d.ts} +0 -0
  48. /package/{index.js → build/src/index.js} +0 -0
  49. /package/{lib.d.ts → build/src/lib.d.ts} +0 -0
  50. /package/{lib.js → build/src/lib.js} +0 -0
  51. /package/{openai.d.ts → build/src/openai.d.ts} +0 -0
  52. /package/{openai.js → build/src/openai.js} +0 -0
  53. /package/{translate.interface.d.ts → build/src/translate.interface.d.ts} +0 -0
  54. /package/{translate.interface.js → build/src/translate.interface.js} +0 -0
  55. /package/{util.d.ts → build/src/util.d.ts} +0 -0
  56. /package/{util.js → build/src/util.js} +0 -0
package/src/index.ts ADDED
@@ -0,0 +1,159 @@
1
+ import { Configuration } from "./config";
2
+ import { translate } from "./lib";
3
+
4
+ export { Configuration, translate };
5
+
6
+ const config: Configuration = {} as Configuration;
7
+
8
+ setDefaultConfiguration();
9
+ setConfigurationFromEnvironment();
10
+ setConfigurationFromCLI();
11
+ console.log(config);
12
+
13
+ function setConfigurationFromCLI() {
14
+ const argv = require("yargs").argv;
15
+
16
+ if (argv.mode === "file") {
17
+ config.mode = "file";
18
+ } else if (argv.mode === "folder") {
19
+ config.mode = "folder";
20
+ }
21
+
22
+ if (argv.startDelimiter !== undefined) {
23
+ config.startDelimiter = argv.startDelimiter;
24
+ }
25
+
26
+ if (argv.endDelimiter !== undefined) {
27
+ config.endDelimiter = argv.endDelimiter;
28
+ }
29
+
30
+ if (argv.keepExtraTranslations === "keep") {
31
+ config.keepExtraTranslations = "keep";
32
+ } else if (argv.keepExtraTranslations === "remove") {
33
+ config.keepExtraTranslations = "remove";
34
+ }
35
+
36
+ if (argv.keepTranslations === "keep") {
37
+ config.keepTranslations = "keep";
38
+ } else if (argv.keepTranslations === "retranslate") {
39
+ config.keepTranslations = "retranslate";
40
+ }
41
+
42
+ if (argv.sourceLocale !== undefined) {
43
+ config.sourceLocale = argv.sourceLocale;
44
+ }
45
+
46
+ if (argv.ignorePrefix !== undefined) {
47
+ config.ignorePrefix = argv.ignorePrefix;
48
+ }
49
+
50
+ if (argv.pivotTranslation !== undefined) {
51
+ translate(argv.pivotTranslation, config);
52
+ } else {
53
+ console.log(argv);
54
+ console.log("Please provide a pivot translation");
55
+ }
56
+ }
57
+
58
+ function setDefaultConfiguration() {
59
+ config.mode = "file";
60
+ config.startDelimiter = "{";
61
+ config.endDelimiter = "}";
62
+ config.keepExtraTranslations = "keep";
63
+ config.keepTranslations = "keep";
64
+ config.sourceLocale = "en";
65
+ config.ignorePrefix = "";
66
+ }
67
+
68
+ function setConfigurationFromEnvironment() {
69
+ require("dotenv").config();
70
+ if (process.env.ATJ_GOOGLE_API_KEY) {
71
+ config.translationKeyInfo = {
72
+ kind: "google",
73
+ apiKey: process.env.ATJ_GOOGLE_API_KEY,
74
+ };
75
+ }
76
+ if (
77
+ process.env.ATJ_AWS_ACCESS_KEY_ID &&
78
+ process.env.ATJ_AWS_SECRET_ACCESS_KEY &&
79
+ process.env.ATJ_AWS_REGION
80
+ ) {
81
+ config.translationKeyInfo = {
82
+ kind: "aws",
83
+ accessKeyId: process.env.ATJ_AWS_ACCESS_KEY_ID,
84
+ secretAccessKey: process.env.ATJ_AWS_SECRET_ACCESS_KEY,
85
+ region: process.env.ATJ_AWS_REGION,
86
+ };
87
+ }
88
+ if (process.env.ATJ_AZURE_SECRET_KEY && process.env.ATJ_AZURE_REGION) {
89
+ config.translationKeyInfo = {
90
+ kind: "azure",
91
+ secretKey: process.env.ATJ_AZURE_SECRET_KEY,
92
+ region: process.env.ATJ_AZURE_REGION,
93
+ };
94
+ }
95
+
96
+ if (process.env.ATJ_DEEPL_PRO_SECRET_KEY) {
97
+ config.translationKeyInfo = {
98
+ kind: "deepLPro",
99
+ secretKey: process.env.ATJ_DEEPL_PRO_SECRET_KEY,
100
+ };
101
+ }
102
+
103
+ if (process.env.ATJ_DEEPL_FREE_SECRET_KEY) {
104
+ config.translationKeyInfo = {
105
+ kind: "deepLFree",
106
+ secretKey: process.env.ATJ_DEEPL_FREE_SECRET_KEY,
107
+ };
108
+ }
109
+
110
+ if (process.env.ATJ_OPEN_AI_SECRET_KEY) {
111
+ config.translationKeyInfo = {
112
+ kind: "openai",
113
+ apiKey: process.env.ATJ_OPEN_AI_SECRET_KEY,
114
+ };
115
+ }
116
+
117
+ if (process.env.ATJ_START_DELIMITER) {
118
+ config.startDelimiter = process.env.ATJ_START_DELIMITER;
119
+ }
120
+
121
+ if (process.env.ATJ_END_DELIMITER) {
122
+ config.endDelimiter = process.env.ATJ_END_DELIMITER;
123
+ }
124
+
125
+ if (process.env.ATJ_END_DELIMITER) {
126
+ config.endDelimiter = process.env.ATJ_END_DELIMITER;
127
+ }
128
+
129
+ if (
130
+ process.env.ATJ_MODE &&
131
+ (process.env.ATJ_MODE === "file" || process.env.ATJ_MODE === "folder")
132
+ ) {
133
+ config.mode = process.env.ATJ_MODE;
134
+ }
135
+
136
+ if (process.env.ATJ_SOURCE_LOCALE) {
137
+ config.sourceLocale = process.env.ATJ_SOURCE_LOCALE;
138
+ }
139
+
140
+ if (
141
+ process.env.ATJ_KEEP_TRANSLATIONS &&
142
+ (process.env.ATJ_KEEP_TRANSLATIONS === "keep" ||
143
+ process.env.ATJ_KEEP_TRANSLATIONS === "retranslate")
144
+ ) {
145
+ config.keepTranslations = process.env.ATJ_KEEP_TRANSLATIONS;
146
+ }
147
+
148
+ if (
149
+ process.env.ATJ_KEEP_EXTRA_TRANSLATIONS &&
150
+ (process.env.ATJ_KEEP_EXTRA_TRANSLATIONS === "keep" ||
151
+ process.env.ATJ_KEEP_EXTRA_TRANSLATIONS === "remove")
152
+ ) {
153
+ config.keepExtraTranslations = process.env.ATJ_KEEP_EXTRA_TRANSLATIONS;
154
+ }
155
+
156
+ if (process.env.ATJ_IGNORE_PREFIX && process.env.ATJ_IGNORE_PREFIX !== "") {
157
+ config.ignorePrefix = process.env.ATJ_IGNORE_PREFIX;
158
+ }
159
+ }
package/src/lib.ts ADDED
@@ -0,0 +1,219 @@
1
+ // The module 'vscode' contains the VS Code extensibility API
2
+ // Import the module and reference it with the alias vscode in your code below
3
+ import { Files, IFiles } from "./files";
4
+ import { FolderFiles } from "./folderFiles";
5
+
6
+ import { AWSTranslate } from "./aws";
7
+ import { AzureTranslate } from "./azure";
8
+ import { Configuration } from "./config";
9
+ import { DeepLTranslate } from "./deepl";
10
+ import { GoogleTranslate } from "./google";
11
+ import { OpenAITranslate } from "./openai";
12
+ import { ITranslate, TranslationFile } from "./translate.interface";
13
+ import { Util } from "./util";
14
+
15
+ export async function translate(
16
+ sourceFile: string,
17
+ config: Configuration,
18
+ ): Promise<void> {
19
+ // set the delimiters for named arguments
20
+ const startDelimiter = config.startDelimiter || "{";
21
+ if (startDelimiter) {
22
+ Util.startDelimiter = startDelimiter;
23
+ }
24
+
25
+ const endDelimiter = config.endDelimiter || "}";
26
+ if (endDelimiter) {
27
+ Util.endDelimiter = endDelimiter;
28
+ }
29
+
30
+ let translateEngine: ITranslate;
31
+
32
+ if (config.translationKeyInfo.kind === "google") {
33
+ translateEngine = await GoogleTranslate.initialize(
34
+ config.translationKeyInfo.apiKey,
35
+ );
36
+ } else if (config.translationKeyInfo.kind === "aws") {
37
+ translateEngine = new AWSTranslate(
38
+ config.translationKeyInfo.accessKeyId,
39
+ config.translationKeyInfo.secretAccessKey,
40
+ config.translationKeyInfo.region,
41
+ );
42
+ } else if (config.translationKeyInfo.kind === "azure") {
43
+ translateEngine = new AzureTranslate(
44
+ config.translationKeyInfo.secretKey,
45
+ config.translationKeyInfo.region,
46
+ );
47
+ } else if (config.translationKeyInfo.kind === "deepLFree") {
48
+ translateEngine = new DeepLTranslate(
49
+ config.translationKeyInfo.secretKey,
50
+ "free",
51
+ );
52
+ } else if (config.translationKeyInfo.kind === "deepLPro") {
53
+ translateEngine = new DeepLTranslate(
54
+ config.translationKeyInfo.secretKey,
55
+ "pro",
56
+ );
57
+ } else if (config.translationKeyInfo.kind === "openai") {
58
+ translateEngine = new OpenAITranslate(config.translationKeyInfo.apiKey);
59
+ } else {
60
+ console.warn(
61
+ "You must provide a Google, AWS, Azure, deepL, openai parameters first in the extension settings.",
62
+ );
63
+ return;
64
+ }
65
+
66
+ const fileMode = config.mode;
67
+ const files = readFiles(sourceFile, fileMode);
68
+ if (files === null) {
69
+ return;
70
+ }
71
+
72
+ // enforce source locale if provided in settings
73
+ if (config.sourceLocale !== files.sourceLocale) {
74
+ console.log(
75
+ `You must use the ${config.sourceLocale}.json file due to your Source Locale setting.`,
76
+ );
77
+ return;
78
+ }
79
+
80
+ const keepTranslations = config.keepTranslations === "keep";
81
+ const keepExtras = config.keepExtraTranslations === "keep";
82
+
83
+ // load source JSON
84
+ let source: TranslationFile;
85
+ try {
86
+ source = await files.loadJsonFromLocale(files.sourceLocale);
87
+ } catch (error) {
88
+ if (error instanceof Error) {
89
+ console.log(error, "Source file malformed");
90
+ }
91
+ return;
92
+ }
93
+
94
+ // Iterate target Locales
95
+ files.targetLocales.forEach(async (targetLocale, _index, _array) => {
96
+ try {
97
+ const isValid = await translateEngine.isValidLocale(targetLocale);
98
+ if (!isValid) {
99
+ throw Error(`${targetLocale} is not supported. Skipping.`);
100
+ }
101
+
102
+ const targetOriginal = await files.loadJsonFromLocale(targetLocale);
103
+
104
+ // Iterate source terms
105
+ const targetNew = await recurseNode(
106
+ source,
107
+ targetOriginal,
108
+ keepTranslations,
109
+ keepExtras,
110
+ files.sourceLocale,
111
+ targetLocale,
112
+ translateEngine,
113
+ config.ignorePrefix,
114
+ );
115
+
116
+ // save target
117
+ files.saveJsonToLocale(targetLocale, targetNew);
118
+
119
+ const feedback = `Translated locale '${targetLocale}'`;
120
+ console.log(feedback);
121
+ } catch (error) {
122
+ if (error instanceof Error) {
123
+ console.error(error);
124
+ }
125
+ return;
126
+ }
127
+ });
128
+ }
129
+
130
+ const readFiles: (filePath: string, mode: "file" | "folder") => IFiles | null =
131
+ (filePath: string, mode: string) => {
132
+ try {
133
+ const files: IFiles =
134
+ mode === "file" ? new Files(filePath) : new FolderFiles(filePath);
135
+
136
+ // log locale info
137
+ console.log(`Source locale = ${files.sourceLocale}`);
138
+ console.log(`Target locales = ${files.targetLocales}`);
139
+
140
+ return files;
141
+ } catch (error) {
142
+ if (error instanceof Error) {
143
+ console.error(error);
144
+ }
145
+ return null;
146
+ }
147
+ };
148
+
149
+ async function recurseNode(
150
+ source: TranslationFile,
151
+ original: TranslationFile,
152
+ keepTranslations: boolean | null,
153
+ keepExtras: boolean | null,
154
+ sourceLocale: string,
155
+ locale: string,
156
+ translateEngine: ITranslate,
157
+ ignorePrefix = "",
158
+ isArray = false,
159
+ ): Promise<TranslationFile> {
160
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
161
+ const destination: any = isArray ? [] : {};
162
+
163
+ // defaults
164
+ if (keepTranslations === null) {
165
+ keepTranslations = true;
166
+ }
167
+ if (keepExtras === null) {
168
+ keepExtras = true;
169
+ }
170
+
171
+ for (const term in source) {
172
+ const node = source[term];
173
+
174
+ if (node instanceof Object && node !== null) {
175
+ destination[term] = await recurseNode(
176
+ node,
177
+ original[term] ?? {},
178
+ keepTranslations,
179
+ keepExtras,
180
+ sourceLocale,
181
+ locale,
182
+ translateEngine,
183
+ ignorePrefix,
184
+ node instanceof Array,
185
+ );
186
+ } else {
187
+ // if we already have a translation, keep it
188
+ if (keepTranslations && original[term]) {
189
+ destination[term] = original[term];
190
+ } else if (typeof node === "number" || typeof node === "boolean") {
191
+ // numbers and booleans do not need translations
192
+ destination[term] = node;
193
+ } else {
194
+ if (
195
+ ignorePrefix === "" ||
196
+ (ignorePrefix !== "" && !term.startsWith(ignorePrefix))
197
+ ) {
198
+ const translation = await translateEngine
199
+ .translateText(node, sourceLocale, locale)
200
+ .catch((err) => console.error(err));
201
+ destination[term] = translation;
202
+ } else {
203
+ delete destination[term];
204
+ }
205
+ }
206
+ }
207
+ }
208
+
209
+ if (keepExtras) {
210
+ // add back in any terms that were not in source
211
+ for (const term in original) {
212
+ if (!destination[term]) {
213
+ destination[term] = original[term];
214
+ }
215
+ }
216
+ }
217
+
218
+ return destination;
219
+ }
package/src/openai.ts ADDED
@@ -0,0 +1,167 @@
1
+ import { OpenAI } from "openai";
2
+ import { ITranslate } from "./translate.interface";
3
+ import { Util } from "./util";
4
+
5
+ const supportedLanguages: { [key: string]: string } = {
6
+ af: "Afrikaans",
7
+ sq: "Albanian",
8
+ am: "Amharic",
9
+ ar: "Arabic",
10
+ hy: "Armenian",
11
+ az: "Azerbaijani",
12
+ eu: "Basque",
13
+ be: "Belarusian",
14
+ bn: "Bengali",
15
+ bs: "Bosnian",
16
+ bg: "Bulgarian",
17
+ ca: "Catalan",
18
+ ceb: "Cebuano",
19
+ "zh-CN": "Chinese (Simplified)",
20
+ "zh-TW": "Chinese (Traditional)",
21
+ co: "Corsican",
22
+ hr: "Croatian",
23
+ cs: "Czech",
24
+ da: "Danish",
25
+ nl: "Dutch",
26
+ en: "English",
27
+ eo: "Esperanto",
28
+ et: "Estonian",
29
+ fi: "Finnish",
30
+ fr: "French",
31
+ fy: "Frisian",
32
+ gl: "Galician",
33
+ ka: "Georgian",
34
+ de: "German",
35
+ el: "Greek",
36
+ gu: "Gujarati",
37
+ ht: "Haitian Creole",
38
+ ha: "Hausa",
39
+ haw: "Hawaiian",
40
+ he: "Hebrew",
41
+ hi: "Hindi",
42
+ hmn: "Hmong",
43
+ hu: "Hungarian",
44
+ is: "Icelandic",
45
+ ig: "Igbo",
46
+ id: "Indonesian",
47
+ ga: "Irish",
48
+ it: "Italian",
49
+ ja: "Japanese",
50
+ jv: "Javanese",
51
+ kn: "Kannada",
52
+ kk: "Kazakh",
53
+ km: "Khmer",
54
+ ko: "Korean",
55
+ ku: "Kurdish",
56
+ ky: "Kyrgyz",
57
+ lo: "Lao",
58
+ la: "Latin",
59
+ lv: "Latvian",
60
+ lt: "Lithuanian",
61
+ lb: "Luxembourgish",
62
+ mk: "Macedonian",
63
+ mg: "Malagasy",
64
+ ms: "Malay",
65
+ ml: "Malayalam",
66
+ mt: "Maltese",
67
+ mi: "Maori",
68
+ mr: "Marathi",
69
+ mn: "Mongolian",
70
+ my: "Myanmar (Burmese)",
71
+ ne: "Nepali",
72
+ no: "Norwegian",
73
+ ny: "Nyanja (Chichewa)",
74
+ or: "Odia (Oriya)",
75
+ ps: "Pashto",
76
+ fa: "Persian",
77
+ pl: "Polish",
78
+ pt: "Portuguese",
79
+ pa: "Punjabi",
80
+ ro: "Romanian",
81
+ ru: "Russian",
82
+ sm: "Samoan",
83
+ gd: "Scots Gaelic",
84
+ sr: "Serbian",
85
+ st: "Sesotho",
86
+ sn: "Shona",
87
+ sd: "Sindhi",
88
+ si: "Sinhala (Sinhalese)",
89
+ sk: "Slovak",
90
+ sl: "Slovenian",
91
+ so: "Somali",
92
+ es: "Spanish",
93
+ su: "Sundanese",
94
+ sw: "Swahili",
95
+ sv: "Swedish",
96
+ tl: "Tagalog (Filipino)",
97
+ tg: "Tajik",
98
+ ta: "Tamil",
99
+ tt: "Tatar",
100
+ te: "Telugu",
101
+ th: "Thai",
102
+ tr: "Turkish",
103
+ tk: "Turkmen",
104
+ uk: "Ukrainian",
105
+ ur: "Urdu",
106
+ ug: "Uyghur",
107
+ uz: "Uzbek",
108
+ vi: "Vietnamese",
109
+ cy: "Welsh",
110
+ xh: "Xhosa",
111
+ yi: "Yiddish",
112
+ yo: "Yoruba",
113
+ zu: "Zulu",
114
+ };
115
+
116
+ export class OpenAITranslate implements ITranslate {
117
+ private openai;
118
+ constructor(apiKey: string) {
119
+ const configuration = {
120
+ apiKey: apiKey,
121
+ };
122
+ this.openai = new OpenAI(configuration);
123
+ }
124
+ isValidLocale(targetLocale: string): boolean {
125
+ return targetLocale in supportedLanguages;
126
+ }
127
+ async translateText(
128
+ text: string,
129
+ sourceLocale: string,
130
+ targetLocale: string,
131
+ ): Promise<string> {
132
+ if (sourceLocale !== "en") {
133
+ throw Error(
134
+ `${sourceLocale} is not supported.Currently we support just English `,
135
+ );
136
+ }
137
+
138
+ let result = "";
139
+ let args;
140
+ ({ args, text } = Util.replaceContextVariables(text));
141
+ const prompt = `You will be provided with a sentence in English, and your task is to translate it into ${
142
+ supportedLanguages[targetLocale] as string
143
+ }:\n${text}\n.`;
144
+ const response = await this.openai.chat.completions.create({
145
+ model: "text-davinci-003",
146
+ messages: [{ role: "system", content: prompt }],
147
+ temperature: 0.2,
148
+ max_tokens: 250,
149
+ top_p: 1.0,
150
+ n: 1,
151
+ frequency_penalty: 0.0,
152
+ presence_penalty: 0.0,
153
+ });
154
+
155
+ if (response.choices[0].message.content !== null) {
156
+ result = Util.replaceArgumentsWithNumbers(
157
+ args,
158
+ response.choices[0].message.content,
159
+ );
160
+ result = result.replace(/^\n+|\n+$/g, "");
161
+ } else {
162
+ console.error(`can not translate text with prompt :${prompt}`);
163
+ result = Util.replaceArgumentsWithNumbers(args, result);
164
+ }
165
+ return result;
166
+ }
167
+ }
@@ -0,0 +1,13 @@
1
+ export interface ITranslate {
2
+ isValidLocale(targetLocale: string): boolean;
3
+ translateText(
4
+ text: string,
5
+ sourceLocale: string,
6
+ targetLocale: string,
7
+ ): Promise<string>;
8
+ }
9
+
10
+ export interface TranslationFile {
11
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
12
+ [key: string]: any;
13
+ }
package/src/util.ts ADDED
@@ -0,0 +1,57 @@
1
+ // biome-ignore lint/complexity/noStaticOnlyClass: <explanation>
2
+ export class Util {
3
+ private static _startDelimiter = "{";
4
+ private static _endDelimiter = "}";
5
+ private static pattern = new RegExp(
6
+ `${Util._startDelimiter}(.*?)${Util._endDelimiter}`,
7
+ "g",
8
+ );
9
+
10
+ public static set startDelimiter(value: string) {
11
+ Util._startDelimiter = value;
12
+ // update regex
13
+ Util.pattern = new RegExp(
14
+ `${Util._startDelimiter}(.*?)${Util._endDelimiter}`,
15
+ "g",
16
+ );
17
+ }
18
+
19
+ public static set endDelimiter(value: string) {
20
+ Util._endDelimiter = value;
21
+ // update regex
22
+ Util.pattern = new RegExp(
23
+ `${Util._startDelimiter}(.*?)${Util._endDelimiter}`,
24
+ "g",
25
+ );
26
+ }
27
+ public static replaceArgumentsWithNumbers(
28
+ args: RegExpMatchArray | null,
29
+ result: string,
30
+ ) {
31
+ if (args) {
32
+ let i = 0;
33
+ for (const arg of args) {
34
+ result = result.replace(
35
+ Util._startDelimiter + i + Util._endDelimiter,
36
+ arg,
37
+ );
38
+ i++;
39
+ }
40
+ }
41
+ return result;
42
+ }
43
+
44
+ public static replaceContextVariables(text: string) {
45
+ const args = text.match(Util.pattern);
46
+
47
+ // replace arguments with numbers
48
+ if (args) {
49
+ let i = 0;
50
+ for (const arg of args) {
51
+ text = text.replace(arg, Util._startDelimiter + i + Util._endDelimiter);
52
+ i++;
53
+ }
54
+ }
55
+ return { args, text };
56
+ }
57
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "hello.txt": "Hello, world!",
3
+ "@@ignore.me": "Ignore me",
4
+
5
+ "accountLayout": {
6
+ "myProfile": "My profile",
7
+ "myAddressBook": "My address book",
8
+ "vouchers": "Vouchers",
9
+ "myOrders": "My orders",
10
+ "myWishlist": "My wishlist",
11
+ "comparedList": "Compared list"
12
+ },
13
+ "trackOrder": {
14
+ "estimatedDelivery": "Estimated delivery",
15
+ "estimated": "Estimated",
16
+ "enterCode": "Enter the track code of your order",
17
+ "trackOrder": "Track Your Order",
18
+ "orderStatus": "Status of the Order",
19
+ "haveAnOrder": "Have an order? Want to know where your order is now?",
20
+ "knowProgress": "Know the progress of your product delivery."
21
+ }
22
+ }
File without changes
@@ -0,0 +1,21 @@
1
+ {
2
+ "hello.txt": "Bonjour tout le monde !",
3
+ "@@ignore.me": "Ignore-moi",
4
+ "accountLayout": {
5
+ "myProfile": "Mon profil",
6
+ "myAddressBook": "Mon carnet d'adresses",
7
+ "vouchers": "Bons d'achat",
8
+ "myOrders": "Mes commandes",
9
+ "myWishlist": "Ma liste d'envies",
10
+ "comparedList": "Liste comparée"
11
+ },
12
+ "trackOrder": {
13
+ "estimatedDelivery": "Livraison estimée",
14
+ "estimated": "Estimé",
15
+ "enterCode": "Entrez le code de suivi de votre commande",
16
+ "trackOrder": "Suivez votre commande",
17
+ "orderStatus": "État de la commande",
18
+ "haveAnOrder": "Vous avez une commande ? Vous voulez savoir où se trouve actuellement votre commande ?",
19
+ "knowProgress": "Suivez l'avancement de la livraison de vos produits."
20
+ }
21
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "hello.txt": "Zdravo, svet!",
3
+ "@@ignore.me": "Ignoriši me",
4
+ "accountLayout": {
5
+ "myProfile": "Moj profil",
6
+ "myAddressBook": "Moj adresar",
7
+ "vouchers": "Vaučeri",
8
+ "myOrders": "Moje naređenja",
9
+ "myWishlist": "Moja lista želja",
10
+ "comparedList": "Upoređena lista"
11
+ },
12
+ "trackOrder": {
13
+ "estimatedDelivery": "Procenjena isporuka",
14
+ "estimated": "Procenjeno",
15
+ "enterCode": "Unesite kod numere vaše porudžbine",
16
+ "trackOrder": "Pratite svoju porudžbinu",
17
+ "orderStatus": "Status naloga",
18
+ "haveAnOrder": "Imate nalog? Želite da znate gde je vaša narudžba sada?",
19
+ "knowProgress": "Znajte napredak isporuke proizvoda."
20
+ }
21
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "dashboard": "Armaturenbrett",
3
+ "pricing": "Preisgestaltung",
4
+ "sign-in": "anmelden",
5
+ "settings": "Einstellungen",
6
+ "language": "Sprache",
7
+ "get-credit": "Holen Sie sich Kredit",
8
+ "logout": "Ausloggen"
9
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "credit-usage": "Kreditverwendung"
3
+ }