Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report the language switched to #17685

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft

Conversation

nvdaes
Copy link
Collaborator

@nvdaes nvdaes commented Feb 8, 2025

  • Add ability to report the current language when detecting languages is enabled
  • Added a command to report the language of the character at the caret

Link to issue number:

#17664

Summary of the issue:

Users may want to know the current language when the language detection is enabled.

Description of user facing changes

  • When switching to a non default language, NVDA should report it.
  • Added an unassigned command in the caret system category to know the language of the charácter positioned at the caret.

Description of development approach

In speech.speech.py, a lastReportedLanguage member has been added to the SpeechState dataclass.
In the speak function, the language description is inserted in the speechSequence when appropriate.
In speech.speech.py, a languageIsSupportedfunction has been added. It accept a language parameter to check if it's available in the current synthesizer.
In globalCommands.py, a script has been added to report the language of the carácter at caret.
This is an API break change since the speakfunction is changed.

Testing strategy:

Tested manually in webpages like addons.nvda-project.org, and navigating to nvda.fr, DuckDuckGo, etc, and in VS Code and other places of Windows.

Known issues with pull request:

This needs to be more tested to know if it Works appropriately. In say all, NVDA can report the language when a new paragraph starts.

Code Review Checklist:

  • Documentation:
    • Change log entry
    • User Documentation
    • Developer / Technical Documentation
    • Context sensitive help for GUI changes
  • Testing:
    • Unit tests
    • System (end to end) tests
    • Manual testing
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers
    • Localization in other languages / culture than English
  • API is compatible with existing add-ons.
  • Security precautions taken.

@coderabbitai summary

@nvdaes nvdaes changed the title Reportthe language switched to Report the language switched to Feb 8, 2025
text = info.text
repeats = scriptHandler.getLastScriptRepeatCount()
if repeats == 0:
ui.message(languageHandler.getLanguageDescription(curLanguage))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please handle the case where the language is not recognized. I.e. report something like f"Unknown language ({languageCode})" or just f"{languageCode}".

speechSequence.insert(1, languageHandler.getLanguageDescription(curLanguage))
SpeechState.lastReportedLanguage = curLanguage
if not languageIsSupported(curLanguage):
log.warn(f"{curLanguage} not supported in {getSynth().name}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that log.warn is usually not used in NVDA's code base. Any specific reason to use it?

We usually have log.warning (used even at info level), and log .debugWarning, used at the same log level.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a mistake from my side. My intention was to use log.debugWarning

if language is None:
return True
for lang in getSynth().availableLanguages:
if language == lang or language == languageHandler.normalizeLanguage(lang).split("_")[0]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this piece of code depend on the "Automatic dialect switching (when supported)" option?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better that this doesn't deppend on the automatic dialect switching option, since we can imagine a synthesizer with languages just in the form of dialects. Anyway I'm open to change my opinion.

nvdaes and others added 2 commits February 8, 2025 23:16
Co-authored-by: Cyrille Bougot <cyrille.bougot2@laposte.net>
@nvdaes
Copy link
Collaborator Author

nvdaes commented Feb 8, 2025

Seems that, when pressing c to go to the combo box in the old add-ons website, the preferences word is in English but, if it's not spoken, the lastReportedLanguage is set to English, and this causes that the language of the word English in the combo box is not reported. I don't know if this may be fixed with the pre_speech extension point in some way.

@CyrilleB79
Copy link
Collaborator

@nvdaes, regarding language translations I guess it would be interesting to list all the specific / corner cases. Then you will be able to determine if they should be handled separately or if they can be ignored.

For example I have the following questions:

  • zh_CN = Chinese (simplified) and zh_TW = Chinese (Traditional) would be both reported as "Chinese", I guess. Is it OK (cc @cary-rowen)
  • the language would be reported in the system's language; this would make a difference if you run NVDA in another language than "Windows". Maybe not a big problem, but it's worth informing of this limitation in the PR.
  • languageHandler.getLanguageDescription('sr'): on my system, it reports (in French): "Serbe (latin)". To be double checked if Serbian tagged webpages are tagged with "sr" or something else and if they are written in Cyrillic or in latin.

@nvdaes
Copy link
Collaborator Author

nvdaes commented Feb 10, 2025

@CyrilleB79 , should the corner cases be addressed in languageHandler.getLanguageDescription?
I'm concerned about the issue regarding pressing c on the add-ons website, since in this case English language may not be reported. So I'm blocked with this.

@CyrilleB79
Copy link
Collaborator

@CyrilleB79 , should the corner cases be addressed in languageHandler.getLanguageDescription?

Maybe not; just mentioning in case everyone is aware of it so to decide what to do (accept as is or fix).

@nvdaes
Copy link
Collaborator Author

nvdaes commented Feb 10, 2025

Let's way for comments on this about corner cases, to see how to document it, or if saying that the language description would be reported is enough.
Hope someone can provide ideas to fix the error when jumping to some parts of webpages using quick navigation characters like c to move to combo boxes.

@nvdaes
Copy link
Collaborator Author

nvdaes commented Feb 18, 2025

I think that the experience when using this feature with quick navigation or moving the focus with tab is not good, when the language description is reported, then for example the text of a heading and a link, and then the link state like "visited link". In this case "visited link" is pronnounced with a bad entonation, tested with eSpeak-NG. And also, listening the language description for each element, since "visited link" is pronnounced in the default language, is too much.
I think that this should be disabled for quick navigation, unless someone can provide better ideas.

@nvdaes
Copy link
Collaborator Author

nvdaes commented Feb 20, 2025

Now for me the user experience is acceptable, not perfect, since in say all NVDA can report the language for new paragraphs. See [In-Process 7th February 2025](https://www.nvaccess.org/post/in-process-7th-february-2025/

Copy control+shift+cClose).
If we move the caret to the ending dot of the paragraph with right arrow, and then we make NVDA to say all, this issue seems not to happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants