diff --git a/src/lib/client/Client.ts b/src/lib/client/Client.ts index 1c2cabf..e9fbdf8 100644 --- a/src/lib/client/Client.ts +++ b/src/lib/client/Client.ts @@ -125,4 +125,13 @@ export const client = new class Client { return res.data.text } + public async translateToEn(content: string): Promise { + this.updateServerUrl() + + const res = await this._axios.post(`${this._serverUrl}/service/translate/toEn`, { + text: content + }) + + return res.data.text + } } diff --git a/src/lib/components/share/ChatInput.svelte b/src/lib/components/share/ChatInput.svelte index 2c7baa7..500b43e 100644 --- a/src/lib/components/share/ChatInput.svelte +++ b/src/lib/components/share/ChatInput.svelte @@ -23,7 +23,16 @@ $stateStore.input = text text = "" - await client.send($stateStore.input) + if (get(stateStore).translate) { + const translated = await client.translateToEn($stateStore.input) + + if (get(stateStore).debug) + console.log("Translated Text Submit: ", translated) + + await client.send(translated) + } else { + await client.send($stateStore.input) + } } const handleKeyDown = (event: KeyboardEvent) => {