fix: Prevent translation with identical source and target languages #1488#1498
Conversation
- Add validation to alert user when attempting to translate to/from same language - Remove redundant plaintext warning from the translate panel - Fixes endless spinner issue when same language is selected
There was a problem hiding this comment.
Pull request overview
Prevents users from initiating a translation when the selected source and target languages are the same, addressing the “endless spinner with no feedback” behavior reported in #1488.
Changes:
- Added a same-language guard in the Translate button handler to block starting translation and show an alert.
- Removed the previous plaintext same-language warning from the panel footer.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Prevent translating when source and target are identical | ||
| if (this.detectedFromLang === this.detectedToLang) { |
There was a problem hiding this comment.
The new same-language guard runs unconditionally, which also blocks turning translation off if the user is currently translating and then changes the From/To dropdowns to the same language. In that state the button reads "Stop Translating", but clicking it will only alert and return, leaving translation stuck on. Consider only preventing the toggle when starting translation (e.g., when !this.userTranslationActive) or otherwise allow the stop action even if languages match.
| // Prevent translating when source and target are identical | |
| if (this.detectedFromLang === this.detectedToLang) { | |
| // Prevent starting translation when source and target are identical | |
| if (!this.userTranslationActive && this.detectedFromLang === this.detectedToLang) { |
Description
Fixes issue #1488 where clicking "Translate" with identical source and target languages causes the spinner to spin endlessly without any user feedback.
Changes
This PR prevents translation requests when source and target languages are the same by:
Added validation in
_toggleTranslation()- Before initiating translation, the method now checks ifdetectedFromLangequalsdetectedToLang. If they match, an alert is shown to the user with the message "You cannot translate to/from the same language" and the translation is not started.Removed redundant UI warning - The plaintext warning "Translate To language is the same as the Source language" has been removed from the
_statusWarning()method. This keeps the UI clean since the default language often matches the book's language anyway.Problem Solved
Files Changed
src/plugins/translate/plugin.translate.js_toggleTranslation()method to add language validation_statusWarning()method to remove redundant messageTesting
To test this fix:
Type of Change