poly-lexis 0.1.0 → 0.2.1
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/README.md +24 -24
- package/dist/cli/translations.js +353 -80
- package/dist/cli/translations.js.map +1 -1
- package/dist/index.d.ts +211 -108
- package/dist/index.js +632 -355
- package/dist/index.js.map +1 -1
- package/dist/translations/core/translations-config.schema.json +252 -32
- package/package.json +5 -6
package/dist/cli/translations.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
5
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
6
|
-
}) : x)(function(x) {
|
|
7
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
8
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
9
|
-
});
|
|
10
4
|
var __esm = (fn, res) => function __init() {
|
|
11
5
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
12
6
|
};
|
|
@@ -48,7 +42,8 @@ function writeTranslation(translationsPath, language, namespace, translations) {
|
|
|
48
42
|
fs.mkdirSync(langPath, { recursive: true });
|
|
49
43
|
}
|
|
50
44
|
const filePath = path2.join(langPath, `${namespace}.json`);
|
|
51
|
-
fs.writeFileSync(filePath, JSON.stringify(translations, null, 2)
|
|
45
|
+
fs.writeFileSync(filePath, `${JSON.stringify(translations, null, 2)}
|
|
46
|
+
`, "utf-8");
|
|
52
47
|
}
|
|
53
48
|
function getAvailableLanguages(translationsPath) {
|
|
54
49
|
if (!fs.existsSync(translationsPath)) {
|
|
@@ -106,54 +101,274 @@ var init_schema = __esm({
|
|
|
106
101
|
"use strict";
|
|
107
102
|
init_esm_shims();
|
|
108
103
|
SUPPORTED_LANGUAGES = [
|
|
104
|
+
"af",
|
|
105
|
+
// Afrikaans
|
|
106
|
+
"sq",
|
|
107
|
+
// Albanian
|
|
108
|
+
"am",
|
|
109
|
+
// Amharic
|
|
110
|
+
"ar",
|
|
111
|
+
// Arabic
|
|
112
|
+
"hy",
|
|
113
|
+
// Armenian
|
|
114
|
+
"as",
|
|
115
|
+
// Assamese
|
|
116
|
+
"ay",
|
|
117
|
+
// Aymara
|
|
118
|
+
"az",
|
|
119
|
+
// Azerbaijani
|
|
120
|
+
"bm",
|
|
121
|
+
// Bambara
|
|
122
|
+
"eu",
|
|
123
|
+
// Basque
|
|
124
|
+
"be",
|
|
125
|
+
// Belarusian
|
|
126
|
+
"bn",
|
|
127
|
+
// Bengali
|
|
128
|
+
"bho",
|
|
129
|
+
// Bhojpuri
|
|
130
|
+
"bs",
|
|
131
|
+
// Bosnian
|
|
132
|
+
"bg",
|
|
133
|
+
// Bulgarian
|
|
134
|
+
"ca",
|
|
135
|
+
// Catalan
|
|
136
|
+
"ceb",
|
|
137
|
+
// Cebuano
|
|
138
|
+
"ny",
|
|
139
|
+
// Chichewa
|
|
140
|
+
"zh",
|
|
141
|
+
// Chinese (Simplified) - Google uses 'zh' or 'zh-CN'
|
|
142
|
+
"zh_cn",
|
|
143
|
+
// Chinese (Simplified) - alternative format
|
|
144
|
+
"zh_tw",
|
|
145
|
+
// Chinese (Traditional)
|
|
146
|
+
"co",
|
|
147
|
+
// Corsican
|
|
148
|
+
"hr",
|
|
149
|
+
// Croatian
|
|
150
|
+
"cs",
|
|
151
|
+
// Czech
|
|
152
|
+
"da",
|
|
153
|
+
// Danish
|
|
154
|
+
"dv",
|
|
155
|
+
// Dhivehi
|
|
156
|
+
"doi",
|
|
157
|
+
// Dogri
|
|
158
|
+
"nl",
|
|
159
|
+
// Dutch
|
|
109
160
|
"en",
|
|
110
161
|
// English
|
|
162
|
+
"eo",
|
|
163
|
+
// Esperanto
|
|
164
|
+
"et",
|
|
165
|
+
// Estonian
|
|
166
|
+
"ee",
|
|
167
|
+
// Ewe
|
|
168
|
+
"tl",
|
|
169
|
+
// Filipino (Tagalog)
|
|
170
|
+
"fi",
|
|
171
|
+
// Finnish
|
|
111
172
|
"fr",
|
|
112
173
|
// French
|
|
113
|
-
"
|
|
114
|
-
//
|
|
115
|
-
"
|
|
116
|
-
//
|
|
117
|
-
"es",
|
|
118
|
-
// Spanish
|
|
119
|
-
"pt",
|
|
120
|
-
// Portuguese
|
|
174
|
+
"gl",
|
|
175
|
+
// Galician
|
|
176
|
+
"ka",
|
|
177
|
+
// Georgian
|
|
121
178
|
"de",
|
|
122
179
|
// German
|
|
123
|
-
"
|
|
124
|
-
//
|
|
125
|
-
"
|
|
126
|
-
//
|
|
127
|
-
"
|
|
128
|
-
//
|
|
180
|
+
"el",
|
|
181
|
+
// Greek
|
|
182
|
+
"gn",
|
|
183
|
+
// Guarani
|
|
184
|
+
"gu",
|
|
185
|
+
// Gujarati
|
|
186
|
+
"ht",
|
|
187
|
+
// Haitian Creole
|
|
188
|
+
"ha",
|
|
189
|
+
// Hausa
|
|
190
|
+
"haw",
|
|
191
|
+
// Hawaiian
|
|
192
|
+
"iw",
|
|
193
|
+
// Hebrew (legacy code, 'he' is preferred)
|
|
194
|
+
"he",
|
|
195
|
+
// Hebrew
|
|
196
|
+
"hi",
|
|
197
|
+
// Hindi
|
|
198
|
+
"hmn",
|
|
199
|
+
// Hmong
|
|
129
200
|
"hu",
|
|
130
201
|
// Hungarian
|
|
131
|
-
"
|
|
132
|
-
//
|
|
202
|
+
"is",
|
|
203
|
+
// Icelandic
|
|
204
|
+
"ig",
|
|
205
|
+
// Igbo
|
|
206
|
+
"ilo",
|
|
207
|
+
// Ilocano
|
|
208
|
+
"id",
|
|
209
|
+
// Indonesian
|
|
210
|
+
"ga",
|
|
211
|
+
// Irish
|
|
212
|
+
"it",
|
|
213
|
+
// Italian
|
|
133
214
|
"ja",
|
|
134
215
|
// Japanese
|
|
135
|
-
"
|
|
136
|
-
//
|
|
137
|
-
"
|
|
138
|
-
//
|
|
216
|
+
"jw",
|
|
217
|
+
// Javanese
|
|
218
|
+
"kn",
|
|
219
|
+
// Kannada
|
|
220
|
+
"kk",
|
|
221
|
+
// Kazakh
|
|
222
|
+
"km",
|
|
223
|
+
// Khmer
|
|
224
|
+
"rw",
|
|
225
|
+
// Kinyarwanda
|
|
226
|
+
"gom",
|
|
227
|
+
// Konkani
|
|
139
228
|
"ko",
|
|
140
229
|
// Korean
|
|
230
|
+
"kri",
|
|
231
|
+
// Krio
|
|
232
|
+
"ku",
|
|
233
|
+
// Kurdish (Kurmanji)
|
|
234
|
+
"ckb",
|
|
235
|
+
// Kurdish (Sorani)
|
|
236
|
+
"ky",
|
|
237
|
+
// Kyrgyz
|
|
238
|
+
"lo",
|
|
239
|
+
// Lao
|
|
240
|
+
"la",
|
|
241
|
+
// Latin
|
|
242
|
+
"lv",
|
|
243
|
+
// Latvian
|
|
244
|
+
"ln",
|
|
245
|
+
// Lingala
|
|
246
|
+
"lt",
|
|
247
|
+
// Lithuanian
|
|
248
|
+
"lg",
|
|
249
|
+
// Luganda
|
|
250
|
+
"lb",
|
|
251
|
+
// Luxembourgish
|
|
252
|
+
"mk",
|
|
253
|
+
// Macedonian
|
|
254
|
+
"mai",
|
|
255
|
+
// Maithili
|
|
256
|
+
"mg",
|
|
257
|
+
// Malagasy
|
|
258
|
+
"ms",
|
|
259
|
+
// Malay
|
|
260
|
+
"ml",
|
|
261
|
+
// Malayalam
|
|
262
|
+
"mt",
|
|
263
|
+
// Maltese
|
|
264
|
+
"mi",
|
|
265
|
+
// Maori
|
|
266
|
+
"mr",
|
|
267
|
+
// Marathi
|
|
268
|
+
"mni",
|
|
269
|
+
// Meiteilon (Manipuri)
|
|
270
|
+
"lus",
|
|
271
|
+
// Mizo
|
|
272
|
+
"mn",
|
|
273
|
+
// Mongolian
|
|
274
|
+
"my",
|
|
275
|
+
// Myanmar (Burmese)
|
|
276
|
+
"ne",
|
|
277
|
+
// Nepali
|
|
278
|
+
"no",
|
|
279
|
+
// Norwegian
|
|
280
|
+
"or",
|
|
281
|
+
// Odia
|
|
282
|
+
"om",
|
|
283
|
+
// Oromo
|
|
284
|
+
"ps",
|
|
285
|
+
// Pashto
|
|
286
|
+
"fa",
|
|
287
|
+
// Persian
|
|
288
|
+
"pl",
|
|
289
|
+
// Polish
|
|
290
|
+
"pt",
|
|
291
|
+
// Portuguese
|
|
292
|
+
"pt_br",
|
|
293
|
+
// Portuguese (Brazil)
|
|
294
|
+
"pa",
|
|
295
|
+
// Punjabi
|
|
296
|
+
"qu",
|
|
297
|
+
// Quechua
|
|
298
|
+
"ro",
|
|
299
|
+
// Romanian
|
|
141
300
|
"ru",
|
|
142
301
|
// Russian
|
|
143
|
-
"
|
|
144
|
-
//
|
|
145
|
-
"
|
|
146
|
-
//
|
|
302
|
+
"sm",
|
|
303
|
+
// Samoan
|
|
304
|
+
"sa",
|
|
305
|
+
// Sanskrit
|
|
306
|
+
"gd",
|
|
307
|
+
// Scottish Gaelic
|
|
308
|
+
"sr",
|
|
309
|
+
// Serbian
|
|
310
|
+
"st",
|
|
311
|
+
// Sesotho
|
|
312
|
+
"sn",
|
|
313
|
+
// Shona
|
|
314
|
+
"sd",
|
|
315
|
+
// Sindhi
|
|
316
|
+
"si",
|
|
317
|
+
// Sinhala
|
|
318
|
+
"sk",
|
|
319
|
+
// Slovak
|
|
320
|
+
"sl",
|
|
321
|
+
// Slovenian
|
|
322
|
+
"so",
|
|
323
|
+
// Somali
|
|
324
|
+
"es",
|
|
325
|
+
// Spanish
|
|
326
|
+
"su",
|
|
327
|
+
// Sundanese
|
|
328
|
+
"sw",
|
|
329
|
+
// Swahili
|
|
330
|
+
"sv",
|
|
331
|
+
// Swedish
|
|
332
|
+
"tg",
|
|
333
|
+
// Tajik
|
|
334
|
+
"ta",
|
|
335
|
+
// Tamil
|
|
336
|
+
"tt",
|
|
337
|
+
// Tatar
|
|
338
|
+
"te",
|
|
339
|
+
// Telugu
|
|
340
|
+
"th",
|
|
341
|
+
// Thai
|
|
342
|
+
"ti",
|
|
343
|
+
// Tigrinya
|
|
344
|
+
"ts",
|
|
345
|
+
// Tsonga
|
|
147
346
|
"tr",
|
|
148
347
|
// Turkish
|
|
149
|
-
"
|
|
150
|
-
//
|
|
151
|
-
"
|
|
152
|
-
//
|
|
153
|
-
"
|
|
154
|
-
//
|
|
155
|
-
"
|
|
156
|
-
//
|
|
348
|
+
"tk",
|
|
349
|
+
// Turkmen
|
|
350
|
+
"ak",
|
|
351
|
+
// Twi
|
|
352
|
+
"uk",
|
|
353
|
+
// Ukrainian
|
|
354
|
+
"ur",
|
|
355
|
+
// Urdu
|
|
356
|
+
"ug",
|
|
357
|
+
// Uyghur
|
|
358
|
+
"uz",
|
|
359
|
+
// Uzbek
|
|
360
|
+
"vi",
|
|
361
|
+
// Vietnamese
|
|
362
|
+
"cy",
|
|
363
|
+
// Welsh
|
|
364
|
+
"xh",
|
|
365
|
+
// Xhosa
|
|
366
|
+
"yi",
|
|
367
|
+
// Yiddish
|
|
368
|
+
"yo",
|
|
369
|
+
// Yoruba
|
|
370
|
+
"zu"
|
|
371
|
+
// Zulu
|
|
157
372
|
];
|
|
158
373
|
}
|
|
159
374
|
});
|
|
@@ -255,7 +470,8 @@ function initTranslations(projectRoot, config = {}) {
|
|
|
255
470
|
ERROR: "Error",
|
|
256
471
|
SUCCESS: "Success"
|
|
257
472
|
};
|
|
258
|
-
fs2.writeFileSync(commonPath, JSON.stringify(sampleTranslations, null, 2)
|
|
473
|
+
fs2.writeFileSync(commonPath, `${JSON.stringify(sampleTranslations, null, 2)}
|
|
474
|
+
`, "utf-8");
|
|
259
475
|
console.log(`Created sample file: ${commonPath}`);
|
|
260
476
|
}
|
|
261
477
|
for (const lang of languages) {
|
|
@@ -275,7 +491,8 @@ function initTranslations(projectRoot, config = {}) {
|
|
|
275
491
|
sourceLanguage,
|
|
276
492
|
typesOutputPath: finalConfig.typesOutputPath
|
|
277
493
|
};
|
|
278
|
-
fs2.writeFileSync(configPath, JSON.stringify(configContent, null, 2)
|
|
494
|
+
fs2.writeFileSync(configPath, `${JSON.stringify(configContent, null, 2)}
|
|
495
|
+
`, "utf-8");
|
|
279
496
|
console.log(`Created config file: ${configPath}`);
|
|
280
497
|
}
|
|
281
498
|
console.log("=====");
|
|
@@ -323,7 +540,7 @@ __export(generate_types_exports, {
|
|
|
323
540
|
generateTranslationTypes: () => generateTranslationTypes
|
|
324
541
|
});
|
|
325
542
|
import { execSync } from "child_process";
|
|
326
|
-
import * as
|
|
543
|
+
import * as fs4 from "fs";
|
|
327
544
|
import * as path8 from "path";
|
|
328
545
|
function generateTranslationTypes(projectRoot = process.cwd()) {
|
|
329
546
|
console.log("=====");
|
|
@@ -335,7 +552,7 @@ function generateTranslationTypes(projectRoot = process.cwd()) {
|
|
|
335
552
|
const sourceLanguage = config.sourceLanguage;
|
|
336
553
|
const outputFilePath = path8.join(projectRoot, config.typesOutputPath);
|
|
337
554
|
const dirPath = path8.join(translationsPath, sourceLanguage);
|
|
338
|
-
if (!
|
|
555
|
+
if (!fs4.existsSync(dirPath)) {
|
|
339
556
|
throw new Error(`Source language directory not found: ${dirPath}`);
|
|
340
557
|
}
|
|
341
558
|
const namespaces = getNamespaces(translationsPath, sourceLanguage);
|
|
@@ -349,15 +566,18 @@ function generateTranslationTypes(projectRoot = process.cwd()) {
|
|
|
349
566
|
allKeys = allKeys.concat(keys);
|
|
350
567
|
}
|
|
351
568
|
const outputDir = path8.dirname(outputFilePath);
|
|
352
|
-
if (!
|
|
353
|
-
|
|
569
|
+
if (!fs4.existsSync(outputDir)) {
|
|
570
|
+
fs4.mkdirSync(outputDir, { recursive: true });
|
|
354
571
|
}
|
|
355
572
|
const typeString = typeTemplate(allKeys, namespaces);
|
|
356
|
-
|
|
573
|
+
fs4.writeFileSync(outputFilePath, typeString, "utf8");
|
|
357
574
|
console.log(`Generated types with ${allKeys.length} keys and ${namespaces.length} namespaces`);
|
|
358
575
|
console.log(`Output: ${outputFilePath}`);
|
|
359
576
|
try {
|
|
360
|
-
execSync(`pnpm biome format --write ${outputFilePath}`, {
|
|
577
|
+
execSync(`pnpm biome format --write ${outputFilePath}`, {
|
|
578
|
+
stdio: "inherit",
|
|
579
|
+
cwd: projectRoot
|
|
580
|
+
});
|
|
361
581
|
} catch {
|
|
362
582
|
console.warn("Failed to format with Biome, continuing without formatting...");
|
|
363
583
|
}
|
|
@@ -384,10 +604,10 @@ var init_generate_types = __esm({
|
|
|
384
604
|
// src/cli/translations.ts
|
|
385
605
|
init_esm_shims();
|
|
386
606
|
import "dotenv/config";
|
|
387
|
-
import
|
|
388
|
-
import * as fs5 from "fs";
|
|
607
|
+
import * as fs6 from "fs";
|
|
389
608
|
import * as path10 from "path";
|
|
390
609
|
import { parseArgs } from "util";
|
|
610
|
+
import { confirm as confirm2, input as input2, select } from "@inquirer/prompts";
|
|
391
611
|
|
|
392
612
|
// src/translations/cli/add-key.ts
|
|
393
613
|
init_esm_shims();
|
|
@@ -395,10 +615,10 @@ import * as path4 from "path";
|
|
|
395
615
|
|
|
396
616
|
// src/translations/utils/translator.ts
|
|
397
617
|
init_esm_shims();
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
618
|
+
|
|
619
|
+
// src/translations/utils/google-translate-provider.ts
|
|
620
|
+
init_esm_shims();
|
|
621
|
+
function preserveVariables(text) {
|
|
402
622
|
const variableMap = /* @__PURE__ */ new Map();
|
|
403
623
|
let placeholderIndex = 0;
|
|
404
624
|
const textWithPlaceholders = text.replace(/\{\{([^}]+)\}\}/g, (match) => {
|
|
@@ -407,29 +627,81 @@ async function translateText(text, targetLang, sourceLang = "en", apiKey) {
|
|
|
407
627
|
placeholderIndex++;
|
|
408
628
|
return placeholder;
|
|
409
629
|
});
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
"Content-Type": "application/json"
|
|
415
|
-
},
|
|
416
|
-
body: JSON.stringify({
|
|
417
|
-
q: textWithPlaceholders,
|
|
418
|
-
source: sourceLang,
|
|
419
|
-
target: targetLang.split("_")[0],
|
|
420
|
-
// Convert 'pt_BR' to 'pt'
|
|
421
|
-
format: "text"
|
|
422
|
-
})
|
|
423
|
-
});
|
|
424
|
-
const data = await response.json();
|
|
425
|
-
if (data.error) {
|
|
426
|
-
throw new Error(`Google Translate API error: ${data.error.message}`);
|
|
427
|
-
}
|
|
428
|
-
let translatedText = data.data.translations[0].translatedText;
|
|
630
|
+
return { textWithPlaceholders, variableMap };
|
|
631
|
+
}
|
|
632
|
+
function restoreVariables(text, variableMap) {
|
|
633
|
+
let result = text;
|
|
429
634
|
for (const [placeholder, original] of variableMap) {
|
|
430
|
-
|
|
635
|
+
result = result.replace(new RegExp(placeholder, "g"), original);
|
|
636
|
+
}
|
|
637
|
+
return result;
|
|
638
|
+
}
|
|
639
|
+
var GoogleTranslateProvider = class {
|
|
640
|
+
async translate(options) {
|
|
641
|
+
const { text, sourceLang, targetLang, apiKey } = options;
|
|
642
|
+
if (!apiKey) {
|
|
643
|
+
throw new Error(
|
|
644
|
+
"Google Translate API key is required. Set GOOGLE_TRANSLATE_API_KEY environment variable or provide apiKey in options."
|
|
645
|
+
);
|
|
646
|
+
}
|
|
647
|
+
const { textWithPlaceholders, variableMap } = preserveVariables(text);
|
|
648
|
+
const url = `https://translation.googleapis.com/language/translate/v2?key=${apiKey}`;
|
|
649
|
+
const response = await fetch(url, {
|
|
650
|
+
method: "POST",
|
|
651
|
+
headers: {
|
|
652
|
+
"Content-Type": "application/json"
|
|
653
|
+
},
|
|
654
|
+
body: JSON.stringify({
|
|
655
|
+
q: textWithPlaceholders,
|
|
656
|
+
source: sourceLang,
|
|
657
|
+
target: targetLang.split("_")[0],
|
|
658
|
+
// Convert 'pt_BR' to 'pt'
|
|
659
|
+
format: "text"
|
|
660
|
+
})
|
|
661
|
+
});
|
|
662
|
+
const data = await response.json();
|
|
663
|
+
if (data.error) {
|
|
664
|
+
throw new Error(`Google Translate API error: ${data.error.message}`);
|
|
665
|
+
}
|
|
666
|
+
const translatedText = data.data.translations[0].translatedText;
|
|
667
|
+
return restoreVariables(translatedText, variableMap);
|
|
668
|
+
}
|
|
669
|
+
async translateBatch(texts, sourceLang, targetLang, apiKey, delayMs = 100) {
|
|
670
|
+
const results = [];
|
|
671
|
+
for (const text of texts) {
|
|
672
|
+
const translated = await this.translate({
|
|
673
|
+
text,
|
|
674
|
+
sourceLang,
|
|
675
|
+
targetLang,
|
|
676
|
+
apiKey
|
|
677
|
+
});
|
|
678
|
+
results.push(translated);
|
|
679
|
+
if (delayMs > 0) {
|
|
680
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
return results;
|
|
684
|
+
}
|
|
685
|
+
async validateConfig() {
|
|
686
|
+
const apiKey = process.env.GOOGLE_TRANSLATE_API_KEY;
|
|
687
|
+
return !!apiKey;
|
|
431
688
|
}
|
|
432
|
-
|
|
689
|
+
};
|
|
690
|
+
|
|
691
|
+
// src/translations/utils/translator.ts
|
|
692
|
+
var defaultProvider = new GoogleTranslateProvider();
|
|
693
|
+
var customProvider = null;
|
|
694
|
+
function getTranslationProvider() {
|
|
695
|
+
return customProvider || defaultProvider;
|
|
696
|
+
}
|
|
697
|
+
async function translateText(text, targetLang, sourceLang = "en", apiKey) {
|
|
698
|
+
const provider = getTranslationProvider();
|
|
699
|
+
return provider.translate({
|
|
700
|
+
text,
|
|
701
|
+
sourceLang,
|
|
702
|
+
targetLang,
|
|
703
|
+
apiKey
|
|
704
|
+
});
|
|
433
705
|
}
|
|
434
706
|
|
|
435
707
|
// src/translations/cli/add-key.ts
|
|
@@ -514,12 +786,13 @@ init_esm_shims();
|
|
|
514
786
|
init_schema();
|
|
515
787
|
init_types();
|
|
516
788
|
init_init();
|
|
789
|
+
import * as fs3 from "fs";
|
|
517
790
|
import * as path5 from "path";
|
|
518
791
|
import { checkbox, confirm, input } from "@inquirer/prompts";
|
|
519
792
|
async function initTranslationsInteractive(projectRoot = process.cwd()) {
|
|
520
793
|
console.log("\n\u{1F30D} Translation System Setup\n");
|
|
521
794
|
const configPath = path5.join(projectRoot, ".translationsrc.json");
|
|
522
|
-
const alreadyExists =
|
|
795
|
+
const alreadyExists = fs3.existsSync(configPath);
|
|
523
796
|
if (alreadyExists) {
|
|
524
797
|
console.log("\u26A0\uFE0F Configuration file already exists at .translationsrc.json\n");
|
|
525
798
|
const shouldOverwrite = await confirm({
|
|
@@ -669,7 +942,7 @@ function getLanguageName(code) {
|
|
|
669
942
|
|
|
670
943
|
// src/translations/cli/manage.ts
|
|
671
944
|
init_esm_shims();
|
|
672
|
-
import * as
|
|
945
|
+
import * as fs5 from "fs";
|
|
673
946
|
import * as path9 from "path";
|
|
674
947
|
|
|
675
948
|
// src/translations/cli/auto-fill.ts
|
|
@@ -841,7 +1114,7 @@ async function manageTranslations(projectRoot = process.cwd(), options = {}) {
|
|
|
841
1114
|
console.log("Translation Management");
|
|
842
1115
|
console.log("=====");
|
|
843
1116
|
const configPath = path9.join(projectRoot, ".translationsrc.json");
|
|
844
|
-
const isInitialized =
|
|
1117
|
+
const isInitialized = fs5.existsSync(configPath);
|
|
845
1118
|
if (!isInitialized) {
|
|
846
1119
|
console.log("\u{1F4C1} No translation configuration found. Initializing...\n");
|
|
847
1120
|
initTranslations(projectRoot);
|
|
@@ -852,7 +1125,7 @@ async function manageTranslations(projectRoot = process.cwd(), options = {}) {
|
|
|
852
1125
|
const config = loadConfig(projectRoot);
|
|
853
1126
|
const translationsPath = path9.join(projectRoot, config.translationsPath);
|
|
854
1127
|
const sourceLangPath = path9.join(translationsPath, config.sourceLanguage);
|
|
855
|
-
if (!
|
|
1128
|
+
if (!fs5.existsSync(sourceLangPath)) {
|
|
856
1129
|
console.log(`\u26A0\uFE0F Source language directory not found: ${sourceLangPath}`);
|
|
857
1130
|
console.log("Please add translation files to the source language directory.\n");
|
|
858
1131
|
return;
|
|
@@ -1036,7 +1309,7 @@ if (command === "add") {
|
|
|
1036
1309
|
try {
|
|
1037
1310
|
console.log("\n\u2728 Add a new translation key\n");
|
|
1038
1311
|
const configPath = path10.join(process.cwd(), ".translationsrc.json");
|
|
1039
|
-
const isInitialized =
|
|
1312
|
+
const isInitialized = fs6.existsSync(configPath);
|
|
1040
1313
|
if (!isInitialized) {
|
|
1041
1314
|
console.log("\u26A0\uFE0F Translation structure not initialized.");
|
|
1042
1315
|
const shouldInit = await confirm2({
|
|
@@ -1188,7 +1461,7 @@ if (command === "add") {
|
|
|
1188
1461
|
(async () => {
|
|
1189
1462
|
try {
|
|
1190
1463
|
const configPath = path10.join(process.cwd(), ".translationsrc.json");
|
|
1191
|
-
const isInitialized =
|
|
1464
|
+
const isInitialized = fs6.existsSync(configPath);
|
|
1192
1465
|
console.log("\n\u{1F30D} Translation Management\n");
|
|
1193
1466
|
const action = await select({
|
|
1194
1467
|
message: "What would you like to do?",
|