From 2870794405ee78222846331f08eea2d1e3fd04d3 Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Mon, 20 Nov 2023 16:48:35 -0800 Subject: [PATCH] Don't prepend random language to keyboard layout names As reported in https://bugzilla.redhat.com/show_bug.cgi?id=2250388 we often prepend an apparently-random language to the keyboard layout+variant description we get from evdev, with sometimes bizarre results. This happens when a layout+variant is associated with more than one language: we effectively pick just one of those languages at random to "care about", and if the evdev description for the layout+variant doesn't start with the name of that language, we prepend it. This gives bizarre results like the one reported in the bug - "French (English (intl., with AltGr dead keys))". To avoid this, let's just keep track of *all* the languages a layout+variant is associated with, and if there's more than one, we'll not try to do anything clever, we'll just use the evdev description. We'll only ever prepend a language or country name if a layout+variant is associated with only one language, or no languages and at least one country. Resolves: rhbz#2250388 Signed-off-by: Adam Williamson --- pyanaconda/ui/gui/xkl_wrapper.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/pyanaconda/ui/gui/xkl_wrapper.py b/pyanaconda/ui/gui/xkl_wrapper.py index f941fc21425..f156462ba05 100644 --- a/pyanaconda/ui/gui/xkl_wrapper.py +++ b/pyanaconda/ui/gui/xkl_wrapper.py @@ -53,7 +53,7 @@ iso_ = lambda x: gettext.translation("iso_639", fallback=True).gettext(x) # namedtuple for information about a keyboard layout (its language and description) -LayoutInfo = namedtuple("LayoutInfo", ["lang", "desc"]) +LayoutInfo = namedtuple("LayoutInfo", ["langs", "desc"]) class XklWrapperError(KeyboardConfigError): @@ -139,11 +139,11 @@ def _get_lang_variant(self, c_reg, item, subitem, lang): name = item.get_name() description = item.get_description() - #if this layout has already been added for some other language, - #do not add it again (would result in duplicates in our lists) - if name not in self._layout_infos: - with self._layout_infos_lock: - self._layout_infos[name] = LayoutInfo(lang, description) + with self._layout_infos_lock: + if name not in self._layout_infos: + self._layout_infos[name] = LayoutInfo([lang], description) + else: + self._layout_infos[name].langs.append(lang) def _get_country_variant(self, c_reg, item, subitem, country): if subitem: @@ -153,10 +153,12 @@ def _get_country_variant(self, c_reg, item, subitem, country): name = item.get_name() description = item.get_description() - # if the layout was not added with any language, add it with a country + # if the layout was not added with any language, add it with + # the first country encountered (but do not append if it's + # already there, as we don't want to add countries to langs) if name not in self._layout_infos: with self._layout_infos_lock: - self._layout_infos[name] = LayoutInfo(country, description) + self._layout_infos[name] = LayoutInfo([country], description) def _get_language_variants(self, c_reg, item, user_data=None): lang_name, lang_desc = item.get_name(), item.get_description() @@ -243,14 +245,16 @@ def get_layout_variant_description(self, layout_variant, with_lang=True, xlated= """ layout_info = self._layout_infos[layout_variant] - + lang = "" # translate language and upcase its first letter, translate the # layout-variant description if xlated: - lang = iso_(layout_info.lang) + if len(layout_info.langs) == 1: + lang = iso_(layout_info.langs[0]) description = Xkb_(layout_info.desc) else: - lang = upcase_first_letter(layout_info.lang) + if len(layout_info.langs) == 1: + lang = upcase_first_letter(layout_info.langs[0]) description = layout_info.desc if with_lang and lang and not description.startswith(lang):