mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add types for global translation function
This commit is contained in:
8
public/global.d.ts
vendored
8
public/global.d.ts
vendored
@ -40,4 +40,12 @@ declare global {
|
|||||||
searchInputCssClass?: string;
|
searchInputCssClass?: string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translates a text to a target language using a translation provider.
|
||||||
|
* @param text Text to translate
|
||||||
|
* @param lang Target language
|
||||||
|
* @param provider Translation provider
|
||||||
|
*/
|
||||||
|
async function translate(text: string, lang: string, provider: string = null): Promise<string>;
|
||||||
}
|
}
|
||||||
|
@ -929,8 +929,8 @@ export async function getExpressionLabel(text, expressionsApi = extension_settin
|
|||||||
return extension_settings.expressions.fallback_expression;
|
return extension_settings.expressions.fallback_expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extension_settings.expressions.translate && typeof window['translate'] === 'function') {
|
if (extension_settings.expressions.translate && typeof globalThis.translate === 'function') {
|
||||||
text = await window['translate'](text, 'en');
|
text = await globalThis.translate(text, 'en');
|
||||||
}
|
}
|
||||||
|
|
||||||
text = sampleClassifyText(text);
|
text = sampleClassifyText(text);
|
||||||
|
@ -605,7 +605,7 @@ const handleOutgoingMessage = createEventHandler(translateOutgoingMessage, () =>
|
|||||||
const handleImpersonateReady = createEventHandler(translateImpersonate, () => shouldTranslate(incomingTypes));
|
const handleImpersonateReady = createEventHandler(translateImpersonate, () => shouldTranslate(incomingTypes));
|
||||||
const handleMessageEdit = createEventHandler(translateMessageEdit, () => true);
|
const handleMessageEdit = createEventHandler(translateMessageEdit, () => true);
|
||||||
|
|
||||||
window['translate'] = translate;
|
globalThis.translate = translate;
|
||||||
|
|
||||||
jQuery(async () => {
|
jQuery(async () => {
|
||||||
const html = await renderExtensionTemplateAsync('translate', 'index');
|
const html = await renderExtensionTemplateAsync('translate', 'index');
|
||||||
|
@ -561,9 +561,9 @@ async function retrieveFileChunks(queryText, collectionId) {
|
|||||||
*/
|
*/
|
||||||
async function vectorizeFile(fileText, fileName, collectionId, chunkSize, overlapPercent) {
|
async function vectorizeFile(fileText, fileName, collectionId, chunkSize, overlapPercent) {
|
||||||
try {
|
try {
|
||||||
if (settings.translate_files && typeof window['translate'] === 'function') {
|
if (settings.translate_files && typeof globalThis.translate === 'function') {
|
||||||
console.log(`Vectors: Translating file ${fileName} to English...`);
|
console.log(`Vectors: Translating file ${fileName} to English...`);
|
||||||
const translatedText = await window['translate'](fileText, 'en');
|
const translatedText = await globalThis.translate(fileText, 'en');
|
||||||
fileText = translatedText;
|
fileText = translatedText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user