From eea99c6ea27a20d7833ec5477ba8e362fc477bd2 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Mon, 17 Mar 2025 16:08:11 +0900 Subject: [PATCH] Change bergamotTranslator to dynamic import --- src/ts/translator/translator.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ts/translator/translator.ts b/src/ts/translator/translator.ts index 463872d1..6f13b819 100644 --- a/src/ts/translator/translator.ts +++ b/src/ts/translator/translator.ts @@ -10,7 +10,6 @@ import { selectedCharID } from "../stores.svelte" import { getModuleRegexScripts } from "../process/modules" import { getNodetextToSentence, sleep } from "../util" import { processScriptFull } from "../process/scripts" -import { bergamotTranslate } from "./bergamotTranslator" import localforage from "localforage" import sendSound from '../../etc/send.mp3' @@ -19,6 +18,8 @@ let cache={ trans: [''] } +let bergamotTranslate: (text: string, from: string, to: string, html?: boolean) => Promise|null = null + export const LLMCacheStorage = localforage.createInstance({ name: "LLMTranslateCache" }) @@ -167,6 +168,11 @@ async function translateMain(text:string, arg:{from:string, to:string, host:stri return f.data.data; } if(db.translatorType == "bergamot") { + if(!bergamotTranslate){ + const bergamotTranslator = await import('./bergamotTranslator') + bergamotTranslate = bergamotTranslator.bergamotTranslate + } + return bergamotTranslate(text, arg.from, arg.to, false); } if(db.useExperimentalGoogleTranslator){