Skip to content

Commit 8e068c8

Browse files
committed
fix: instruct LLM to translate variables in curly brackets smoothly
1 parent 7948458 commit 8e068c8

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,9 @@ export default class I18nPlugin extends AdminForthPlugin {
498498
const requestSlavicPlurals = Object.keys(SLAVIC_PLURAL_EXAMPLES).includes(lang) && plurals;
499499

500500
const prompt = `
501-
I need to translate strings in JSON to ${lang} (${langName}) language from English for my web app.
501+
I need to translate strings in JSON to ${langName} language (ISO 639-1 code ${lang}) from English for my web app.
502502
${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:
503+
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:
504504
505505
\`\`\`json
506506
${
@@ -512,6 +512,8 @@ JSON.stringify(strings.reduce((acc: object, s: { en_string: string }): object =>
512512
\`\`\`
513513
`;
514514

515+
process.env.HEAVY_DEBUG && console.log(`🪲🔪LLM prompt >> ${prompt.length}, <<${prompt} :\n\n`, JSON.stringify(prompt));
516+
515517
// call OpenAI
516518
const resp = await this.options.completeAdapter.complete(
517519
prompt,
@@ -520,7 +522,7 @@ JSON.stringify(strings.reduce((acc: object, s: { en_string: string }): object =>
520522
);
521523

522524
process.env.HEAVY_DEBUG && console.log(`🪲🔪LLM resp >> ${prompt.length}, <<${resp.content.length} :\n\n`, JSON.stringify(resp));
523-
525+
524526
if (resp.error) {
525527
throw new AiTranslateError(resp.error);
526528
}

0 commit comments

Comments
 (0)