fix: update API for Google Translate
This commit is contained in:
@@ -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(" "))
|
||||
|
||||
Reference in New Issue
Block a user