poly-lexis 0.2.1 → 0.3.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/README.md +40 -0
- package/dist/cli/translations.js +111 -63
- package/dist/cli/translations.js.map +1 -1
- package/dist/index.d.ts +54 -8
- package/dist/index.js +155 -63
- package/dist/index.js.map +1 -1
- package/dist/scripts/verify-translations.js +505 -0
- package/dist/scripts/verify-translations.js.map +1 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -79,6 +79,46 @@ poly-lexis add --namespace common --key HELLO --value "Hello"
|
|
|
79
79
|
poly-lexis add -n common -k WELCOME -v "Welcome" --auto-fill
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
+
### Verify Translations (CI/CD)
|
|
83
|
+
|
|
84
|
+
For CI/CD pipelines, you can validate translations and fail the build if any are missing:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# In your project that uses poly-lexis
|
|
88
|
+
npx poly-lexis --skip-types # Validates translations, exits with code 1 if invalid
|
|
89
|
+
|
|
90
|
+
# Or create a script in your package.json:
|
|
91
|
+
{
|
|
92
|
+
"scripts": {
|
|
93
|
+
"verify-translations": "poly-lexis --skip-types"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
# Then run in your CI/CD pipeline:
|
|
98
|
+
npm run verify-translations
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The command will:
|
|
102
|
+
- ✅ Exit with code 0 if all translations are valid
|
|
103
|
+
- ❌ Exit with code 1 if any translations are missing or empty
|
|
104
|
+
|
|
105
|
+
This makes it perfect for CI/CD checks to prevent incomplete translations from being deployed.
|
|
106
|
+
|
|
107
|
+
**Example CI/CD workflow (GitHub Actions):**
|
|
108
|
+
|
|
109
|
+
```yaml
|
|
110
|
+
name: Verify Translations
|
|
111
|
+
on: [push, pull_request]
|
|
112
|
+
jobs:
|
|
113
|
+
verify:
|
|
114
|
+
runs-on: ubuntu-latest
|
|
115
|
+
steps:
|
|
116
|
+
- uses: actions/checkout@v3
|
|
117
|
+
- uses: actions/setup-node@v3
|
|
118
|
+
- run: npm install
|
|
119
|
+
- run: npx poly-lexis --skip-types
|
|
120
|
+
```
|
|
121
|
+
|
|
82
122
|
### CLI Options
|
|
83
123
|
|
|
84
124
|
**Smart Mode:**
|
package/dist/cli/translations.js
CHANGED
|
@@ -95,12 +95,94 @@ function validateLanguages(languages) {
|
|
|
95
95
|
invalid
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
|
-
var SUPPORTED_LANGUAGES;
|
|
98
|
+
var DEEPL_LANGUAGES, GOOGLE_LANGUAGES, SUPPORTED_LANGUAGES;
|
|
99
99
|
var init_schema = __esm({
|
|
100
100
|
"src/translations/core/schema.ts"() {
|
|
101
101
|
"use strict";
|
|
102
102
|
init_esm_shims();
|
|
103
|
-
|
|
103
|
+
DEEPL_LANGUAGES = [
|
|
104
|
+
"ar",
|
|
105
|
+
// Arabic
|
|
106
|
+
"bg",
|
|
107
|
+
// Bulgarian
|
|
108
|
+
"cs",
|
|
109
|
+
// Czech
|
|
110
|
+
"da",
|
|
111
|
+
// Danish
|
|
112
|
+
"de",
|
|
113
|
+
// German
|
|
114
|
+
"el",
|
|
115
|
+
// Greek
|
|
116
|
+
"en",
|
|
117
|
+
// English (unspecified)
|
|
118
|
+
"en_gb",
|
|
119
|
+
// English (British)
|
|
120
|
+
"en_us",
|
|
121
|
+
// English (American)
|
|
122
|
+
"es",
|
|
123
|
+
// Spanish
|
|
124
|
+
"es_419",
|
|
125
|
+
// Spanish (Latin American)
|
|
126
|
+
"et",
|
|
127
|
+
// Estonian
|
|
128
|
+
"fi",
|
|
129
|
+
// Finnish
|
|
130
|
+
"fr",
|
|
131
|
+
// French
|
|
132
|
+
"he",
|
|
133
|
+
// Hebrew (next-gen models only)
|
|
134
|
+
"hu",
|
|
135
|
+
// Hungarian
|
|
136
|
+
"id",
|
|
137
|
+
// Indonesian
|
|
138
|
+
"it",
|
|
139
|
+
// Italian
|
|
140
|
+
"ja",
|
|
141
|
+
// Japanese
|
|
142
|
+
"ko",
|
|
143
|
+
// Korean
|
|
144
|
+
"lt",
|
|
145
|
+
// Lithuanian
|
|
146
|
+
"lv",
|
|
147
|
+
// Latvian
|
|
148
|
+
"nb",
|
|
149
|
+
// Norwegian Bokmål
|
|
150
|
+
"nl",
|
|
151
|
+
// Dutch
|
|
152
|
+
"pl",
|
|
153
|
+
// Polish
|
|
154
|
+
"pt",
|
|
155
|
+
// Portuguese (unspecified)
|
|
156
|
+
"pt_br",
|
|
157
|
+
// Portuguese (Brazilian)
|
|
158
|
+
"pt_pt",
|
|
159
|
+
// Portuguese (excluding Brazilian)
|
|
160
|
+
"ro",
|
|
161
|
+
// Romanian
|
|
162
|
+
"ru",
|
|
163
|
+
// Russian
|
|
164
|
+
"sk",
|
|
165
|
+
// Slovak
|
|
166
|
+
"sl",
|
|
167
|
+
// Slovenian
|
|
168
|
+
"sv",
|
|
169
|
+
// Swedish
|
|
170
|
+
"th",
|
|
171
|
+
// Thai (next-gen models only)
|
|
172
|
+
"tr",
|
|
173
|
+
// Turkish
|
|
174
|
+
"uk",
|
|
175
|
+
// Ukrainian
|
|
176
|
+
"vi",
|
|
177
|
+
// Vietnamese (next-gen models only)
|
|
178
|
+
"zh",
|
|
179
|
+
// Chinese (unspecified)
|
|
180
|
+
"zh_hans",
|
|
181
|
+
// Chinese (simplified)
|
|
182
|
+
"zh_hant"
|
|
183
|
+
// Chinese (traditional)
|
|
184
|
+
];
|
|
185
|
+
GOOGLE_LANGUAGES = [
|
|
104
186
|
"af",
|
|
105
187
|
// Afrikaans
|
|
106
188
|
"sq",
|
|
@@ -111,22 +193,14 @@ var init_schema = __esm({
|
|
|
111
193
|
// Arabic
|
|
112
194
|
"hy",
|
|
113
195
|
// Armenian
|
|
114
|
-
"as",
|
|
115
|
-
// Assamese
|
|
116
|
-
"ay",
|
|
117
|
-
// Aymara
|
|
118
196
|
"az",
|
|
119
197
|
// Azerbaijani
|
|
120
|
-
"bm",
|
|
121
|
-
// Bambara
|
|
122
198
|
"eu",
|
|
123
199
|
// Basque
|
|
124
200
|
"be",
|
|
125
201
|
// Belarusian
|
|
126
202
|
"bn",
|
|
127
203
|
// Bengali
|
|
128
|
-
"bho",
|
|
129
|
-
// Bhojpuri
|
|
130
204
|
"bs",
|
|
131
205
|
// Bosnian
|
|
132
206
|
"bg",
|
|
@@ -135,12 +209,10 @@ var init_schema = __esm({
|
|
|
135
209
|
// Catalan
|
|
136
210
|
"ceb",
|
|
137
211
|
// Cebuano
|
|
138
|
-
"ny",
|
|
139
|
-
// Chichewa
|
|
140
212
|
"zh",
|
|
141
|
-
// Chinese (Simplified)
|
|
213
|
+
// Chinese (Simplified)
|
|
142
214
|
"zh_cn",
|
|
143
|
-
// Chinese (Simplified)
|
|
215
|
+
// Chinese (Simplified)
|
|
144
216
|
"zh_tw",
|
|
145
217
|
// Chinese (Traditional)
|
|
146
218
|
"co",
|
|
@@ -151,10 +223,6 @@ var init_schema = __esm({
|
|
|
151
223
|
// Czech
|
|
152
224
|
"da",
|
|
153
225
|
// Danish
|
|
154
|
-
"dv",
|
|
155
|
-
// Dhivehi
|
|
156
|
-
"doi",
|
|
157
|
-
// Dogri
|
|
158
226
|
"nl",
|
|
159
227
|
// Dutch
|
|
160
228
|
"en",
|
|
@@ -163,14 +231,12 @@ var init_schema = __esm({
|
|
|
163
231
|
// Esperanto
|
|
164
232
|
"et",
|
|
165
233
|
// Estonian
|
|
166
|
-
"ee",
|
|
167
|
-
// Ewe
|
|
168
|
-
"tl",
|
|
169
|
-
// Filipino (Tagalog)
|
|
170
234
|
"fi",
|
|
171
235
|
// Finnish
|
|
172
236
|
"fr",
|
|
173
237
|
// French
|
|
238
|
+
"fy",
|
|
239
|
+
// Frisian
|
|
174
240
|
"gl",
|
|
175
241
|
// Galician
|
|
176
242
|
"ka",
|
|
@@ -179,8 +245,6 @@ var init_schema = __esm({
|
|
|
179
245
|
// German
|
|
180
246
|
"el",
|
|
181
247
|
// Greek
|
|
182
|
-
"gn",
|
|
183
|
-
// Guarani
|
|
184
248
|
"gu",
|
|
185
249
|
// Gujarati
|
|
186
250
|
"ht",
|
|
@@ -189,8 +253,6 @@ var init_schema = __esm({
|
|
|
189
253
|
// Hausa
|
|
190
254
|
"haw",
|
|
191
255
|
// Hawaiian
|
|
192
|
-
"iw",
|
|
193
|
-
// Hebrew (legacy code, 'he' is preferred)
|
|
194
256
|
"he",
|
|
195
257
|
// Hebrew
|
|
196
258
|
"hi",
|
|
@@ -203,8 +265,6 @@ var init_schema = __esm({
|
|
|
203
265
|
// Icelandic
|
|
204
266
|
"ig",
|
|
205
267
|
// Igbo
|
|
206
|
-
"ilo",
|
|
207
|
-
// Ilocano
|
|
208
268
|
"id",
|
|
209
269
|
// Indonesian
|
|
210
270
|
"ga",
|
|
@@ -213,7 +273,7 @@ var init_schema = __esm({
|
|
|
213
273
|
// Italian
|
|
214
274
|
"ja",
|
|
215
275
|
// Japanese
|
|
216
|
-
"
|
|
276
|
+
"jv",
|
|
217
277
|
// Javanese
|
|
218
278
|
"kn",
|
|
219
279
|
// Kannada
|
|
@@ -223,16 +283,10 @@ var init_schema = __esm({
|
|
|
223
283
|
// Khmer
|
|
224
284
|
"rw",
|
|
225
285
|
// Kinyarwanda
|
|
226
|
-
"gom",
|
|
227
|
-
// Konkani
|
|
228
286
|
"ko",
|
|
229
287
|
// Korean
|
|
230
|
-
"kri",
|
|
231
|
-
// Krio
|
|
232
288
|
"ku",
|
|
233
|
-
// Kurdish
|
|
234
|
-
"ckb",
|
|
235
|
-
// Kurdish (Sorani)
|
|
289
|
+
// Kurdish
|
|
236
290
|
"ky",
|
|
237
291
|
// Kyrgyz
|
|
238
292
|
"lo",
|
|
@@ -241,18 +295,12 @@ var init_schema = __esm({
|
|
|
241
295
|
// Latin
|
|
242
296
|
"lv",
|
|
243
297
|
// Latvian
|
|
244
|
-
"ln",
|
|
245
|
-
// Lingala
|
|
246
298
|
"lt",
|
|
247
299
|
// Lithuanian
|
|
248
|
-
"lg",
|
|
249
|
-
// Luganda
|
|
250
300
|
"lb",
|
|
251
301
|
// Luxembourgish
|
|
252
302
|
"mk",
|
|
253
303
|
// Macedonian
|
|
254
|
-
"mai",
|
|
255
|
-
// Maithili
|
|
256
304
|
"mg",
|
|
257
305
|
// Malagasy
|
|
258
306
|
"ms",
|
|
@@ -265,10 +313,6 @@ var init_schema = __esm({
|
|
|
265
313
|
// Maori
|
|
266
314
|
"mr",
|
|
267
315
|
// Marathi
|
|
268
|
-
"mni",
|
|
269
|
-
// Meiteilon (Manipuri)
|
|
270
|
-
"lus",
|
|
271
|
-
// Mizo
|
|
272
316
|
"mn",
|
|
273
317
|
// Mongolian
|
|
274
318
|
"my",
|
|
@@ -277,10 +321,10 @@ var init_schema = __esm({
|
|
|
277
321
|
// Nepali
|
|
278
322
|
"no",
|
|
279
323
|
// Norwegian
|
|
324
|
+
"ny",
|
|
325
|
+
// Nyanja (Chichewa)
|
|
280
326
|
"or",
|
|
281
|
-
// Odia
|
|
282
|
-
"om",
|
|
283
|
-
// Oromo
|
|
327
|
+
// Odia (Oriya)
|
|
284
328
|
"ps",
|
|
285
329
|
// Pashto
|
|
286
330
|
"fa",
|
|
@@ -293,18 +337,14 @@ var init_schema = __esm({
|
|
|
293
337
|
// Portuguese (Brazil)
|
|
294
338
|
"pa",
|
|
295
339
|
// Punjabi
|
|
296
|
-
"qu",
|
|
297
|
-
// Quechua
|
|
298
340
|
"ro",
|
|
299
341
|
// Romanian
|
|
300
342
|
"ru",
|
|
301
343
|
// Russian
|
|
302
344
|
"sm",
|
|
303
345
|
// Samoan
|
|
304
|
-
"sa",
|
|
305
|
-
// Sanskrit
|
|
306
346
|
"gd",
|
|
307
|
-
//
|
|
347
|
+
// Scots Gaelic
|
|
308
348
|
"sr",
|
|
309
349
|
// Serbian
|
|
310
350
|
"st",
|
|
@@ -314,7 +354,7 @@ var init_schema = __esm({
|
|
|
314
354
|
"sd",
|
|
315
355
|
// Sindhi
|
|
316
356
|
"si",
|
|
317
|
-
// Sinhala
|
|
357
|
+
// Sinhala (Sinhalese)
|
|
318
358
|
"sk",
|
|
319
359
|
// Slovak
|
|
320
360
|
"sl",
|
|
@@ -329,6 +369,8 @@ var init_schema = __esm({
|
|
|
329
369
|
// Swahili
|
|
330
370
|
"sv",
|
|
331
371
|
// Swedish
|
|
372
|
+
"tl",
|
|
373
|
+
// Tagalog (Filipino)
|
|
332
374
|
"tg",
|
|
333
375
|
// Tajik
|
|
334
376
|
"ta",
|
|
@@ -339,16 +381,10 @@ var init_schema = __esm({
|
|
|
339
381
|
// Telugu
|
|
340
382
|
"th",
|
|
341
383
|
// Thai
|
|
342
|
-
"ti",
|
|
343
|
-
// Tigrinya
|
|
344
|
-
"ts",
|
|
345
|
-
// Tsonga
|
|
346
384
|
"tr",
|
|
347
385
|
// Turkish
|
|
348
386
|
"tk",
|
|
349
387
|
// Turkmen
|
|
350
|
-
"ak",
|
|
351
|
-
// Twi
|
|
352
388
|
"uk",
|
|
353
389
|
// Ukrainian
|
|
354
390
|
"ur",
|
|
@@ -370,6 +406,9 @@ var init_schema = __esm({
|
|
|
370
406
|
"zu"
|
|
371
407
|
// Zulu
|
|
372
408
|
];
|
|
409
|
+
SUPPORTED_LANGUAGES = Array.from(
|
|
410
|
+
/* @__PURE__ */ new Set([...DEEPL_LANGUAGES, ...GOOGLE_LANGUAGES])
|
|
411
|
+
).sort();
|
|
373
412
|
}
|
|
374
413
|
});
|
|
375
414
|
|
|
@@ -622,7 +661,7 @@ function preserveVariables(text) {
|
|
|
622
661
|
const variableMap = /* @__PURE__ */ new Map();
|
|
623
662
|
let placeholderIndex = 0;
|
|
624
663
|
const textWithPlaceholders = text.replace(/\{\{([^}]+)\}\}/g, (match) => {
|
|
625
|
-
const placeholder = `
|
|
664
|
+
const placeholder = `XXX_${placeholderIndex}_XXX`;
|
|
626
665
|
variableMap.set(placeholder, match);
|
|
627
666
|
placeholderIndex++;
|
|
628
667
|
return placeholder;
|
|
@@ -1128,7 +1167,7 @@ async function manageTranslations(projectRoot = process.cwd(), options = {}) {
|
|
|
1128
1167
|
if (!fs5.existsSync(sourceLangPath)) {
|
|
1129
1168
|
console.log(`\u26A0\uFE0F Source language directory not found: ${sourceLangPath}`);
|
|
1130
1169
|
console.log("Please add translation files to the source language directory.\n");
|
|
1131
|
-
return;
|
|
1170
|
+
return false;
|
|
1132
1171
|
}
|
|
1133
1172
|
console.log("\u{1F50D} Validating translations...\n");
|
|
1134
1173
|
const validationResult = validateTranslations(projectRoot);
|
|
@@ -1192,6 +1231,11 @@ async function manageTranslations(projectRoot = process.cwd(), options = {}) {
|
|
|
1192
1231
|
console.log("\n\u2705 All systems ready!");
|
|
1193
1232
|
}
|
|
1194
1233
|
console.log("=====\n");
|
|
1234
|
+
if (autoFill && !dryRun && apiKey) {
|
|
1235
|
+
const finalValidation = validateTranslations(projectRoot);
|
|
1236
|
+
return finalValidation.valid;
|
|
1237
|
+
}
|
|
1238
|
+
return validationResult.valid;
|
|
1195
1239
|
}
|
|
1196
1240
|
|
|
1197
1241
|
// src/cli/translations.ts
|
|
@@ -1453,6 +1497,10 @@ if (command === "add") {
|
|
|
1453
1497
|
language: values.language,
|
|
1454
1498
|
skipTypes: values["skip-types"],
|
|
1455
1499
|
dryRun: values["dry-run"]
|
|
1500
|
+
}).then((isValid) => {
|
|
1501
|
+
if (!isValid) {
|
|
1502
|
+
process.exit(1);
|
|
1503
|
+
}
|
|
1456
1504
|
}).catch((error) => {
|
|
1457
1505
|
console.error("Error:", error instanceof Error ? error.message : error);
|
|
1458
1506
|
process.exit(1);
|