Add types for global translation function
| @@ -40,4 +40,12 @@ declare global { | |||
| 40 | searchInputCssClass?: string; | 40 | searchInputCssClass?: string; |
| 41 | } | 41 | } |
| 42 | } | 42 | } |
| 43 | |||
| 44 | /** | ||
| 45 | * Translates a text to a target language using a translation provider. | ||
| 46 | * @param text Text to translate | ||
| 47 | * @param lang Target language | ||
| 48 | * @param provider Translation provider | ||
| 49 | */ | ||
| 50 | async function translate(text: string, lang: string, provider: string = null): Promise<string>; | ||
| 43 | } | 51 | } |
| @@ -929,8 +929,8 @@ export async function getExpressionLabel(text, expressionsApi = extension_settin | |||
| 929 | return extension_settings.expressions.fallback_expression; | 929 | return extension_settings.expressions.fallback_expression; |
| 930 | } | 930 | } |
| 931 | 931 | ||
| 932 | if (extension_settings.expressions.translate && typeof window['translate'] === 'function') { | 932 | if (extension_settings.expressions.translate && typeof globalThis.translate === 'function') { |
| 933 | text = await window['translate'](text, 'en'); | 933 | text = await globalThis.translate(text, 'en'); |
| 934 | } | 934 | } |
| 935 | 935 | ||
| 936 | text = sampleClassifyText(text); | 936 | text = sampleClassifyText(text); |
| @@ -605,7 +605,7 @@ const handleOutgoingMessage = createEventHandler(translateOutgoingMessage, () => | |||
| 605 | const handleImpersonateReady = createEventHandler(translateImpersonate, () => shouldTranslate(incomingTypes)); | 605 | const handleImpersonateReady = createEventHandler(translateImpersonate, () => shouldTranslate(incomingTypes)); |
| 606 | const handleMessageEdit = createEventHandler(translateMessageEdit, () => true); | 606 | const handleMessageEdit = createEventHandler(translateMessageEdit, () => true); |
| 607 | 607 | ||
| 608 | window['translate'] = translate; | 608 | globalThis.translate = translate; |
| 609 | 609 | ||
| 610 | jQuery(async () => { | 610 | jQuery(async () => { |
| 611 | const html = await renderExtensionTemplateAsync('translate', 'index'); | 611 | const html = await renderExtensionTemplateAsync('translate', 'index'); |
| @@ -561,9 +561,9 @@ async function retrieveFileChunks(queryText, collectionId) { | |||
| 561 | */ | 561 | */ |
| 562 | async function vectorizeFile(fileText, fileName, collectionId, chunkSize, overlapPercent) { | 562 | async function vectorizeFile(fileText, fileName, collectionId, chunkSize, overlapPercent) { |
| 563 | try { | 563 | try { |
| 564 | if (settings.translate_files && typeof window['translate'] === 'function') { | 564 | if (settings.translate_files && typeof globalThis.translate === 'function') { |
| 565 | console.log(`Vectors: Translating file ${fileName} to English...`); | 565 | console.log(`Vectors: Translating file ${fileName} to English...`); |
| 566 | const translatedText = await window['translate'](fileText, 'en'); | 566 | const translatedText = await globalThis.translate(fileText, 'en'); |
| 567 | fileText = translatedText; | 567 | fileText = translatedText; |
| 568 | } | 568 | } |
| 569 | 569 | ||