MCPcopy Create free account
hub / github.com/MCSManager/MCSManager / translateText

Function translateText

scripts/auto-translate.mjs:95–102  ·  view source on GitHub ↗

* 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 = "")

Source from the content-addressed store, hash-verified

93 * @returns {Promise<{key:string, text:string}[]>} - Translated text array
94 */
95async 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

Callers 1

processFileFunction · 0.85

Calls 2

sendMessageMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected