🐞 fix: 修复翻译为单例模式

This commit is contained in:
zhiyu1998 2024-09-09 21:59:07 +08:00
parent 2fa0294311
commit b57c9212bf

View File

@ -118,7 +118,7 @@ class DeeplTranslateStrategy extends TranslateStrategy {
export default class Translate { export default class Translate {
constructor(config) { constructor(config) {
this.config = config; this.config = config;
this.strategy = this.selectStrategy(); this.strategy = null;
} }
selectStrategy() { selectStrategy() {
@ -133,7 +133,7 @@ export default class Translate {
async translate(query, targetLanguage) { async translate(query, targetLanguage) {
if (!this.strategy) { if (!this.strategy) {
throw new Error("无翻译策略可用"); this.strategy = this.selectStrategy();
} }
return this.strategy.translate(query, targetLanguage); return this.strategy.translate(query, targetLanguage);
} }