FIX lang selection resetting to en_US for some langs (#3744)

* FIX lang selection resetting to en_US for some langs

Fixes https://forums.ankiweb.net/t/anki-25-01-beta/54490/17?u=anon_0000.

# Issue
Set a hand full of certain languages in the preferences screen and see that the translations have been applied after reboot. The language selection in preferences wrongly shows en_US though, not the current active language. If you wanted to switch to `en_US` in this case, then you'd have to first switch to a working language (like de_DE) and then switch to en_US.

# Solution
`anki/qt/aqt/preferences.py` has the functions `setup_language()` and `current_lang_index()`. I noticed that it defaults to en_US, if the language is not in `compatMap` and it couldn’t return the index of the current language. No idea if this code is faulty but I headed over to `anki/pylib/anki/lang.py` afterwards.

Here, in `compatMap`, I added e.g. `"la": "la_LA"`. I knew the code since I could get it with `print("––– lang is ", lang)` in `preferences.py` (`current_lang_index()` retrieves `la` for latin).

After adding those code changes from my PR, the problem for those selected languages had gone away.

No idea if that's best practices though or if something else should be fixed instead.

* UPDATE CONTRIBUTORS adding myself to the list
This commit is contained in:
GithubAnon0000 2025-01-25 08:14:50 +00:00 committed by GitHub
parent df808727c8
commit e32292585b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 0 deletions

View file

@ -210,6 +210,7 @@ Omar Kohl <omarkohl@posteo.net>
David Elizalde <david.elizalde.r.a@gmail.com>
Yuki <https://github.com/YukiNagat0>
wackbyte <wackbyte@protonmail.com>
GithubAnon0000 <GithubAnon0000@users.noreply.github.com>
********************

View file

@ -80,6 +80,7 @@ langs = sorted(
compatMap = {
"af": "af_ZA",
"ar": "ar_SA",
"be": "be_BY",
"bg": "bg_BG",
"ca": "ca_ES",
"cs": "cs_CZ",
@ -101,13 +102,16 @@ compatMap = {
"hy": "hy_AM",
"it": "it_IT",
"ja": "ja_JP",
"jbo": "jbo_EN",
"ko": "ko_KR",
"la": "la_LA",
"mn": "mn_MN",
"ms": "ms_MY",
"nl": "nl_NL",
"nb": "nb_NL",
"no": "nb_NL",
"oc": "oc_FR",
"or": "or_OR",
"pl": "pl_PL",
"pt": "pt_PT",
"ro": "ro_RO",