fix: revert old google translate api

This commit is contained in:
Gabe
2025-06-26 11:13:51 +08:00
parent a6cb5544f8
commit eaa47af269
3 changed files with 26 additions and 23 deletions

View File

@@ -256,19 +256,10 @@ export const apiTranslate = async ({
);
switch (translator) {
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;
}
case OPT_TRANS_GOOGLE:
trText = res.sentences.map((item) => item.trans).join(" ");
isSame = to === res.src;
break;
}
case OPT_TRANS_MICROSOFT:
trText = res
.map((item) => item.translations.map((item) => item.text).join(" "))