nvda
cec20953 - Resolve Windows LCIDs via the Windows API instead of locale.windows_locale (#20589)

Commit
93 days ago
Resolve Windows LCIDs via the Windows API instead of locale.windows_locale (#20589) Summary of the issue: languageHandler.windowsLCIDToLocaleName consulted locale.windows_locale before asking Windows for a locale name. That table is documented as incomplete, has no remaining users inside CPython, and its contents change between Python patch releases: 3.13.14 rewrote it against MS-LCID revision 16.0, changing existing values and adding 1170: "ku_IQ". The new entry shadowed NVDA's mapping of LCID 1170 (Central Kurdish) to ckb, which lived in LCIDS_TO_TRANSLATED_LOCALES and was only consulted after locale.windows_locale. Consequently, test_NVDASupportedLanguages_LanguageIsSetCorrectly failed with 'ckb' != 'ku' on 3.13.14. Additionally, the SAPI 4 and SAPI 5 synthesizer drivers indexed locale.windows_locale directly when building their voice lists, so voices with a locale identifier absent from that table got no language at all, even when Windows knows the locale. Description of user facing changes: The SAPI 4 and SAPI 5 drivers now resolve voice languages through the Windows API, so the language of a voice can be reported for locale identifiers that locale.windows_locale did not cover. Some locale identifiers now resolve to a different (correct) locale name, such as zh_CN rather than zh_CHS, km_KH rather than kh_KH and en_JM rather than en_JA. Names for locales with a script subtag, such as sr_LATN_CS, are now returned in full where Windows reports one. Description of developer facing changes: languageHandler.windowsLCIDToLocaleName no longer consults locale.windows_locale. It now checks a small internal override mapping (_LCID_TO_LOCALE_NAME_OVERRIDES) and otherwise defers to winKernel.LCIDToLocaleName. languageHandler.LCIDS_TO_TRANSLATED_LOCALES is deprecated with no public replacement, using a module level __getattr__ via utils._deprecate. Accessing it logs a deprecation warning and returns the new override mapping, which is a superset of the previous public value (all three Central Kurdish LCIDs instead of only 1170). Description of development approach: The two mappings in languageHandler (_LCIDS_TO_TRANSLATED_LOCALES_OVERRIDES and LCIDS_TO_TRANSLATED_LOCALES) are merged into a single private _LCID_TO_LOCALE_NAME_OVERRIDES, which only contains identifiers where the language code NVDA uses differs from the one Windows reports: Central Kurdish keeps an override, as Windows reports all three of its LCIDs (0x0092, 0x0492, 0x7C92) as ku-Arab-IQ, while NVDA ships its translation under ckb. The Khmer override is dropped, since Windows already reports km-KH for LCID 0x0453; the old override only existed to correct the wrong kh_KH value in locale.windows_locale. windowsLCIDToLocaleName checks this mapping first and otherwise uses winKernel.LCIDToLocaleName, normalizing the result as before. The SAPI 4 and SAPI 5 drivers now call languageHandler.windowsLCIDToLocaleName instead of indexing locale.windows_locale directly, removing the KeyError handling; the function returns None for unknown identifiers. This removes the last uses of locale.windows_locale in NVDA.
Author
Parents
Loading