Repository: nvaccess/nvda

Issue:
Error when opening NVDA general settings

### Steps to reproduce:
* Launch NVDA with the following command line:
  `nvda --lang=windows`
* Press NVDA+ctrl+G to open the General settings 
### Actual behavior:
* The General settings window does not open
* Error sound is heard
### Expected behavior:
General settings panel opens without error
### NVDA logs, crash dumps and other attachments:
```
ERROR - unhandled exception (00:08:25.608) - MainThread (38744):
Traceback (most recent call last):
  File "wx\core.pyc", line 3407, in <lambda>
  File "gui\__init__.pyc", line 230, in onGeneralSettingsCommand
  File "gui\blockAction.pyc", line 60, in funcWrapper
  File "gui\__init__.pyc", line 166, in _popupSettingsDialog
  File "gui\settingsDialogs.pyc", line 464, in __init__
  File "gui\settingsDialogs.pyc", line 194, in __init__
  File "gui\settingsDialogs.pyc", line 4131, in makeSettings
  File "gui\settingsDialogs.pyc", line 533, in makeSettings
  File "gui\settingsDialogs.pyc", line 642, in _doCategoryChange
  File "gui\settingsDialogs.pyc", line 570, in _getCategoryPanel
  File "gui\settingsDialogs.pyc", line 328, in __init__
  File "gui\settingsDialogs.pyc", line 338, in _buildGui
  File "gui\settingsDialogs.pyc", line 727, in makeSettings
IndexError: list index out of range
```

### Additional notes
In the console:
```
>>> import globalVars
>>> globalVars.appArgs.language
'fr_FR'

```

So Windows indicates it uses fr_FR, but NVDA's translation corresponding language is only 'fr', i.e. no country code.

### System configuration
#### NVDA installed/portable/running from source:
Installed
#### NVDA version:
2022.4beta3
#### Windows version:
Windows 10 2004 (x64) build 19041.388
#### Name and version of other software in use when reproducing the issue:
N/A
#### Other information about your system:
N/A
### Other questions
#### Does the issue still occur after restarting your computer?
Yes
#### Have you tried any other versions of NVDA? If so, please report their behaviors.
2022.1; same issue
#### If NVDA add-ons are disabled, is your problem still occurring?
Yes
#### Does the issue still occur after you run the COM Registration Fixing Tool in NVDA's tools menu?
Not tested, but unrelated.



Discussion:

Resolving patch:
diff --git a/source/gui/settingsDialogs.py b/source/gui/settingsDialogs.py
--- a/source/gui/settingsDialogs.py
+++ b/source/gui/settingsDialogs.py
@@ -729,9 +729,16 @@ def makeSettings(self, settingsSizer):
 		self.languageNames = languageHandler.getAvailableLanguages(presentational=True)
 		languageChoices = [x[1] for x in self.languageNames]
 		if languageHandler.isLanguageForced():
-			cmdLangDescription = [
-				ld[1] for ld in self.languageNames if ld[0] == globalVars.appArgs.language
-			][0]
+			try:
+				cmdLangDescription = next(
+					ld for code, ld in self.languageNames if code == globalVars.appArgs.language
+				)
+			except StopIteration:
+				# In case --lang=Windows is passed to the command line, globalVars.appArgs.language is the current
+				# Windows language,, which may not be in the list of NVDA supported languages, e.g. Windows language may
+				# be 'fr_FR' but NVDA only supports 'fr'.
+				# In this situation, only use language code as a description.
+				cmdLangDescription = globalVars.appArgs.language
 			languageChoices.append(
 				# Translators: Shown for a language which has been provided from the command line
 				# 'langDesc' would be replaced with description of the given locale.


Test patch: