From 20a4916ff605e8f97e437457ea3b8dce510cfce0 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sun, 3 May 2026 16:50:41 +0200 Subject: Fix wrong locale selection for English (#1263) The "en" locale, which was meant to be the default for English locales that are not in the list, was used instead of exact locales like "en_US". The "en" locale was also used as the default locale for languages that are not in the list at all. The "en_GB" locale is used for this instead.--- gen_method_xml.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'gen_method_xml.py') diff --git a/gen_method_xml.py b/gen_method_xml.py index b5479bd..44dffb9 100644 --- a/gen_method_xml.py +++ b/gen_method_xml.py @@ -5,7 +5,7 @@ import itertools as it def loc(loc_name, script, default_layout, **kwargs): return { "name": loc_name, "script": script, - "default_layout": default_layout, **kwargs } + "default_layout": default_layout, **kwargs } # The locales are defined here. To add support for a language, add it to the # following block: @@ -24,6 +24,7 @@ LOCALES = [ loc("de_BE", "latin", "latn_azerty_be", extra_keys="accent_grave:è@f|accent_aigu:á:é:í:ó:ú:ý:j́@d|accent_circonflexe:ê@f|accent_cedille:ç@c|accent_trema@u|€"), loc("de_DE", "latin", "latn_qwertz_de", extra_keys="accent_trema:ä:ö:ü@u|ß|€"), loc("el", "latin", "grek_qwerty", extra_keys="£@l|€"), + loc("en", "latin", "latn_qwerty_us", dictionary="en_GB"), loc("en_AU", "latin", "latn_qwerty_us"), loc("en_CA", "latin", "latn_qwerty_us"), loc("en_GB", "latin", "latn_qwerty_gb", extra_keys="£@l"), @@ -79,8 +80,8 @@ LOCALES = [ loc("yo_NG", "latin", "latn_qwerty_us", extra_keys="₦|ẹ|ọ|ṣ") ] -# The locale that is at the beginning of the list -DEFAULT_LOCALE = loc("en", "latin", "latn_qwerty_us", tag="en", dictionary="en_GB") +# The locale that is at the beginning of the list. +DEFAULT_LOCALE = "en_GB" def parse_dictionaries(): tree = ET.parse("res/values/dictionaries.xml") @@ -113,8 +114,8 @@ def compute_attrs(): for loc in LOCALES: locales_grouped.setdefault(lang(loc), []).append(loc) def tag(loc): - if "tag" in loc: return loc["tag"] l = lang(loc) + if loc["name"] == l: return l # Locales like "en" if loc["name"] == f"{l}_{l.upper()}": return l # Locales like "fr_FR" # Return a short tag when it's not shared between several locales return l if len(locales_grouped[l]) == 1 else loc["name"] @@ -124,11 +125,23 @@ def compute_attrs(): if l in available_dictionaries: return l return None def add_attrs(loc): - return dict(tag=tag(loc), dictionary=dictionary(loc), **loc) + loc = dict(**loc) + loc["tag"] = tag(loc) + loc["dictionary"] = dictionary(loc) + return loc return map(add_attrs, LOCALES) +def sort_locales(locales): + # The default locale for a language (eg. "en") might shadow the exact + # locale (eg. "en_US"). Makes sure the default locale sorts after the exact + # ones. + def key(l): + s = l["name"].split("_") + return (l["name"] != DEFAULT_LOCALE), s[0], (len(s) == 1), s[1:] + return sorted(locales, key=key) + def gen(): - locales = compute_attrs() + locales = sort_locales(compute_attrs()) root = ET.Element("input-method", attrib={ "xmlns:android": "http://schemas.android.com/apk/res/android", "android:settingsActivity": "juloo.keyboard2.SettingsActivity", @@ -139,8 +152,7 @@ def gen(): Update this file with 'gradle test'. """)) - subtype_elem(root, DEFAULT_LOCALE) - for loc in sorted(locales, key=lambda loc: loc["name"]): + for loc in locales: subtype_elem(root, loc) ET.indent(root) print(ET.tostring(root, encoding="utf-8", xml_declaration=True).decode("UTF-8")) -- cgit v1.2.3 From 9189921719ac903bd645516f187c9b9aced20f68 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sun, 3 May 2026 19:19:51 +0200 Subject: Add languages for which a dictionary is available (#1267) * gen_method_xml.py: Warn for unused dictionaries Helps catch missing locales. * Add languages for which a dictionary is available Make dictionaries are available to more languages. Extra keys are added for as many languages as possible but no layout is added. Some languages are still not added, mainly because they use a script that the keyboard doesn't support yet: pa, gu, or, te, mai, sat, km, iw, zgh, sd, ml, sa--- gen_method_xml.py | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'gen_method_xml.py') diff --git a/gen_method_xml.py b/gen_method_xml.py index 44dffb9..135a3ca 100644 --- a/gen_method_xml.py +++ b/gen_method_xml.py @@ -1,8 +1,12 @@ import xml.etree.ElementTree as ET import itertools as it +import sys # This script generates res/xml/method.xml. +def warn(msg): + print("Warning: " + msg, file=sys.stderr) + def loc(loc_name, script, default_layout, **kwargs): return { "name": loc_name, "script": script, "default_layout": default_layout, **kwargs } @@ -13,15 +17,18 @@ def loc(loc_name, script, default_layout, **kwargs): LOCALES = [ loc("ar", "arabic", "arab_pc_hindu"), loc("ar_TN", "arabic", "arab_pc"), - loc("ay_AM", "armenian", "armenian_ph_am"), + loc("as", "beng", "beng_assamese"), loc("az_AZ", "latin", "latn_qwerty_az", extra_keys="accent_trema:ü:ö@w|accent_cedille:ç:ş@s|ğ@g|ı@k|ə@l"), loc("be_BY", "cyrillic", "cyrl_jcuken_ru", extra_keys="ґ|є|і|ї|ў"), loc("bg_BG", "cyrillic", "cyrl_ueishsht", extra_keys="€"), loc("bn_BD", "latin", "latn_qwerty_us", extra_keys="৳"), + loc("bs", "latin", "latn_qwerty_us", extra_keys="đ|ž|lj|nj|ć|č|dž|š"), + loc("ca", "latin", "latn_qwerty_us", extra_keys="accent_grave:à:ò:è|accent_cedille:ç@c|accent_aigu:é:í:ú:ó|accent_trema:ï:ü|ŀl|€"), loc("cs_CZ", "latin", "latn_qwertz_cz", extra_keys="accent_aigu:á:é:í:ó:ú:ý@d|accent_ring:ů@s|accent_caron:č:ě:ň:ř:š:ž:ď:ť@f"), loc("cy_GB", "latin", "latn_qwerty_cy"), loc("da_DK", "latin", "latn_qwerty_da", extra_keys="€|æ|å|ø"), loc("de_BE", "latin", "latn_azerty_be", extra_keys="accent_grave:è@f|accent_aigu:á:é:í:ó:ú:ý:j́@d|accent_circonflexe:ê@f|accent_cedille:ç@c|accent_trema@u|€"), + loc("de_CH", "latin", "latn_qwertz_de", extra_keys="accent_trema:ä:ö:ü@u|ß"), loc("de_DE", "latin", "latn_qwertz_de", extra_keys="accent_trema:ä:ö:ü@u|ß|€"), loc("el", "latin", "grek_qwerty", extra_keys="£@l|€"), loc("en", "latin", "latn_qwerty_us", dictionary="en_GB"), @@ -33,6 +40,7 @@ LOCALES = [ loc("en_US", "latin", "latn_qwerty_us"), loc("es_ES", "latin", "latn_qwerty_es", extra_keys="accent_aigu:á:é:í:ó:ú@d|accent_tilde:ñ@n|accent_grave@f|accent_trema@u|€"), loc("et_EE", "latin", "latn_qwerty_et", extra_keys="accent_trema:ä:ö:ü@u|accent_tilde:õ@o|accent_caron:š:ž@s|€"), + loc("eu", "latin", "latn_qwerty_us", extra_keys="ñ|ç|ü|dd|ll|rr|ts|tt|tx|tz"), loc("fa_IR", "persian", "arab_pc_ir"), loc("fi", "latin", "latn_qwerty_fi", extra_keys="å|accent_ring|accent_aigu|accent_trema|ö|ä|€"), loc("fr_BE", "latin", "latn_azerty_be", extra_keys="accent_grave:à:è:ù@f|accent_aigu:é@d|accent_circonflexe:ê:û@f|accent_cedille:ç@c|accent_trema@u|€"), @@ -40,11 +48,14 @@ LOCALES = [ loc("fr_CH", "latin", "latn_qwertz_fr_ch", extra_keys="accent_grave:à:è:ù@f|accent_aigu:é@d|accent_circonflexe:â:ê:ô:û@o|accent_cedille:ç@c|accent_trema:ë:ï:ü:ÿ@u|€"), loc("fr_FR", "latin", "latn_azerty_fr", extra_keys="accent_grave:à:è:ù@d|accent_aigu:é@d|accent_circonflexe:â:ê:ô:û@o|accent_cedille:ç@c|accent_trema:ë:ï:ü@l|€"), loc("ga_IE", "latin", "latn_qwerty_ga", extra_keys="accent_aigu:á:é:í:ó:ú@k|accent_dot_above@l"), + loc("gl", "latin", "latn_qwerty_us"), loc("ha_NG", "latin", "latn_qwerty_us", extra_keys="₦|ɓ|ɗ|ƙ|’|ƴ|r̃"), loc("haw_US", "latin", "latn_qwerty_haw", extra_keys="ʻ@l|accent_macron:ā:ē:ī:ō:ū@m"), loc("he_IL", "hebrew", "default_layout=hebr_1_il,extra_keys=₪@r|€"), loc("hi_IN", "devanagari", "deva_inscript", extra_keys="₹"), + loc("hr", "latin", "latn_qwerty_us", extra_keys="č|ć|dž|đ|lj|nj|š|ž"), loc("hu_HU", "latin", "latn_qwertz_hu", extra_keys="accent_aigu:á:é:í:ó:ú@d|accent_trema:ö:ü@u|accent_ogonek@s|accent_double_aigu:ő:ű@k|€"), + loc("hy", "armenian", "armenian_ph_am"), loc("ig_NG", "latin", "latn_qwerty_us", extra_keys="₦|ṅ|ọ|ụ"), loc("is_IS", "latin", "latn_qwerty_is", extra_keys="ð|þ|æ|accent_trema:ö@o|accent_aigu:á:é:í:ó:ú:ý@d|accent_circonflexe|accent_ring|accent_grave"), loc("it_IT", "latin", "latn_qwerty_us", extra_keys="accent_grave:à:è:ì:ò:ù@f|accent_aigu:é:ó@d|accent_circonflexe:î@f|€|ə"), @@ -52,21 +63,25 @@ LOCALES = [ loc("kk_KZ", "latin", "cyrl_jcuken_kk"), loc("kn_IN", "kannada", "kann_kannada"), loc("ko_KR", "hangul", "hang_dubeolsik_kr"), + loc("lb", "latin", "latn_qwerty_us", extra_keys="é|ä|ë|accent_grave|accent_cedille@c|accent_aigu|accent_trema|€"), loc("lt_LT", "latin", "latn_qwerty_lt", extra_keys="accent_ogonek:ą:ę:į:ų@s|accent_caron:č:š:ž@f|accent_dot_above:ė@s|accent_macron:ū@o|€"), loc("lv_LV", "latin", "latn_qwerty_lv", extra_keys="accent_macron:ā:ē:ī:ū@o|accent_caron:č:š:ž@f|accent_ogonek:ķ:ļ:ņ@s|accent_cedille:ģ@c|€"), loc("mk", "cyrillic", "cyrl_lynyertdz_mk", extra_keys="ѕ|ѓ|ќ|ѝ|ѐ|љ|њ|џ|„|“|€"), loc("mn_MN", "cyrillic", "cyrl_fcuzhen_mn", extra_keys="ү|ө"), loc("mr_IN", "devanagari", "deva_inscript", extra_keys="₹"), loc("mt_MT", "latin", "latn_qwerty_mt", extra_keys="accent_grave:à:è:ì:ò:ù|accent_dot_above:ċ:ż:ġ|ħ"), + loc("nb", "latin", "latn_qwerty_us", extra_keys="€|æ@a|å@a|ø@o|accent_aigu:é:ó@d|accent_grave:è:ò:ù@f|accent_circonflexe:ê:ô@f"), loc("ne_NE", "devanagari", "deva_inscript", extra_keys="₹"), loc("nl_BE", "latin", "latn_azerty_be", extra_keys="accent_grave:è@f|accent_aigu:á:é:í:ó:ú:ý:j́@d|accent_circonflexe:ê@f|accent_cedille:ç@c|accent_trema@u|€"), loc("no_NO", "latin", "latn_qwerty_us", extra_keys="€|æ@a|å@a|ø@o|accent_aigu:é:ó@d|accent_grave:è:ò:ù@f|accent_circonflexe:ê:ô@f"), loc("pl_PL", "latin", "latn_qwerty_pl"), loc("pt_BR", "latin", "latn_qwerty_pt", extra_keys="accent_aigu:á:é:í:ó:ú@d|accent_cedille:ç@c|accent_circonflexe:â:ê:ô@f|accent_grave:à:ò@f|accent_tilde:ã:õ@n|€|ª|º"), + loc("pt_PT", "latin", "latn_qwerty_pt", extra_keys="accent_aigu:á:é:í:ó:ú@d|accent_cedille:ç@c|accent_circonflexe:â:ê:ô@f|accent_grave:à:ò@f|accent_tilde:ã:õ@n|€|ª|º"), loc("ro_RO", "latin", "latn_qwerty_ro", extra_keys="ă|â|î|ș|ț|€|$"), loc("ru_RU", "latin", "cyrl_jcuken_ru"), loc("si_LK", "sinhala", "sinhala_phonetic", extra_keys="₨"), loc("sk_SK", "latin", "latn_qwertz_sk", extra_keys="accent_caron:ě:ř:ž:š:č:ň:ď:ľ:ť@f|accent_ring:ů@s|accent_circonflexe:ô@f|accent_trema:ä:ü:ö@u|accent_aigu:á:é:í:ó:ú:ŕ:ś:ĺ:ý@d"), + loc("sl", "latin", "latn_qwerty_us", extra_keys="accent_caron:Č:Š:Ž|€"), loc("sq_AL", "latin", "latn_qwertz_sq"), loc("sr_", "latin", "cyrl_lynyertz_sr"), loc("sv_SE", "latin", "latn_qwerty_se", extra_keys="accent_aigu:á@d|accent_trema:ä:ö@o|accent_ring:å@s|€"), @@ -75,6 +90,7 @@ LOCALES = [ loc("tly_IR", "persian", "arab_hamvaj_tly"), loc("tr_TR", "latin", "latn_qwerty_tr", extra_keys="accent_cedille:ç:ş@c|accent_trema:ö:ü@u|accent_circonflexe:â:î:û@f|₺|ı|ğ"), loc("uk_UA", "cyrillic", "cyrl_jcuken_uk", extra_keys="ґ|є|і|ї|₴"), + loc("ur", "persian", "arab_pc_ir"), loc("uz_UZ", "latin", "latn_qwerty_uz", extra_keys="ʻ|ʼ"), loc("vi_VN", "latin", "latn_qwerty_vi"), loc("yo_NG", "latin", "latn_qwerty_us", extra_keys="₦|ẹ|ọ|ṣ") @@ -91,6 +107,13 @@ def parse_dictionaries(): # Available dictionares of the form "de" or "de_CH". available_dictionaries = parse_dictionaries() +# Warn when a dictionary is attached to no locale +def check_locales_for_dictionaries(locales): + used = { l["dictionary"] for l in locales if "dictionary" in l } + for d in available_dictionaries: + if d not in used: + warn("Dictionary '%s' is attached to no locale" % d) + def subtype_elem(root, loc): tag = loc["tag"].replace("_", "-") extra_keys = ",extra_keys=" + loc["extra_keys"] if "extra_keys" in loc else "" @@ -105,8 +128,7 @@ def subtype_elem(root, loc): "android:imeSubtypeExtraValue": extra_value }) -# Return locales in sorted order with the "tag" and "dictionary" attributes -# added. +# Return locales with the "tag" and "dictionary" attributes added. def compute_attrs(): locales_grouped = {} # Locales grouped by language tag def lang(loc): @@ -142,6 +164,7 @@ def sort_locales(locales): def gen(): locales = sort_locales(compute_attrs()) + check_locales_for_dictionaries(locales) root = ET.Element("input-method", attrib={ "xmlns:android": "http://schemas.android.com/apk/res/android", "android:settingsActivity": "juloo.keyboard2.SettingsActivity", -- cgit v1.2.3