@adminforth/i18n 1.0.18-next.8 → 1.0.18
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/custom/LanguageInUserMenu.vue +19 -15
- package/dist/custom/LanguageInUserMenu.vue +19 -15
- package/dist/index.js +12 -14
- package/index.ts +14 -21
- package/package.json +1 -1
|
@@ -18,21 +18,25 @@
|
|
|
18
18
|
/>
|
|
19
19
|
</div>
|
|
20
20
|
|
|
21
|
-
<div v-if="showDropdown"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
21
|
+
<div v-if="showDropdown" >
|
|
22
|
+
|
|
23
|
+
<div class="cursor-pointer flex items-center gap-1 block px-4 py-1 text-sm
|
|
24
|
+
text-black dark:text-darkSidebarTextHover
|
|
25
|
+
bg-black bg-opacity-10
|
|
26
|
+
hover:brightness-110
|
|
27
|
+
hover:bg-lightPrimaryContrast dark:hover:bg-darkPrimaryContrasts
|
|
28
|
+
w-full text-select-none pl-5 select-none"
|
|
29
|
+
v-for="option in options.filter((opt) => opt.value !== selectedOption.value)"
|
|
30
|
+
@click="doChangeLang(option.value)"
|
|
31
|
+
>
|
|
32
|
+
<span class="mr-1">
|
|
33
|
+
<span class="flag-icon"
|
|
34
|
+
:class="`flag-icon-${getCountryCodeFromLangCode(option.value)}`"
|
|
35
|
+
></span>
|
|
36
|
+
</span>
|
|
37
|
+
<span>{{ option.label }}</span>
|
|
38
|
+
|
|
39
|
+
</div>
|
|
36
40
|
</div>
|
|
37
41
|
|
|
38
42
|
|
|
@@ -18,21 +18,25 @@
|
|
|
18
18
|
/>
|
|
19
19
|
</div>
|
|
20
20
|
|
|
21
|
-
<div v-if="showDropdown"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
21
|
+
<div v-if="showDropdown" >
|
|
22
|
+
|
|
23
|
+
<div class="cursor-pointer flex items-center gap-1 block px-4 py-1 text-sm
|
|
24
|
+
text-black dark:text-darkSidebarTextHover
|
|
25
|
+
bg-black bg-opacity-10
|
|
26
|
+
hover:brightness-110
|
|
27
|
+
hover:bg-lightPrimaryContrast dark:hover:bg-darkPrimaryContrasts
|
|
28
|
+
w-full text-select-none pl-5 select-none"
|
|
29
|
+
v-for="option in options.filter((opt) => opt.value !== selectedOption.value)"
|
|
30
|
+
@click="doChangeLang(option.value)"
|
|
31
|
+
>
|
|
32
|
+
<span class="mr-1">
|
|
33
|
+
<span class="flag-icon"
|
|
34
|
+
:class="`flag-icon-${getCountryCodeFromLangCode(option.value)}`"
|
|
35
|
+
></span>
|
|
36
|
+
</span>
|
|
37
|
+
<span>{{ option.label }}</span>
|
|
38
|
+
|
|
39
|
+
</div>
|
|
36
40
|
</div>
|
|
37
41
|
|
|
38
42
|
|
package/dist/index.js
CHANGED
|
@@ -286,12 +286,12 @@ export default class I18N extends AdminForthPlugin {
|
|
|
286
286
|
translatedCount = yield this.bulkTranslate({ selectedIds });
|
|
287
287
|
}
|
|
288
288
|
catch (e) {
|
|
289
|
+
process.env.HEAVY_DEBUG && console.error('🪲⛔ bulkTranslate error', e);
|
|
289
290
|
if (e instanceof AiTranslateError) {
|
|
290
|
-
process.env.HEAVY_DEBUG && console.error('🪲⛔ bulkTranslate error', e);
|
|
291
291
|
return { ok: false, error: e.message };
|
|
292
292
|
}
|
|
293
|
+
throw e;
|
|
293
294
|
}
|
|
294
|
-
process.env.HEAVY_DEBUG && console.log('🪲bulkTranslate done', translatedCount);
|
|
295
295
|
this.updateUntranslatedMenuBadge();
|
|
296
296
|
return {
|
|
297
297
|
ok: true,
|
|
@@ -345,9 +345,10 @@ export default class I18N extends AdminForthPlugin {
|
|
|
345
345
|
return totalTranslated;
|
|
346
346
|
}
|
|
347
347
|
const lang = langIsoCode;
|
|
348
|
+
const langName = iso6391.getName(lang);
|
|
348
349
|
const requestSlavicPlurals = Object.keys(SLAVIC_PLURAL_EXAMPLES).includes(lang) && plurals;
|
|
349
350
|
const prompt = `
|
|
350
|
-
I need to translate strings in JSON to ${lang} language from English for my web app.
|
|
351
|
+
I need to translate strings in JSON to ${lang} (${langName}) language from English for my web app.
|
|
351
352
|
${requestSlavicPlurals ? `You should provide 4 translations (in format zero | singular | 2-4 | 5+) e.g. ${SLAVIC_PLURAL_EXAMPLES[lang]}` : ''}
|
|
352
353
|
Keep keys, as is, write translation into values! Here are the strings:
|
|
353
354
|
|
|
@@ -358,10 +359,8 @@ ${JSON.stringify(strings.reduce((acc, s) => {
|
|
|
358
359
|
}, {}), null, 2)}
|
|
359
360
|
\`\`\`
|
|
360
361
|
`;
|
|
361
|
-
// process.env.HEAVY_DEBUG && console.log('🧠 llm prompt', prompt);
|
|
362
362
|
// call OpenAI
|
|
363
363
|
const resp = yield this.options.completeAdapter.complete(prompt, [], 300);
|
|
364
|
-
// process.env.HEAVY_DEBUG && console.log('🧠 llm resp', resp);
|
|
365
364
|
if (resp.error) {
|
|
366
365
|
throw new AiTranslateError(resp.error);
|
|
367
366
|
}
|
|
@@ -375,10 +374,16 @@ ${JSON.stringify(strings.reduce((acc, s) => {
|
|
|
375
374
|
res = resp.content.split("```json")[1].split("```")[0];
|
|
376
375
|
}
|
|
377
376
|
catch (e) {
|
|
378
|
-
console.error(`Error in parsing
|
|
377
|
+
console.error(`Error in parsing LLM resp: ${resp}\n Prompt was: ${prompt}\n Resp was: ${JSON.stringify(resp)}`);
|
|
378
|
+
return [];
|
|
379
|
+
}
|
|
380
|
+
try {
|
|
381
|
+
res = JSON.parse(res);
|
|
382
|
+
}
|
|
383
|
+
catch (e) {
|
|
384
|
+
console.error(`Error in parsing LLM resp json: ${resp}\n Prompt was: ${prompt}\n Resp was: ${JSON.stringify(resp)}`);
|
|
379
385
|
return [];
|
|
380
386
|
}
|
|
381
|
-
res = JSON.parse(res);
|
|
382
387
|
for (const [enStr, translatedStr] of Object.entries(res)) {
|
|
383
388
|
const translationsTargeted = translations.filter(t => t[this.enFieldName] === enStr);
|
|
384
389
|
// might be several with same en_string
|
|
@@ -421,24 +426,17 @@ ${JSON.stringify(strings.reduce((acc, s) => {
|
|
|
421
426
|
}
|
|
422
427
|
}
|
|
423
428
|
}
|
|
424
|
-
const maxKeysInOneReq = 10;
|
|
425
429
|
const updateStrings = {};
|
|
426
430
|
const langsInvolved = new Set(Object.keys(needToTranslateByLang));
|
|
427
431
|
let totalTranslated = [];
|
|
428
|
-
process.env.HEAVY_DEBUG && console.log(' 🐛starting Promise.all Object.entries(needToTranslateByLang)');
|
|
429
432
|
yield Promise.all(Object.entries(needToTranslateByLang).map((_b) => __awaiter(this, [_b], void 0, function* ([lang, strings]) {
|
|
430
433
|
// first translate without plurals
|
|
431
434
|
const stringsWithoutPlurals = strings.filter(s => !s.en_string.includes('|'));
|
|
432
|
-
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} noplurals started ${stringsWithoutPlurals.length}`);
|
|
433
435
|
const noPluralKeys = yield this.translateToLang(lang, stringsWithoutPlurals, false, translations, updateStrings);
|
|
434
|
-
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} noplurals finished`);
|
|
435
436
|
const stringsWithPlurals = strings.filter(s => s.en_string.includes('|'));
|
|
436
|
-
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} plurals started ${stringsWithPlurals.length}`);
|
|
437
437
|
const pluralKeys = yield this.translateToLang(lang, stringsWithPlurals, true, translations, updateStrings);
|
|
438
|
-
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} plurals finished`);
|
|
439
438
|
totalTranslated = totalTranslated.concat(noPluralKeys, pluralKeys);
|
|
440
439
|
})));
|
|
441
|
-
process.env.HEAVY_DEBUG && console.log('✅ updateStrings were formed', (new Set(totalTranslated)));
|
|
442
440
|
yield Promise.all(Object.entries(updateStrings).map((_c) => __awaiter(this, [_c], void 0, function* ([_, { updates, strId }]) {
|
|
443
441
|
// because this will translate all languages, we can set completedLangs to all languages
|
|
444
442
|
const futureCompletedFieldValue = this.fullCompleatedFieldValue;
|
package/index.ts
CHANGED
|
@@ -329,12 +329,12 @@ export default class I18N extends AdminForthPlugin {
|
|
|
329
329
|
try {
|
|
330
330
|
translatedCount = await this.bulkTranslate({ selectedIds });
|
|
331
331
|
} catch (e) {
|
|
332
|
+
process.env.HEAVY_DEBUG && console.error('🪲⛔ bulkTranslate error', e);
|
|
332
333
|
if (e instanceof AiTranslateError) {
|
|
333
|
-
process.env.HEAVY_DEBUG && console.error('🪲⛔ bulkTranslate error', e);
|
|
334
334
|
return { ok: false, error: e.message };
|
|
335
|
-
}
|
|
335
|
+
}
|
|
336
|
+
throw e;
|
|
336
337
|
}
|
|
337
|
-
process.env.HEAVY_DEBUG && console.log('🪲bulkTranslate done', translatedCount);
|
|
338
338
|
this.updateUntranslatedMenuBadge();
|
|
339
339
|
return {
|
|
340
340
|
ok: true,
|
|
@@ -395,11 +395,11 @@ export default class I18N extends AdminForthPlugin {
|
|
|
395
395
|
return totalTranslated;
|
|
396
396
|
}
|
|
397
397
|
const lang = langIsoCode;
|
|
398
|
-
|
|
398
|
+
const langName = iso6391.getName(lang);
|
|
399
399
|
const requestSlavicPlurals = Object.keys(SLAVIC_PLURAL_EXAMPLES).includes(lang) && plurals;
|
|
400
400
|
|
|
401
401
|
const prompt = `
|
|
402
|
-
I need to translate strings in JSON to ${lang} language from English for my web app.
|
|
402
|
+
I need to translate strings in JSON to ${lang} (${langName}) language from English for my web app.
|
|
403
403
|
${requestSlavicPlurals ? `You should provide 4 translations (in format zero | singular | 2-4 | 5+) e.g. ${SLAVIC_PLURAL_EXAMPLES[lang]}` : ''}
|
|
404
404
|
Keep keys, as is, write translation into values! Here are the strings:
|
|
405
405
|
|
|
@@ -411,9 +411,7 @@ JSON.stringify(strings.reduce((acc: object, s: { en_string: string }): object =>
|
|
|
411
411
|
}, {}), null, 2)
|
|
412
412
|
}
|
|
413
413
|
\`\`\`
|
|
414
|
-
`;
|
|
415
|
-
|
|
416
|
-
// process.env.HEAVY_DEBUG && console.log('🧠 llm prompt', prompt);
|
|
414
|
+
`;
|
|
417
415
|
|
|
418
416
|
// call OpenAI
|
|
419
417
|
const resp = await this.options.completeAdapter.complete(
|
|
@@ -422,8 +420,6 @@ JSON.stringify(strings.reduce((acc: object, s: { en_string: string }): object =>
|
|
|
422
420
|
300,
|
|
423
421
|
);
|
|
424
422
|
|
|
425
|
-
// process.env.HEAVY_DEBUG && console.log('🧠 llm resp', resp);
|
|
426
|
-
|
|
427
423
|
if (resp.error) {
|
|
428
424
|
throw new AiTranslateError(resp.error);
|
|
429
425
|
}
|
|
@@ -437,10 +433,16 @@ JSON.stringify(strings.reduce((acc: object, s: { en_string: string }): object =>
|
|
|
437
433
|
try {
|
|
438
434
|
res = resp.content.split("```json")[1].split("```")[0];
|
|
439
435
|
} catch (e) {
|
|
440
|
-
console.error(`Error in parsing
|
|
436
|
+
console.error(`Error in parsing LLM resp: ${resp}\n Prompt was: ${prompt}\n Resp was: ${JSON.stringify(resp)}`, );
|
|
437
|
+
return [];
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
try {
|
|
441
|
+
res = JSON.parse(res);
|
|
442
|
+
} catch (e) {
|
|
443
|
+
console.error(`Error in parsing LLM resp json: ${resp}\n Prompt was: ${prompt}\n Resp was: ${JSON.stringify(resp)}`, );
|
|
441
444
|
return [];
|
|
442
445
|
}
|
|
443
|
-
res = JSON.parse(res);
|
|
444
446
|
|
|
445
447
|
|
|
446
448
|
for (const [enStr, translatedStr] of Object.entries(res) as [string, string][]) {
|
|
@@ -500,8 +502,6 @@ JSON.stringify(strings.reduce((acc: object, s: { en_string: string }): object =>
|
|
|
500
502
|
}
|
|
501
503
|
}
|
|
502
504
|
|
|
503
|
-
const maxKeysInOneReq = 10;
|
|
504
|
-
|
|
505
505
|
const updateStrings: Record<string, {
|
|
506
506
|
updates: any,
|
|
507
507
|
category: string,
|
|
@@ -513,31 +513,24 @@ JSON.stringify(strings.reduce((acc: object, s: { en_string: string }): object =>
|
|
|
513
513
|
const langsInvolved = new Set(Object.keys(needToTranslateByLang));
|
|
514
514
|
|
|
515
515
|
let totalTranslated = [];
|
|
516
|
-
process.env.HEAVY_DEBUG && console.log(' 🐛starting Promise.all Object.entries(needToTranslateByLang)');
|
|
517
516
|
|
|
518
517
|
await Promise.all(
|
|
519
518
|
Object.entries(needToTranslateByLang).map(
|
|
520
519
|
async ([lang, strings]: [LanguageCode, { en_string: string, category: string }[]]) => {
|
|
521
520
|
// first translate without plurals
|
|
522
521
|
const stringsWithoutPlurals = strings.filter(s => !s.en_string.includes('|'));
|
|
523
|
-
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} noplurals started ${stringsWithoutPlurals.length}`);
|
|
524
522
|
const noPluralKeys = await this.translateToLang(lang, stringsWithoutPlurals, false, translations, updateStrings);
|
|
525
|
-
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} noplurals finished`);
|
|
526
523
|
|
|
527
524
|
|
|
528
525
|
const stringsWithPlurals = strings.filter(s => s.en_string.includes('|'));
|
|
529
526
|
|
|
530
|
-
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} plurals started ${stringsWithPlurals.length}`);
|
|
531
527
|
const pluralKeys = await this.translateToLang(lang, stringsWithPlurals, true, translations, updateStrings);
|
|
532
|
-
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} plurals finished`);
|
|
533
528
|
|
|
534
529
|
totalTranslated = totalTranslated.concat(noPluralKeys, pluralKeys);
|
|
535
530
|
}
|
|
536
531
|
)
|
|
537
532
|
);
|
|
538
533
|
|
|
539
|
-
process.env.HEAVY_DEBUG && console.log('✅ updateStrings were formed', (new Set(totalTranslated)));
|
|
540
|
-
|
|
541
534
|
await Promise.all(
|
|
542
535
|
Object.entries(updateStrings).map(
|
|
543
536
|
async ([_, { updates, strId }]: [string, { updates: any, category: string, strId: string }]) => {
|