fix: update API for Google Translate

This commit is contained in:
Bush2021
2025-04-16 18:00:54 -04:00
parent 77c6102de7
commit 84432e98ae
3 changed files with 23 additions and 22 deletions

View File

@@ -255,10 +255,19 @@ export const apiTranslate = async ({
);
switch (translator) {
case OPT_TRANS_GOOGLE:
trText = res.sentences.map((item) => item.trans).join(" ");
isSame = to === res.src;
case OPT_TRANS_GOOGLE: {
if (!res || !Array.isArray(res) || res.length < 2) {
console.error("Unexpected response structure:", res);
trText = "Error: Invalid response structure";
isSame = false;
} else {
const translatedText = Array.isArray(res[0]) ? res[0].join(" ") : "Translation unavailable";
const isTranslationComplete = to === (Array.isArray(res[1]) ? res[1][0] : undefined);
trText = translatedText;
isSame = isTranslationComplete;
}
break;
}
case OPT_TRANS_MICROSOFT:
trText = res
.map((item) => item.translations.map((item) => item.text).join(" "))