Add types for global translation function

58bbfc0d4ebeefb0590fab5a9583cd3d43addb05

Cohee <18619528+Cohee1207@users.noreply.github.com>

4 files changed, +13 -5Ignore whitespace
public/global.d.ts+8 -0
@@ -40,4 +40,12 @@ declare global {
4040 searchInputCssClass?: string;
4141 }
4242 }
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>;
4351}
public/scripts/extensions/expressions/index.js+2 -2
@@ -929,8 +929,8 @@ export async function getExpressionLabel(text, expressionsApi = extension_settin
929929 return extension_settings.expressions.fallback_expression;
930930 }
931931
932932 if (extension_settings.expressions.translate && typeof window['globalThis.translate'] === 'function') {
933933 text = await window['globalThis.translate'](text, 'en');
934934 }
935935
936936 text = sampleClassifyText(text);
public/scripts/extensions/translate/index.js+1 -1
@@ -605,7 +605,7 @@ const handleOutgoingMessage = createEventHandler(translateOutgoingMessage, () =>
605605const handleImpersonateReady = createEventHandler(translateImpersonate, () => shouldTranslate(incomingTypes));
606606const handleMessageEdit = createEventHandler(translateMessageEdit, () => true);
607607
608608window['globalThis.translate'] = translate;
609609
610610jQuery(async () => {
611611 const html = await renderExtensionTemplateAsync('translate', 'index');
public/scripts/extensions/vectors/index.js+2 -2
@@ -561,9 +561,9 @@ async function retrieveFileChunks(queryText, collectionId) {
561561 */
562562async function vectorizeFile(fileText, fileName, collectionId, chunkSize, overlapPercent) {
563563 try {
564564 if (settings.translate_files && typeof window['globalThis.translate'] === 'function') {
565565 console.log(`Vectors: Translating file ${fileName} to English...`);
566566 const translatedText = await window['globalThis.translate'](fileText, 'en');
567567 fileText = translatedText;
568568 }
569569