Skip to content

Commit

Permalink
fix: improved fasttext/bergamot messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
Fevol committed Nov 30, 2022
1 parent c7cae16 commit 79b729a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/handlers/dummy-translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ export class DummyTranslate {
}

async detect(text: string): Promise<DetectionResult> {
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"};

Expand Down Expand Up @@ -96,8 +99,11 @@ export class DummyTranslate {


async translate(text: string, from: string, to: string, apply_glossary: boolean = false): Promise<TranslationResult> {
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)
Expand Down
3 changes: 2 additions & 1 deletion src/handlers/fasttext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {FastText, FastTextModel} from "./fasttext/fasttext";

export class FastTextDetector extends DummyTranslate {
detector: FastTextModel;
id = "fasttext";

version: number;

Expand Down Expand Up @@ -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.");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}}
>
<Icon icon={"download"} />
Expand Down

0 comments on commit 79b729a

Please sign in to comment.