@adminforth/i18n 1.0.18-next.9 → 1.0.19-next.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/custom/LanguageInUserMenu.vue +19 -15
- package/custom/LanguageUnderLogin.vue +1 -0
- package/dist/custom/LanguageInUserMenu.vue +19 -15
- package/dist/custom/LanguageUnderLogin.vue +1 -0
- package/dist/index.js +11 -12
- package/index.ts +14 -18
- 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
|
@@ -290,8 +290,8 @@ export default class I18N extends AdminForthPlugin {
|
|
|
290
290
|
if (e instanceof AiTranslateError) {
|
|
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
|
|
@@ -424,20 +429,14 @@ ${JSON.stringify(strings.reduce((acc, s) => {
|
|
|
424
429
|
const updateStrings = {};
|
|
425
430
|
const langsInvolved = new Set(Object.keys(needToTranslateByLang));
|
|
426
431
|
let totalTranslated = [];
|
|
427
|
-
process.env.HEAVY_DEBUG && console.log(' 🐛starting Promise.all Object.entries(needToTranslateByLang)');
|
|
428
432
|
yield Promise.all(Object.entries(needToTranslateByLang).map((_b) => __awaiter(this, [_b], void 0, function* ([lang, strings]) {
|
|
429
433
|
// first translate without plurals
|
|
430
434
|
const stringsWithoutPlurals = strings.filter(s => !s.en_string.includes('|'));
|
|
431
|
-
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} noplurals started ${stringsWithoutPlurals.length}`);
|
|
432
435
|
const noPluralKeys = yield this.translateToLang(lang, stringsWithoutPlurals, false, translations, updateStrings);
|
|
433
|
-
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} noplurals finished`);
|
|
434
436
|
const stringsWithPlurals = strings.filter(s => s.en_string.includes('|'));
|
|
435
|
-
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} plurals started ${stringsWithPlurals.length}`);
|
|
436
437
|
const pluralKeys = yield this.translateToLang(lang, stringsWithPlurals, true, translations, updateStrings);
|
|
437
|
-
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} plurals finished`);
|
|
438
438
|
totalTranslated = totalTranslated.concat(noPluralKeys, pluralKeys);
|
|
439
439
|
})));
|
|
440
|
-
process.env.HEAVY_DEBUG && console.log('✅ updateStrings were formed', (new Set(totalTranslated)));
|
|
441
440
|
yield Promise.all(Object.entries(updateStrings).map((_c) => __awaiter(this, [_c], void 0, function* ([_, { updates, strId }]) {
|
|
442
441
|
// because this will translate all languages, we can set completedLangs to all languages
|
|
443
442
|
const futureCompletedFieldValue = this.fullCompleatedFieldValue;
|
package/index.ts
CHANGED
|
@@ -332,9 +332,9 @@ export default class I18N extends AdminForthPlugin {
|
|
|
332
332
|
process.env.HEAVY_DEBUG && console.error('🪲⛔ bulkTranslate error', e);
|
|
333
333
|
if (e instanceof AiTranslateError) {
|
|
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,17 @@ 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
|
-
|
|
446
|
+
|
|
444
447
|
|
|
445
448
|
for (const [enStr, translatedStr] of Object.entries(res) as [string, string][]) {
|
|
446
449
|
const translationsTargeted = translations.filter(t => t[this.enFieldName] === enStr);
|
|
@@ -510,31 +513,24 @@ JSON.stringify(strings.reduce((acc: object, s: { en_string: string }): object =>
|
|
|
510
513
|
const langsInvolved = new Set(Object.keys(needToTranslateByLang));
|
|
511
514
|
|
|
512
515
|
let totalTranslated = [];
|
|
513
|
-
process.env.HEAVY_DEBUG && console.log(' 🐛starting Promise.all Object.entries(needToTranslateByLang)');
|
|
514
516
|
|
|
515
517
|
await Promise.all(
|
|
516
518
|
Object.entries(needToTranslateByLang).map(
|
|
517
519
|
async ([lang, strings]: [LanguageCode, { en_string: string, category: string }[]]) => {
|
|
518
520
|
// first translate without plurals
|
|
519
521
|
const stringsWithoutPlurals = strings.filter(s => !s.en_string.includes('|'));
|
|
520
|
-
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} noplurals started ${stringsWithoutPlurals.length}`);
|
|
521
522
|
const noPluralKeys = await this.translateToLang(lang, stringsWithoutPlurals, false, translations, updateStrings);
|
|
522
|
-
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} noplurals finished`);
|
|
523
523
|
|
|
524
524
|
|
|
525
525
|
const stringsWithPlurals = strings.filter(s => s.en_string.includes('|'));
|
|
526
526
|
|
|
527
|
-
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} plurals started ${stringsWithPlurals.length}`);
|
|
528
527
|
const pluralKeys = await this.translateToLang(lang, stringsWithPlurals, true, translations, updateStrings);
|
|
529
|
-
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} plurals finished`);
|
|
530
528
|
|
|
531
529
|
totalTranslated = totalTranslated.concat(noPluralKeys, pluralKeys);
|
|
532
530
|
}
|
|
533
531
|
)
|
|
534
532
|
);
|
|
535
533
|
|
|
536
|
-
process.env.HEAVY_DEBUG && console.log('✅ updateStrings were formed', (new Set(totalTranslated)));
|
|
537
|
-
|
|
538
534
|
await Promise.all(
|
|
539
535
|
Object.entries(updateStrings).map(
|
|
540
536
|
async ([_, { updates, strId }]: [string, { updates: any, category: string, strId: string }]) => {
|