Skip to content

Command line switch to specify language on startup (#10044) (taken over after abandoned #10089)#12958

Merged
michaelDCurran merged 17 commits intonvaccess:masterfrom
lukaszgo1:i10044-cmdLineLanguage
Nov 21, 2021
Merged

Command line switch to specify language on startup (#10044) (taken over after abandoned #10089)#12958
michaelDCurran merged 17 commits intonvaccess:masterfrom
lukaszgo1:i10044-cmdLineLanguage

Conversation

@lukaszgo1
Copy link
Copy Markdown
Contributor

@lukaszgo1 lukaszgo1 commented Oct 19, 2021

Many thanks for @JulienCochuyt for laying the foundation of this work!

Link to issue number:

Fixes #10044
Supersedes #10089

Summary of the issue:

It can sometimes be useful to specify NVDA's language from the CLI. One use case which has been mentioned in #10044 is when language has been accidentally changed to a foreign one. This can also be useful for developers (it would certainly be a welcome addition for me when working on #12250 and #12753).

Description of how this pull request fixes the issue:

Add a new --lang command line parameter.
It accepts either "Windows" or the usual "en" / "de_CH" codes, with a little tolerance regarding to case and dashes.
As discussed during the review in #10089 the parameter is treated as a temporary override (i.e. it does not affect configuration at all and is effective only until NVDA is restarted).
As a bonus this PR adds unit tests for languageHandler.normalizeLanguage and languageHandler.getAvailableLanguages (tests for the former were necessary to confirm it provides us with normalization we need, and since I had to split the latter one into two functions added tests made it possible to confirm that current behavior has not changed).

Testing strategy:

  • Started NVDA without languate specified from the CLI - ensured that language can be changed.
  • Started NVDA with valid language code from the CLI - ensured that specified language has indeed been applied, that settings dialog shows "Command line: lang_code" as the selected language, that the language is set to the one specified from the configuration after restart and that language can still be changed from the settings dialog.
  • Started NVDA with invalid language - made sure that error dialog is shown and that the help message contains all supported language codes.

Known issues with pull request:

  • Resetting NVDA configuration does not change language properly (this is not new for this PR).
  • In Command line switch to specify language on startup (#10044) #10089 @LeonarddeR suggested to use globalVars.appArgs.language to store the current language the same way we do for config path regardless if it has been provided from the command line or not. While I like this idea myself it causes installer failure, and while I'd like to look into this further this should be done as a follow up.

Change log entries:

New features

  • The new --lang command line parameter allows to override the configured NVDA language.

Code Review Checklist:

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

@lukaszgo1
Copy link
Copy Markdown
Contributor Author

@feerrenrut @LeonarddeR Since you've both reviewed #10089 you may be interested in reviewing this PR. Also @CyrilleB79 your testing and/or review would be welcome as you've expressed interest in such CLI option in the past.

@AppVeyorBot
Copy link
Copy Markdown

See test results for failed build of commit 9a474befd0

@lukaszgo1 lukaszgo1 marked this pull request as draft October 19, 2021 13:08
@AppVeyorBot
Copy link
Copy Markdown

See test results for failed build of commit cd0aeb9558

@AppVeyorBot
Copy link
Copy Markdown

@AppVeyorBot
Copy link
Copy Markdown

@AppVeyorBot
Copy link
Copy Markdown

@AppVeyorBot
Copy link
Copy Markdown

@AppVeyorBot
Copy link
Copy Markdown

@AppVeyorBot
Copy link
Copy Markdown

@lukaszgo1 lukaszgo1 force-pushed the i10044-cmdLineLanguage branch from 904ce6b to 07596fa Compare October 19, 2021 19:06
@lukaszgo1 lukaszgo1 marked this pull request as ready for review October 19, 2021 19:28

def isLanguageForced() -> bool:
"""Returns `True` if language is provided from the command line - `False` otherwise."""
return any(filter(lambda elem: elem.startswith("--lang="), sys.argv))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This returns false if I start NVDA using the syntax:

runnvda --lang fr

I.e. without the =, which is also valid argparse syntax.
I would suggest that bool(globalVars.appArgs.language) is a better check.

@CyrilleB79
Copy link
Copy Markdown
Contributor

I have not tested yet; I hope to do it soon.

But I think that --lang=Windows should be kept because it is not in the list. And if I am not mistaken, it's not the same thing to provide --lang=en and --lang=Windows even if your Windows is in English.

@michaelDCurran
Copy link
Copy Markdown
Member

michaelDCurran commented Oct 20, 2021 via email

@lukaszgo1
Copy link
Copy Markdown
Contributor Author

This returns false if I start NVDA using the syntax: runnvda --lang fr I.e. without the =, which is also valid argparse syntax.

Thanks - I was not aware argParse` recognizes this form.

I would suggest that bool(globalVars.appArgs.language) is a better check.

It would indeed be a better check - however I was using the same comparison in core.restart to remove language from the lists of arguments so that it is not preserved after NVDA is restarted. Removing all arguments starting with --lang would work only partially (in case of --lang fr we would end up with fr in globalVars.appArgsExtra after restart). For now it is not much of a problem but as soon as #12795 gets implemented NVDA would show a warning after restart which is not what we want. The last commit covers both of these cases properly - hopefully that are all forms argParse recognizes.

@lukaszgo1
Copy link
Copy Markdown
Contributor Author

@michaelDCurran Did you intent to merge this - or is this awaiting @Qchristensen 's approval to the user guide changes?

@michaelDCurran
Copy link
Copy Markdown
Member

michaelDCurran commented Oct 25, 2021 via email

@CyrilleB79
Copy link
Copy Markdown
Contributor

Hi

I have tested this PR's snapshot (portable version created from nvda_snapshot_pr12958-24041,00e11f18.exe).
I am globally happy with the new feature as it is implemented and hope to have it soon in NVDA. Thanks @lukaszgo1 for having taken over this development and thanks @JulienCochuyt for the initial work.

I have still two points that I would like to discuss:

  1. In the language combo-box, we are used to have the default (Windows user) item at a fixed position. May we add the "Command line" item in second or last position. Indeed, I think that there is no use case to re-select the "command line" item.
  2. I am a bit concerned by the fact that when we restart, the "--lang" parameter is dropped from the command line. I understand that it is expected by a user who uses this command line parameter to start NVDA in a known language, open the general parameters and reset his UI language to the desirable one. But in the other cases, i.e. if you restart with NVDA+Q rather than from general parameter window, it's a bit surprising to have the --lang parameter dropped. What about adding a comment in the restart window as it is done when NVDA is running with the --disable-addons flag? A suggestion for the text to add in the restart dialog could be the following:

    NVDA's interface language is now forced from the command line. On the next restart, the language defined in NVDA's saved configuration will be used instead.

Should you disagree with one or both of these two points, I support merging this PR anyway.

@lukaszgo1
Copy link
Copy Markdown
Contributor Author

I have tested this PR's snapshot (portable version created from nvda_snapshot_pr12958-24041,00e11f18.exe). I am globally happy with the new feature as it is implemented and hope to have it soon in NVDA. Thanks @lukaszgo1 for having taken over this development and thanks @JulienCochuyt for the initial work.

You're welcome!

I have still two points that I would like to discuss:

Thanks for these suggestions.

1. In the language combo-box, we are used to have the default (Windows user) item at a fixed position. May we add the "Command line" item in second or last position. Indeed, I think that there is no use case to re-select the "command line" item.

This makes sense - in the last commit I've moved the language from the CLI to the last position.

2. I am a bit concerned by the fact that when we restart, the "--lang" parameter is dropped from the command line. I understand that it is expected by a user who uses this command line parameter to start NVDA in a known language, open the general parameters and reset his UI language to the desirable one. But in the other cases, i.e. if you restart with NVDA+Q rather than from general parameter window, it's a bit surprising to have the --lang parameter dropped. What about adding a comment in the restart window as it is done when NVDA is running with the --disable-addons flag? A suggestion for the text to add in the restart dialog could be the following:
   > NVDA's interface language is now forced from the command line. On the next restart, the language defined in NVDA's saved configuration will be used instead.

Implemented in the latest commit.

@AppVeyorBot
Copy link
Copy Markdown

See test results for failed build of commit 0116139e02

@lukaszgo1
Copy link
Copy Markdown
Contributor Author

@Qchristensen Would it be possible for you to review the user guide change? I'd like to have this merged sooner than later since as mentioned in the known issues of this PR there is a follow up work I'd like to do, but since it would not be backwards compatible it has to be done during development cycle for a .1 release. Also @CyrilleB79 are you happy with the latest changes?

@CyrilleB79
Copy link
Copy Markdown
Contributor

Hi Lukasz

I have not yet had the opportunity to test the last build. But from the description you have made of the lasts commits, I am fully happy with it. Many thanks!

@CyrilleB79
Copy link
Copy Markdown
Contributor

And I have now been able to download and test the snapshot containing your last modifications. All is fine for me. Thanks again!

Hope to have @Qchristensen's approval soon to see this PR merged.

Copy link
Copy Markdown
Member

@Qchristensen Qchristensen left a comment

Choose a reason for hiding this comment

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

User Guide text is fine, but I'd like a small change to the changes.t2t as proposed. In any case, great work on a useful feature!

@michaelDCurran
Copy link
Copy Markdown
Member

michaelDCurran commented Nov 18, 2021 via email

@michaelDCurran michaelDCurran merged commit a77aff3 into nvaccess:master Nov 21, 2021
@nvaccessAuto nvaccessAuto added this to the 2022.1 milestone Nov 21, 2021
@lukaszgo1 lukaszgo1 deleted the i10044-cmdLineLanguage branch November 22, 2021 10:00
seanbudd added a commit that referenced this pull request Nov 23, 2021
… provided from the command line or not. (#13082)

Follow up of #10089 and #12958

Summary of the issue:
PR #12958 introduced additional command line parameter which allows to set NVDA's language. The currently set language is stored in globalVars.appArgs.language however when it is not overridden from the CLI this variable is set to None. TO improve consistency with globalVars.appArgs.configPath it makes sense to store current NVDA's language in globalVars regardless of where it comes from.

Description of how this pull request fixes the issue:
Current NVDA language is now stored in globalVars.appArgs.language - it still can be accessed via languageHandler.getLanguage which is a recommended way to get its value for add-ons developers. To make this work for nvda_slave it has been necessary to provide a 'fake' implementation of globalVars.appArgs which is used in cases where command line arguments are not available or not yet parsed. This also provides type hints for values of appArgs so I'd say it is beneficial regardless.

* Use `languageHandler.getLanguage` when querying current NVDA's language rather than accessing `curLang` directly.
* Store current NVDA's language in `globalVars`
* Set `globalVarrs.appArgs` to a fake implementation by default.
* update changes

Co-authored-by: buddsean <sean@nvaccess.org>
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.

Command line switch to specify language on startup

7 participants