From c734dc5b20c02d279cdd941d3056ffe36172918b Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Mon, 20 Nov 2023 17:22:53 -0800 Subject: [PATCH] Keyboard layout descriptions: more liberal language name check Checking whether the layout+variant description from evdev starts with the exact ISO-ified name of the language or country with which it's associated is rather too strict. See things like the official ISO name of Iran - "Iran, Islamic Republic of" - or the ISO name of modern Greek - "Greek, Modern (1453-)" - or Berber - "Berber languages". These cases mean our layout list winds up with entries like "Greek, Modern (1453-) (Greek)" in it. Avoid that with a more liberal check. Once we have our 'lang' string, take the first word of it, strip any trailing commas and semi-colons, then check if that word is in the evdev description, and if so, don't prepend the lang string. Also ignore case - I noticed that in French all translated language names are not title-cased, so we wind up with entries like "anglais (Anglais (US))". Signed-off-by: Adam Williamson --- pyanaconda/ui/gui/xkl_wrapper.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pyanaconda/ui/gui/xkl_wrapper.py b/pyanaconda/ui/gui/xkl_wrapper.py index f156462ba05..0c1d11421d7 100644 --- a/pyanaconda/ui/gui/xkl_wrapper.py +++ b/pyanaconda/ui/gui/xkl_wrapper.py @@ -257,10 +257,18 @@ def get_layout_variant_description(self, layout_variant, with_lang=True, xlated= lang = upcase_first_letter(layout_info.langs[0]) description = layout_info.desc - if with_lang and lang and not description.startswith(lang): - return "%s (%s)" % (lang, description) - else: - return description + if with_lang and lang: + # ISO language/country names can be things like + # "Occitan (post 1500); Provencal", or + # "Iran, Islamic Republic of", or "Greek, Modern (1453-)" + # or "Catalan; Valencian": let's handle that gracefully + # let's also ignore case, e.g. in French all translated + # language names are lower-case for some reason + checklang = lang.split()[0].strip(",;").lower() + if checklang not in description.lower(): + return "%s (%s)" % (lang, description) + + return description def get_switch_opt_description(self, switch_opt): """