-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor the filename; add setting to change translator provider
- Loading branch information
Showing
8 changed files
with
70 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import { TranslatorProvider } from "@/services/setting.service" | ||
|
||
export type TranslateSettingModel = { | ||
active: boolean | ||
targetLanguage: string | ||
corsProxy: string | ||
corsProxy: string, | ||
provider: `${TranslatorProvider}` | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { GoogleTranslator } from "@translate-tools/core/translators/GoogleTranslator"; | ||
import { YandexTranslator } from "@translate-tools/core/translators/YandexTranslator"; | ||
import { TranslatorProvider, settingService } from "./setting.service"; | ||
import { BaseTranslator } from "@translate-tools/core/translators/BaseTranslator"; | ||
|
||
export class TranslatorService { | ||
|
||
/** | ||
* Translates the input text from Japanese to the target language using Google Translate | Yandex. | ||
* @param {string} text - The text to be translated. | ||
*/ | ||
public async translate(text: string): Promise<string> { | ||
const options = { | ||
corsProxy: settingService.getTranslatorSetting().corsProxy, | ||
} | ||
const translator: BaseTranslator = settingService.getTranslatorSetting().provider === TranslatorProvider.GOOGLE | ||
? new GoogleTranslator(options) | ||
: new YandexTranslator(options); | ||
const res = await translator.translate(text, "ja", settingService.getTranslatorSetting().targetLanguage); | ||
return res; | ||
} | ||
} | ||
|
||
export const translatorService = new TranslatorService() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters