Skip to content

Commit

Permalink
Merge pull request #6175 from KKoukiou/common-keyboards-api
Browse files Browse the repository at this point in the history
pyanaconda: localization: sort keyboard list in a sane manner
  • Loading branch information
KKoukiou authored Feb 17, 2025
2 parents 4a8bc61 + 5aa99aa commit 8a208f6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
13 changes: 12 additions & 1 deletion pyanaconda/modules/localization/localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
get_english_name,
get_language_id,
get_language_locales,
get_locale_keyboards,
get_native_name,
)
from pyanaconda.modules.common.base import KickstartService
Expand Down Expand Up @@ -205,8 +206,18 @@ def get_locale_keyboard_layouts(self, lang):

english_name = get_english_name(language_id)

# rxkb_context.layouts lists all XKB layouts, including variants and less common options,
# while langtable.list_keyboards filters for the most relevant layouts per language.
keyboards = self._layout_infos.items()
langtable_keyboards = get_locale_keyboards(language_id)

# Sort the available keyboards by name alphabetically and but put the most common ones
# (langtable) on top
keyboards = sorted(keyboards, key=lambda x: x[0])
keyboards = sorted(keyboards, key=lambda x: langtable_keyboards.index(x[0]) if x[0] in langtable_keyboards else 999)

layouts = []
for name, info in self._layout_infos.items():
for name, info in keyboards:
if any(english_name in langs for langs in info.langs):
if name:
layout = KeyboardLayout()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,13 @@ def test_keyboard_layouts_for_language(self):
layouts_expectation = [
("cz", "Czech"),
("cz (bksl)", "Czech (extra backslash)"),
("cz (dvorak-ucw)", "Czech (US, Dvorak, UCW support)"),
("cz (qwerty)", "Czech (QWERTY)"),
("cz (qwerty-mac)", "Czech (QWERTY, Macintosh)"),
("cz (qwerty_bksl)", "Czech (QWERTY, extra backslash)"),
("cz (ucw)", "Czech (UCW, only accented letters)"),
("cz (winkeys)", "Czech (QWERTZ, Windows)"),
("cz (winkeys-qwerty)", "Czech (QWERTY, Windows)"),
("cz (qwerty-mac)", "Czech (QWERTY, Macintosh)"),
("cz (ucw)", "Czech (UCW, only accented letters)"),
("cz (dvorak-ucw)", "Czech (US, Dvorak, UCW support)"),
]

expected_layouts = []
Expand Down Expand Up @@ -265,9 +265,9 @@ def test_keyboard_layouts_for_language(self):

layouts_expectation = [
("gr", "Greek"),
("gr (simple)", "Greek (simple)"),
("gr (nodeadkeys)", "Greek (no dead keys)"),
("gr (polytonic)", "Greek (polytonic)"),
("gr (simple)", "Greek (simple)"),
]

expected_layouts = []
Expand All @@ -280,6 +280,15 @@ def test_keyboard_layouts_for_language(self):

assert normalized_layouts == expected_layouts

# Test that for english the common layouts are correctly sorted
layouts = get_keyboard_layouts("en_US.UTF-8")

normalized_layouts = KeyboardLayout.from_structure_list(layouts)

assert normalized_layouts[0].layout_id == "us"
assert normalized_layouts[1].layout_id == "gb"
assert normalized_layouts[2].layout_id == "au"

def test_common_locales(self):
common_locales = self.localization_interface.GetCommonLocales()

Expand Down

0 comments on commit 8a208f6

Please sign in to comment.