From 6e93aae93deeeaf312f036ce7b27dd1824c0a696 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Tue, 18 Aug 2026 15:01:23 +0700 Subject: [PATCH] feat(linux): use display language for keyboard search Look up the current display language and pass it into the keyboard search on keyman.com. Fallback to 'en'. Test-bot: skip Fixes: #15512 --- .../keyman_config/downloadkeyboard.py | 9 +++++- .../keyman_config/keyman_locales.py | 30 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 linux/keyman-config/keyman_config/keyman_locales.py diff --git a/linux/keyman-config/keyman_config/downloadkeyboard.py b/linux/keyman-config/keyman_config/downloadkeyboard.py index 7eac44b5ecb..9d52506fc0a 100755 --- a/linux/keyman-config/keyman_config/downloadkeyboard.py +++ b/linux/keyman-config/keyman_config/downloadkeyboard.py @@ -3,6 +3,7 @@ import logging import os import urllib.parse +from keyman_config.keyman_locales import find_locales import gi @@ -30,7 +31,7 @@ def __init__(self, parent=None): self.webview = WebKit2.WebView() self.webview.connect("decide-policy", self._keyman_policy) self.webview.connect("load-changed", self._update_back_button) - url = KeymanComUrl + "/go/linux/" + __releaseversion__ + "/download-keyboards" + url = KeymanComUrl + "/go/linux/" + __releaseversion__ + "/download-keyboards" + "?lang=" + self._get_current_locale() self.webview.load_uri(url) s.add(self.webview) @@ -56,6 +57,12 @@ def __init__(self, parent=None): self.resize(800, 450) self.show_all() + def _get_current_locale(self): + loc = find_locales()[0] + if loc == "C": + loc = "en" + return loc.replace('_','-') + def _update_back_button(self, webview, load_event): self.back_button.set_sensitive(webview.can_go_back()) diff --git a/linux/keyman-config/keyman_config/keyman_locales.py b/linux/keyman-config/keyman_config/keyman_locales.py new file mode 100644 index 00000000000..212d15077ac --- /dev/null +++ b/linux/keyman-config/keyman_config/keyman_locales.py @@ -0,0 +1,30 @@ +#!/usr/bin/python3 +# +# Keyman is copyright (C) SIL Global. MIT License. +# +# Created by Marc Durdin on 2026-08-18 +# +# Find the current display locale ID, using the same method as +# gettext.find() +# + +import os + +# +# @returns array of language identifiers in POSIX style, i.e. 'en_US', not 'en-US'. +# +# The returned array always includes the value 'C' for the default static locale, +# which should be replaced with 'en' when passed to other processes +# +def find_locales(): + # Approach comes from gettext.find() + languages = [] + for envvar in ('LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG'): + val = os.environ.get(envvar) + if val: + languages = val.split(':') + break + if 'C' not in languages: + languages.append('C') + + return languages