* Translate a list of texts to a target language * @param {{key:string, text:string}[]} textList - Text array to translate * @param {string} targetLanguage - Target language (e.g., "zh-CN", "en-US") * @returns {Promise<{key:string, text:string}[]>} - Translated text array
(chatAiSession, textList = [], targetLanguage = "")
| 93 | * @returns {Promise<{key:string, text:string}[]>} - Translated text array |
| 94 | */ |
| 95 | async function translateText(chatAiSession, textList = [], targetLanguage = "") { |
| 96 | const result = await chatAiSession.sendMessage(JSON.stringify(textList), (text) => { |
| 97 | process.stdout.write(text || ""); |
| 98 | }); |
| 99 | let text = result.content; |
| 100 | text = text.replace(/^```json\n/, "").replace(/\n```$/, ""); |
| 101 | return JSON.parse(text); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Use en_US.json as the standard to fill missing keys in other language files |
no test coverage detected