3434#: or because it is not a legal locale name (e.g. "zzzz").
3535LCID_NONE = 0 # 0 used instead of None for backwards compatibility.
3636
37- curLang = "en"
38-
3937
4038class LOCALE (enum .IntEnum ):
4139 # Represents NLS constants which can be used with `GetLocaleInfoEx` or `GetLocaleInfoW`
@@ -321,10 +319,9 @@ def setLanguage(lang: str) -> None:
321319 Sets the following using `lang` such as "en", "ru_RU", or "es-ES". Use "Windows" to use the system locale
322320 - the windows locale for the thread (fallback to system locale)
323321 - the translation service (fallback to English)
324- - languageHandler.curLang (match the translation service)
322+ - globalVars.appArgs.language (match the translation service)
325323 - the python locale for the thread (match the translation service, fallback to system default)
326324 '''
327- global curLang
328325 if lang == "Windows" :
329326 localeName = getWindowsLanguage ()
330327 else :
@@ -338,20 +335,20 @@ def setLanguage(lang: str) -> None:
338335
339336 try :
340337 trans = gettext .translation ("nvda" , localedir = "locale" , languages = [localeName ])
341- curLang = localeName
338+ globalVars . appArgs . language = localeName
342339 except IOError :
343340 try :
344341 log .debugWarning (f"couldn't set the translation service locale to { localeName } " )
345342 localeName = localeName .split ("_" )[0 ]
346343 trans = gettext .translation ("nvda" , localedir = "locale" , languages = [localeName ])
347- curLang = localeName
344+ globalVars . appArgs . language = localeName
348345 except IOError :
349346 log .debugWarning (f"couldn't set the translation service locale to { localeName } " )
350347 trans = gettext .translation ("nvda" , fallback = True )
351- curLang = "en"
348+ globalVars . appArgs . language = "en"
352349
353350 trans .install ()
354- setLocale (curLang )
351+ setLocale (getLanguage () )
355352 # Install our pgettext function.
356353 builtins .pgettext = makePgettext (trans )
357354
@@ -392,7 +389,8 @@ def _setPythonLocale(localeString: str) -> bool:
392389def setLocale (localeName : str ) -> None :
393390 '''
394391 Set python's locale using a `localeName` such as "en", "ru_RU", or "es-ES".
395- Will fallback on `curLang` if it cannot be set and finally fallback to the system locale.
392+ Will fallback on `globalVars.appArgs.language` if it cannot be set
393+ and finally fallback to the system locale.
396394 Passing NVDA locales straight to python `locale.setlocale` does now work since it tries to normalize the
397395 parameter using `locale.normalize` which results in locales unknown to Windows (Python issue 37945).
398396 For example executing: `locale.setlocale(locale.LC_ALL, "pl")`
@@ -426,18 +424,18 @@ def setLocale(localeName: str) -> None:
426424 return
427425 # Either Windows does not know the locale, or Python is unable to handle it.
428426 # reset to default locale
429- if originalLocaleName == curLang :
427+ if originalLocaleName == getLanguage () :
430428 # reset to system locale default if we can't set the current lang's locale
431429 locale .setlocale (locale .LC_ALL , "" )
432430 log .debugWarning (f"set python locale to system default" )
433431 else :
434- log .debugWarning (f"setting python locale to the current language { curLang } " )
432+ log .debugWarning (f"setting python locale to the current language { getLanguage () } " )
435433 # fallback and try to reset the locale to the current lang
436- setLocale (curLang )
434+ setLocale (getLanguage () )
437435
438436
439437def getLanguage () -> str :
440- return curLang
438+ return globalVars . appArgs . language
441439
442440
443441def normalizeLanguage (lang : str ) -> Optional [str ]:
0 commit comments