mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2024-12-11 17:07:07 +01:00
Merge pull request #3059 from yar3333/staging
Exclude links to embedded images from translation
This commit is contained in:
commit
664a531c22
@ -406,33 +406,50 @@ async function translate(text, lang) {
|
|||||||
lang = extension_settings.translate.target_language;
|
lang = extension_settings.translate.target_language;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (extension_settings.translate.provider) {
|
// split text by embedded images links
|
||||||
case 'libre':
|
const chunks = text.split(/!\[.*?]\([^)]*\)/);
|
||||||
return await translateProviderLibre(text, lang);
|
const links = [ ...text.matchAll(/!\[.*?]\([^)]*\)/g) ];
|
||||||
case 'google':
|
|
||||||
return await chunkedTranslate(text, lang, translateProviderGoogle, 5000);
|
let r = "";
|
||||||
case 'lingva':
|
for (let i = 0; i < chunks.length; i++) {
|
||||||
return await chunkedTranslate(text, lang, translateProviderLingva, 5000);
|
r += await translateInner(chunks[i], lang);
|
||||||
case 'deepl':
|
if (i < links.length) r += links[i][0];
|
||||||
return await translateProviderDeepl(text, lang);
|
|
||||||
case 'deeplx':
|
|
||||||
return await chunkedTranslate(text, lang, translateProviderDeepLX, 1500);
|
|
||||||
case 'oneringtranslator':
|
|
||||||
return await translateProviderOneRing(text, lang);
|
|
||||||
case 'bing':
|
|
||||||
return await chunkedTranslate(text, lang, translateProviderBing, 1000);
|
|
||||||
case 'yandex':
|
|
||||||
return await translateProviderYandex(text, lang);
|
|
||||||
default:
|
|
||||||
console.error('Unknown translation provider', extension_settings.translate.provider);
|
|
||||||
return text;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
toastr.error(String(error), 'Failed to translate message');
|
toastr.error(String(error), 'Failed to translate message');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function translateInner(text, lang) {
|
||||||
|
if (text == '') {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
switch (extension_settings.translate.provider) {
|
||||||
|
case 'libre':
|
||||||
|
return await translateProviderLibre(text, lang);
|
||||||
|
case 'google':
|
||||||
|
return await chunkedTranslate(text, lang, translateProviderGoogle, 5000);
|
||||||
|
case 'lingva':
|
||||||
|
return await chunkedTranslate(text, lang, translateProviderLingva, 5000);
|
||||||
|
case 'deepl':
|
||||||
|
return await translateProviderDeepl(text, lang);
|
||||||
|
case 'deeplx':
|
||||||
|
return await chunkedTranslate(text, lang, translateProviderDeepLX, 1500);
|
||||||
|
case 'oneringtranslator':
|
||||||
|
return await translateProviderOneRing(text, lang);
|
||||||
|
case 'bing':
|
||||||
|
return await chunkedTranslate(text, lang, translateProviderBing, 1000);
|
||||||
|
case 'yandex':
|
||||||
|
return await translateProviderYandex(text, lang);
|
||||||
|
default:
|
||||||
|
console.error('Unknown translation provider', extension_settings.translate.provider);
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function translateOutgoingMessage(messageId) {
|
async function translateOutgoingMessage(messageId) {
|
||||||
const context = getContext();
|
const context = getContext();
|
||||||
const message = context.chat[messageId];
|
const message = context.chat[messageId];
|
||||||
|
Loading…
Reference in New Issue
Block a user