From 79b729a882f697ce9dde9caf97beba1673b19205 Mon Sep 17 00:00:00 2001 From: Fevol Date: Wed, 30 Nov 2022 16:20:22 +0100 Subject: [PATCH] fix: improved fasttext/bergamot messaging --- src/handlers/dummy-translate.ts | 10 ++++++++-- src/handlers/fasttext.ts | 3 ++- src/main.ts | 2 +- .../settings-tabs/DetectorSettings.svelte | 2 ++ 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/handlers/dummy-translate.ts b/src/handlers/dummy-translate.ts index a3d4e4cb..e04fdf47 100644 --- a/src/handlers/dummy-translate.ts +++ b/src/handlers/dummy-translate.ts @@ -64,8 +64,11 @@ export class DummyTranslate { } async detect(text: string): Promise { - if (!this.valid) + if (!this.valid) { + if (this.id === "fasttext") + return {status_code: 400, message: "FastText is not installed"}; return {status_code: 400, message: "Translation service is not validated"}; + } if (!text.trim()) return {status_code: 400, message: "No text was provided"}; @@ -96,8 +99,11 @@ export class DummyTranslate { async translate(text: string, from: string, to: string, apply_glossary: boolean = false): Promise { - if (!this.valid) + if (!this.valid) { + if (this.id === "bergamot") + return {status_code: 400, message: "Bergamot is not installed"}; return {status_code: 400, message: "Translation service is not validated"}; + } if (!text.trim()) return {status_code: 400, message: "No text was provided"}; if (!to) diff --git a/src/handlers/fasttext.ts b/src/handlers/fasttext.ts index 4a25e3a7..9fade548 100644 --- a/src/handlers/fasttext.ts +++ b/src/handlers/fasttext.ts @@ -9,6 +9,7 @@ import {FastText, FastTextModel} from "./fasttext/fasttext"; export class FastTextDetector extends DummyTranslate { detector: FastTextModel; + id = "fasttext"; version: number; @@ -41,7 +42,7 @@ export class FastTextDetector extends DummyTranslate { }) } else { this.valid = false; - this.plugin.message_queue("FastText is not installed, automatic detection of language is disabled."); + // this.plugin.message_queue("FastText is not installed, automatic detection of language is disabled."); } } diff --git a/src/main.ts b/src/main.ts index ff79c96b..e29a63ef 100644 --- a/src/main.ts +++ b/src/main.ts @@ -94,11 +94,11 @@ export default class TranslatorPlugin extends Plugin { try { // @ts-ignore (path exists in legacy versions) await app.vault.adapter.rename(`.obsidian/${loaded_settings.storage_path}`, `.obsidian/plugins/obsidian-translate/models`); - // @ts-ignore (path exists in legacy versions) } catch (e) { // .obsidian/plugins/obsidian-translate/models already exists, shouldn't be an issue for 99% of users console.error(e); } + // @ts-ignore (path exists in legacy versions) delete loaded_settings.storage_path; } diff --git a/src/ui/translator-components/settings-tabs/DetectorSettings.svelte b/src/ui/translator-components/settings-tabs/DetectorSettings.svelte index 892033cd..1d0deb73 100644 --- a/src/ui/translator-components/settings-tabs/DetectorSettings.svelte +++ b/src/ui/translator-components/settings-tabs/DetectorSettings.svelte @@ -62,6 +62,8 @@ if (!detector?.detector) detector.setup_service($data.models.fasttext); detector.valid = true; + if ($settings.service_settings.fasttext.default_usage) + plugin.detector = detector; }} >