@adminforth/i18n 1.3.1 → 1.3.3
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/dist/index.js +5 -3
- package/index.ts +7 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -366,8 +366,9 @@ export default class I18nPlugin extends AdminForthPlugin {
|
|
|
366
366
|
id: 'translate_all',
|
|
367
367
|
label: 'Translate selected',
|
|
368
368
|
icon: 'flowbite:language-outline',
|
|
369
|
+
badge: 'AI',
|
|
369
370
|
// if optional `confirm` is provided, user will be asked to confirm action
|
|
370
|
-
confirm: 'Are you sure you want to translate selected items?',
|
|
371
|
+
confirm: 'Are you sure you want to translate selected items? Only empty strings will be translated',
|
|
371
372
|
allowed: (_a) => __awaiter(this, [_a], void 0, function* ({ resource, adminUser, selectedIds, allowedActions }) {
|
|
372
373
|
process.env.HEAVY_DEBUG && console.log('allowedActions', JSON.stringify(allowedActions));
|
|
373
374
|
return allowedActions.edit;
|
|
@@ -440,9 +441,9 @@ export default class I18nPlugin extends AdminForthPlugin {
|
|
|
440
441
|
const langName = iso6391.getName(lang);
|
|
441
442
|
const requestSlavicPlurals = Object.keys(SLAVIC_PLURAL_EXAMPLES).includes(lang) && plurals;
|
|
442
443
|
const prompt = `
|
|
443
|
-
I need to translate strings in JSON to ${
|
|
444
|
+
I need to translate strings in JSON to ${langName} language (ISO 639-1 code ${lang}) from English for my web app.
|
|
444
445
|
${requestSlavicPlurals ? `You should provide 4 slavic forms (in format "zero count | singular count | 2-4 | 5+") e.g. "apple | apples" should become "${SLAVIC_PLURAL_EXAMPLES[lang]}"` : ''}
|
|
445
|
-
Keep keys, as is, write translation into values! Here are the strings:
|
|
446
|
+
Keep keys, as is, write translation into values! If keys have variables (in curly brackets), then translated strings should have them as well (variables itself should not be translated). Here are the strings:
|
|
446
447
|
|
|
447
448
|
\`\`\`json
|
|
448
449
|
${JSON.stringify(strings.reduce((acc, s) => {
|
|
@@ -451,6 +452,7 @@ ${JSON.stringify(strings.reduce((acc, s) => {
|
|
|
451
452
|
}, {}), null, 2)}
|
|
452
453
|
\`\`\`
|
|
453
454
|
`;
|
|
455
|
+
process.env.HEAVY_DEBUG && console.log(`🪲🔪LLM prompt >> ${prompt.length}, <<${prompt} :\n\n`, JSON.stringify(prompt));
|
|
454
456
|
// call OpenAI
|
|
455
457
|
const resp = yield this.options.completeAdapter.complete(prompt, [], prompt.length * 2);
|
|
456
458
|
process.env.HEAVY_DEBUG && console.log(`🪲🔪LLM resp >> ${prompt.length}, <<${resp.content.length} :\n\n`, JSON.stringify(resp));
|
package/index.ts
CHANGED
|
@@ -417,8 +417,9 @@ export default class I18nPlugin extends AdminForthPlugin {
|
|
|
417
417
|
id: 'translate_all',
|
|
418
418
|
label: 'Translate selected',
|
|
419
419
|
icon: 'flowbite:language-outline',
|
|
420
|
+
badge: 'AI',
|
|
420
421
|
// if optional `confirm` is provided, user will be asked to confirm action
|
|
421
|
-
confirm: 'Are you sure you want to translate selected items?',
|
|
422
|
+
confirm: 'Are you sure you want to translate selected items? Only empty strings will be translated',
|
|
422
423
|
allowed: async ({ resource, adminUser, selectedIds, allowedActions }) => {
|
|
423
424
|
process.env.HEAVY_DEBUG && console.log('allowedActions', JSON.stringify(allowedActions));
|
|
424
425
|
return allowedActions.edit;
|
|
@@ -498,9 +499,9 @@ export default class I18nPlugin extends AdminForthPlugin {
|
|
|
498
499
|
const requestSlavicPlurals = Object.keys(SLAVIC_PLURAL_EXAMPLES).includes(lang) && plurals;
|
|
499
500
|
|
|
500
501
|
const prompt = `
|
|
501
|
-
I need to translate strings in JSON to ${
|
|
502
|
+
I need to translate strings in JSON to ${langName} language (ISO 639-1 code ${lang}) from English for my web app.
|
|
502
503
|
${requestSlavicPlurals ? `You should provide 4 slavic forms (in format "zero count | singular count | 2-4 | 5+") e.g. "apple | apples" should become "${SLAVIC_PLURAL_EXAMPLES[lang]}"` : ''}
|
|
503
|
-
Keep keys, as is, write translation into values! Here are the strings:
|
|
504
|
+
Keep keys, as is, write translation into values! If keys have variables (in curly brackets), then translated strings should have them as well (variables itself should not be translated). Here are the strings:
|
|
504
505
|
|
|
505
506
|
\`\`\`json
|
|
506
507
|
${
|
|
@@ -512,6 +513,8 @@ JSON.stringify(strings.reduce((acc: object, s: { en_string: string }): object =>
|
|
|
512
513
|
\`\`\`
|
|
513
514
|
`;
|
|
514
515
|
|
|
516
|
+
process.env.HEAVY_DEBUG && console.log(`🪲🔪LLM prompt >> ${prompt.length}, <<${prompt} :\n\n`, JSON.stringify(prompt));
|
|
517
|
+
|
|
515
518
|
// call OpenAI
|
|
516
519
|
const resp = await this.options.completeAdapter.complete(
|
|
517
520
|
prompt,
|
|
@@ -520,7 +523,7 @@ JSON.stringify(strings.reduce((acc: object, s: { en_string: string }): object =>
|
|
|
520
523
|
);
|
|
521
524
|
|
|
522
525
|
process.env.HEAVY_DEBUG && console.log(`🪲🔪LLM resp >> ${prompt.length}, <<${resp.content.length} :\n\n`, JSON.stringify(resp));
|
|
523
|
-
|
|
526
|
+
|
|
524
527
|
if (resp.error) {
|
|
525
528
|
throw new AiTranslateError(resp.error);
|
|
526
529
|
}
|