Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/plugins/translate/plugin.translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,19 @@ export class TranslatePlugin extends BookReaderPlugin {
}

handleToggleTranslation = async () => {
// If enabling translation, check if languages are the same
if (!this.userToggleTranslate) {
// Check if from and to languages are the same
if (this.langFromCode === this.langToCode) {
alert("You cannot translate to/from the same language.");
// Keep translation disabled
this.userToggleTranslate = false;
this.translationManager.active = false;
this._render();
return;
}
}

this.userToggleTranslate = !this.userToggleTranslate;
this.translationManager.active = this.userToggleTranslate;

Expand Down Expand Up @@ -427,9 +440,6 @@ export class BrTranslatePanel extends LitElement {
}
</select>
</details>
<div class="footer" id="status" style="margin-top:5%">
${this._statusWarning()}
</div>

<div class="lang-models-loading">
${this._languageModelStatus()}
Expand Down Expand Up @@ -485,18 +495,9 @@ export class BrTranslatePanel extends LitElement {
bubbles: true,
composed:true,
});
this.userTranslationActive = !this.userTranslationActive;
this.dispatchEvent(toggleTranslateEvent);
}

// TODO: Hardcoded warning message for now but should add more statuses
_statusWarning() {
if (this.detectedFromLang == this.detectedToLang) {
return "Translate To language is the same as the Source language";
}
return "";
}

_languageModelStatus() {
if (this.userTranslationActive) {
if (this.loadingModel) {
Expand Down