Command line switch to specify language on startup (#10044) (taken over after abandoned #10089)#12958
Conversation
…normalize language provided from the CLI
…if language from the CLI is in the list of supported locales.
…from the general settings
|
@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. |
See test results for failed build of commit 9a474befd0 |
See test results for failed build of commit cd0aeb9558 |
See test results for failed build of commit 85a7bd2bfa |
See test results for failed build of commit 3e706d4c65 |
See test results for failed build of commit 00d619d915 |
See test results for failed build of commit 65309f20d6 |
See test results for failed build of commit 8dde317afb |
See test results for failed build of commit 4d57eebc25 |
904ce6b to
07596fa
Compare
source/languageHandler.py
Outdated
|
|
||
| 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)) |
There was a problem hiding this comment.
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.
|
I have not tested yet; I hope to do it soon. But I think that |
|
in nvda.pyw, the given language argument is checked to see if it is in
the list produced by languageHandler.listNVDALocales.
This pr also seems to insert 'windows' into that list in the
listNVDALocales function, thus it is already an acceptable value.
|
Thanks - I was not aware argParse` recognizes this form.
It would indeed be a better check - however I was using the same comparison in |
|
@michaelDCurran Did you intent to merge this - or is this awaiting @Qchristensen 's approval to the user guide changes? |
|
Correct. Waiting on @Qchristensen.
|
|
Hi I have tested this PR's snapshot (portable version created from nvda_snapshot_pr12958-24041,00e11f18.exe). I have still two points that I would like to discuss:
Should you disagree with one or both of these two points, I support merging this PR anyway. |
You're welcome!
Thanks for these suggestions.
This makes sense - in the last commit I've moved the language from the CLI to the last position.
Implemented in the latest commit. |
See test results for failed build of commit 0116139e02 |
|
@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? |
|
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! |
|
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. |
Qchristensen
left a comment
There was a problem hiding this comment.
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!
|
Yes, I'll handle it from here.
|
… 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>
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
--langcommand 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.normalizeLanguageandlanguageHandler.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:
Known issues with pull request:
globalVars.appArgs.languageto 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
--langcommand line parameter allows to override the configured NVDA language.Code Review Checklist: