Skip to content

Commit

Permalink
Don't prepend random language to keyboard layout names
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
AdamWill committed Nov 21, 2023
1 parent c9e9f96 commit 2870794
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions pyanaconda/ui/gui/xkl_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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()
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 2870794

Please sign in to comment.