diff --git a/Makefile b/Makefile index 2653bb6..b86019a 100644 --- a/Makefile +++ b/Makefile @@ -31,10 +31,14 @@ sync_translations: check_layouts: python check_layout.py $(wildcard res/xml/*.xml) > check_layout.output -# Will modify the source tree. -runtest: rebuild_special_font sync_translations check_layouts +gen_layouts: + python gen_layouts.py -.PHONY: release debug installd clean rebuild_special_font check_layouts sync_translations runtest +# Will modify the source tree. +runtest: rebuild_special_font sync_translations check_layouts gen_layouts + +.PHONY: release debug installd clean rebuild_special_font check_layouts \ + sync_translations runtest gen_layouts $(shell mkdir -p _build) diff --git a/gen_layouts.py b/gen_layouts.py new file mode 100644 index 0000000..2b86883 --- /dev/null +++ b/gen_layouts.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python + +# Generates the list of layouts in res/values/layouts.xml from the layout files +# in res/xml. Every layouts must have a 'name' attribute to be listed. + +import itertools as it +import sys, os, glob +import xml.etree.ElementTree as XML + +# Layouts first in the list (these are the programming layouts). Other layouts +# are sorted alphabetically. +FIRST_LAYOUTS = [ "latn_qwerty_us", "latn_colemak", "latn_dvorak" ] + +# Read a layout from a file. Returns [None] if [fname] is not a layout. +def read_layout(fname): + root = XML.parse(fname).getroot() + if root.tag != "keyboard": + return None + return { "name": root.get("name") } + +# Yields the id (based on the file name) and the display name for every layouts +def read_layouts(files): + for layout_file in files: + layout_id, _ = os.path.splitext(os.path.basename(layout_file)) + layout = read_layout(layout_file) + if layout == None: + print("Not a layout file: %s" % layout_file) + elif layout["name"] == None: + print("Layout doesn't have a name: %s" % layout_id) + else: + yield (layout_id, layout["name"]) + +# Sort layouts alphabetically, except for layouts in FIRST_LAYOUTS, which are +# placed at the top. +# Returns a list. 'layouts' can be an iterator. +def sort_layouts(layouts): + layouts = dict(layouts) + head = [ (lid, layouts.pop(lid)) for lid in FIRST_LAYOUTS ] + return head + sorted(layouts.items()) + +# Write the XML arrays used in the preferences. +def generate_arrays(out, layouts): + def add_items(parent, strings): + for s in strings: + item = XML.Element("item") + item.text = s + parent.append(item) + none_item = [ ("none", "None") ] + custom_item = [ ("custom", "@string/pref_layout_e_custom") ] + lids, names = zip(*(none_item + layouts + custom_item)) # unzip + values = XML.Element("string-array", name="pref_layout_values") + add_items(values, lids) + entries = XML.Element("string-array", name="pref_layout_entries") + add_items(entries, names) + root = XML.Element("resources") + root.append(XML.Comment(text="DO NOT EDIT. This file is generated, see gen_layouts.py.")) + root.append(values) + root.append(entries) + XML.indent(root) + XML.ElementTree(element=root).write(out, encoding="unicode", xml_declaration=True) + +layouts = sort_layouts(read_layouts(glob.glob("res/xml/*.xml"))) +with open("res/values/layouts.xml", "w") as out: + generate_arrays(out, layouts) diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 713459d..14a536d 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -1,85 +1,5 @@ - - none - latn_qwerty_us - latn_colemak - latn_dvorak - arab_pc_ckb - arab_pc - arab_alt - arab_pc_ir - beng_national - beng_provat - cyrl_jcuken_ru - cyrl_jcuken_uk - cyrl_yaverti - deva_inscript - deva_alt - grek_qwerty - hang_dubeolsik_kr - hebr_1_il - hebr_2_il - latn_azerty_fr - latn_bone - latn_neo2 - latn_qwerty_hu - latn_qwerty_br - latn_qwerty_es - latn_qwerty_lv - latn_qwerty_no - latn_qwerty_pl - latn_qwerty_se - latn_qwerty_tr - latn_qwerty_vi - latn_qwerty_ro - latn_qwertz - latn_qwertz_cz - latn_qwertz_de - latn_qwertz_hu - latn_qwertz_sk - custom - - - None - QWERTY (US) - Colemak - Dvorak - Arabic (کوردی) - Arabic PC - Arabic Alt - Persian PC - বাংলা (জাতীয়) - বাংলা (প্রভাত) - ЙЦУКЕН (Русский) - ЙЦУКЕН (Українська) - ЯВЕРТЪ - देवनागरी (हिंदी)-1 - देवनागरी (हिंदी)-2 - QWERTY (Greek) - 두벌식 (Korean) - Hebrew 1 - Hebrew 2 - AZERTY (Français) - Bone - Neo 2 - QWERTY (Magyar) - QWERTY (Brasileiro) - QWERTY (Español) - QWERTY (Latvian) - QWERTY (Norwegian) - QWERTY (Polski) - QWERTY (Swedish) - QWERTY (Türkçe) - QWERTY (Vietnamese) - QWERTY (Română) - QWERTZ - QWERTZ (Czech) - QWERTZ (Deutsch) - QWERTZ (Magyar) - QWERTZ (Slovak) - @string/pref_layout_e_custom - @string/pref_accents_e_all_installed @string/pref_accents_e_selected diff --git a/res/values/layouts.xml b/res/values/layouts.xml new file mode 100644 index 0000000..6042437 --- /dev/null +++ b/res/values/layouts.xml @@ -0,0 +1,84 @@ + + + + + none + latn_qwerty_us + latn_colemak + latn_dvorak + arab_alt + arab_pc + arab_pc_ckb + arab_pc_ir + beng_national + beng_provat + cyrl_jcuken_ru + cyrl_jcuken_uk + cyrl_yaverti + deva_alt + deva_inscript + grek_qwerty + hang_dubeolsik_kr + hebr_1_il + hebr_2_il + latn_azerty_fr + latn_bone + latn_neo2 + latn_qwerty_br + latn_qwerty_es + latn_qwerty_hu + latn_qwerty_lv + latn_qwerty_no + latn_qwerty_pl + latn_qwerty_ro + latn_qwerty_se + latn_qwerty_tr + latn_qwerty_vi + latn_qwertz + latn_qwertz_cz + latn_qwertz_de + latn_qwertz_hu + latn_qwertz_sk + custom + + + None + QWERTY (US) + Colemak + Dvorak + Arabic Alt + Arabic PC + Arabic (کوردی) + Persian PC + বাংলা (জাতীয়) + বাংলা (প্রভাত) + ЙЦУКЕН (Русский) + ЙЦУКЕН (Українська) + ЯВЕРТЪ + देवनागरी (हिंदी)-2 + देवनागरी (हिंदी)-1 + QWERTY (Greek) + 두벌식 (Korean) + Hebrew 1 + Hebrew 2 + AZERTY (Français) + Bone + Neo 2 + QWERTY (Brasileiro) + QWERTY (Español) + QWERTY (Magyar) + QWERTY (Latvian) + QWERTY (Norwegian) + QWERTY (Polski) + QWERTY (Română) + QWERTY (Swedish) + QWERTY (Türkçe) + QWERTY (Vietnamese) + QWERTZ + QWERTZ (Czech) + QWERTZ (Deutsch) + QWERTZ (Magyar) + QWERTZ (Slovak) + @string/pref_layout_e_custom + + \ No newline at end of file diff --git a/res/xml/arab_alt.xml b/res/xml/arab_alt.xml index bc5f123..f594f92 100644 --- a/res/xml/arab_alt.xml +++ b/res/xml/arab_alt.xml @@ -1,5 +1,5 @@ - + diff --git a/res/xml/arab_pc.xml b/res/xml/arab_pc.xml index 8ab8650..9fb9dad 100644 --- a/res/xml/arab_pc.xml +++ b/res/xml/arab_pc.xml @@ -1,5 +1,5 @@ - + diff --git a/res/xml/arab_pc_ckb.xml b/res/xml/arab_pc_ckb.xml index bc8bb4a..53f09d9 100644 --- a/res/xml/arab_pc_ckb.xml +++ b/res/xml/arab_pc_ckb.xml @@ -1,5 +1,5 @@ - + diff --git a/res/xml/arab_pc_ir.xml b/res/xml/arab_pc_ir.xml index be2720c..f285123 100644 --- a/res/xml/arab_pc_ir.xml +++ b/res/xml/arab_pc_ir.xml @@ -1,6 +1,6 @@ - + diff --git a/res/xml/beng_national.xml b/res/xml/beng_national.xml index 9d70e37..2df7bce 100644 --- a/res/xml/beng_national.xml +++ b/res/xml/beng_national.xml @@ -1,5 +1,5 @@ - + diff --git a/res/xml/beng_provat.xml b/res/xml/beng_provat.xml index caaa836..572e0ef 100644 --- a/res/xml/beng_provat.xml +++ b/res/xml/beng_provat.xml @@ -1,5 +1,5 @@ - + diff --git a/res/xml/cyrl_jcuken_ru.xml b/res/xml/cyrl_jcuken_ru.xml index 5f392ca..eb4b939 100644 --- a/res/xml/cyrl_jcuken_ru.xml +++ b/res/xml/cyrl_jcuken_ru.xml @@ -1,5 +1,5 @@ - + diff --git a/res/xml/cyrl_jcuken_uk.xml b/res/xml/cyrl_jcuken_uk.xml index d5ae950..905f0e1 100644 --- a/res/xml/cyrl_jcuken_uk.xml +++ b/res/xml/cyrl_jcuken_uk.xml @@ -1,5 +1,5 @@ - + diff --git a/res/xml/cyrl_yaverti.xml b/res/xml/cyrl_yaverti.xml index f4eb820..a228f24 100644 --- a/res/xml/cyrl_yaverti.xml +++ b/res/xml/cyrl_yaverti.xml @@ -1,5 +1,5 @@ - + diff --git a/res/xml/deva_alt.xml b/res/xml/deva_alt.xml index 1606abd..453285c 100644 --- a/res/xml/deva_alt.xml +++ b/res/xml/deva_alt.xml @@ -1,5 +1,5 @@ - + diff --git a/res/xml/deva_inscript.xml b/res/xml/deva_inscript.xml index 1f306e7..553f43d 100644 --- a/res/xml/deva_inscript.xml +++ b/res/xml/deva_inscript.xml @@ -1,5 +1,5 @@ - + diff --git a/res/xml/grek_qwerty.xml b/res/xml/grek_qwerty.xml index 50da475..f5499ec 100644 --- a/res/xml/grek_qwerty.xml +++ b/res/xml/grek_qwerty.xml @@ -1,5 +1,5 @@ - + diff --git a/res/xml/hang_dubeolsik_kr.xml b/res/xml/hang_dubeolsik_kr.xml index 998ab8f..29dd01b 100644 --- a/res/xml/hang_dubeolsik_kr.xml +++ b/res/xml/hang_dubeolsik_kr.xml @@ -1,5 +1,5 @@ - + diff --git a/res/xml/hebr_1_il.xml b/res/xml/hebr_1_il.xml index 50ba86e..bbf5e56 100644 --- a/res/xml/hebr_1_il.xml +++ b/res/xml/hebr_1_il.xml @@ -1,6 +1,6 @@ - + diff --git a/res/xml/hebr_2_il.xml b/res/xml/hebr_2_il.xml index ff83a91..090bef8 100644 --- a/res/xml/hebr_2_il.xml +++ b/res/xml/hebr_2_il.xml @@ -1,6 +1,6 @@ - + diff --git a/res/xml/latn_azerty_fr.xml b/res/xml/latn_azerty_fr.xml index 8434466..e3cc130 100644 --- a/res/xml/latn_azerty_fr.xml +++ b/res/xml/latn_azerty_fr.xml @@ -1,7 +1,7 @@ - + diff --git a/res/xml/latn_bone.xml b/res/xml/latn_bone.xml index 2f8a012..ea31131 100644 --- a/res/xml/latn_bone.xml +++ b/res/xml/latn_bone.xml @@ -1,6 +1,6 @@ - + diff --git a/res/xml/latn_colemak.xml b/res/xml/latn_colemak.xml index a7c78f2..1a73fbb 100644 --- a/res/xml/latn_colemak.xml +++ b/res/xml/latn_colemak.xml @@ -1,6 +1,6 @@ - + diff --git a/res/xml/latn_dvorak.xml b/res/xml/latn_dvorak.xml index 4dccc23..4e052ee 100644 --- a/res/xml/latn_dvorak.xml +++ b/res/xml/latn_dvorak.xml @@ -1,5 +1,5 @@ - + diff --git a/res/xml/latn_neo2.xml b/res/xml/latn_neo2.xml index 6f20f38..939e131 100644 --- a/res/xml/latn_neo2.xml +++ b/res/xml/latn_neo2.xml @@ -1,6 +1,6 @@ - + diff --git a/res/xml/latn_qwerty_br.xml b/res/xml/latn_qwerty_br.xml index fda6f93..d76c6e4 100644 --- a/res/xml/latn_qwerty_br.xml +++ b/res/xml/latn_qwerty_br.xml @@ -1,6 +1,6 @@ - + diff --git a/res/xml/latn_qwerty_es.xml b/res/xml/latn_qwerty_es.xml index 273cfed..5f1fc24 100644 --- a/res/xml/latn_qwerty_es.xml +++ b/res/xml/latn_qwerty_es.xml @@ -1,5 +1,5 @@ - + diff --git a/res/xml/latn_qwerty_hu.xml b/res/xml/latn_qwerty_hu.xml index 302c304..aee223c 100644 --- a/res/xml/latn_qwerty_hu.xml +++ b/res/xml/latn_qwerty_hu.xml @@ -1,5 +1,5 @@ - + diff --git a/res/xml/latn_qwerty_lv.xml b/res/xml/latn_qwerty_lv.xml index 7f16d5a..1e82d8e 100644 --- a/res/xml/latn_qwerty_lv.xml +++ b/res/xml/latn_qwerty_lv.xml @@ -1,5 +1,5 @@ - + diff --git a/res/xml/latn_qwerty_no.xml b/res/xml/latn_qwerty_no.xml index 33e9f3b..9f38f06 100644 --- a/res/xml/latn_qwerty_no.xml +++ b/res/xml/latn_qwerty_no.xml @@ -1,5 +1,5 @@ - + diff --git a/res/xml/latn_qwerty_pl.xml b/res/xml/latn_qwerty_pl.xml index 1c28766..c31ae76 100644 --- a/res/xml/latn_qwerty_pl.xml +++ b/res/xml/latn_qwerty_pl.xml @@ -1,5 +1,5 @@ - + diff --git a/res/xml/latn_qwerty_ro.xml b/res/xml/latn_qwerty_ro.xml index e5e0a19..1282d36 100644 --- a/res/xml/latn_qwerty_ro.xml +++ b/res/xml/latn_qwerty_ro.xml @@ -1,5 +1,5 @@ - + diff --git a/res/xml/latn_qwerty_se.xml b/res/xml/latn_qwerty_se.xml index 69884d7..aab6bc6 100644 --- a/res/xml/latn_qwerty_se.xml +++ b/res/xml/latn_qwerty_se.xml @@ -1,5 +1,5 @@ - + diff --git a/res/xml/latn_qwerty_tr.xml b/res/xml/latn_qwerty_tr.xml index 60f52a2..2093db7 100644 --- a/res/xml/latn_qwerty_tr.xml +++ b/res/xml/latn_qwerty_tr.xml @@ -1,5 +1,5 @@ - + diff --git a/res/xml/latn_qwerty_us.xml b/res/xml/latn_qwerty_us.xml index 06e91b9..9165283 100644 --- a/res/xml/latn_qwerty_us.xml +++ b/res/xml/latn_qwerty_us.xml @@ -20,7 +20,7 @@ See bottom_row.xml for the definition of the bottom row and neo2.xml for a layout that re-defines it. See srcs/juloo.keyboard2/KeyValue.java for the keys that have a special meaning. --> - + diff --git a/res/xml/latn_qwerty_vi.xml b/res/xml/latn_qwerty_vi.xml index 8b51299..6af7bc7 100644 --- a/res/xml/latn_qwerty_vi.xml +++ b/res/xml/latn_qwerty_vi.xml @@ -1,6 +1,6 @@ - + diff --git a/res/xml/latn_qwertz.xml b/res/xml/latn_qwertz.xml index 107b738..6ba19c6 100644 --- a/res/xml/latn_qwertz.xml +++ b/res/xml/latn_qwertz.xml @@ -1,5 +1,5 @@ - + diff --git a/res/xml/latn_qwertz_cz.xml b/res/xml/latn_qwertz_cz.xml index 6546163..fc096ee 100644 --- a/res/xml/latn_qwertz_cz.xml +++ b/res/xml/latn_qwertz_cz.xml @@ -1,5 +1,5 @@ - + diff --git a/res/xml/latn_qwertz_de.xml b/res/xml/latn_qwertz_de.xml index 906c4fc..ff1ec11 100644 --- a/res/xml/latn_qwertz_de.xml +++ b/res/xml/latn_qwertz_de.xml @@ -1,6 +1,6 @@ - + diff --git a/res/xml/latn_qwertz_hu.xml b/res/xml/latn_qwertz_hu.xml index 557b2e5..a77aa1c 100644 --- a/res/xml/latn_qwertz_hu.xml +++ b/res/xml/latn_qwertz_hu.xml @@ -1,5 +1,5 @@ - + diff --git a/res/xml/latn_qwertz_sk.xml b/res/xml/latn_qwertz_sk.xml index 7d3d1f4..f71a825 100644 --- a/res/xml/latn_qwertz_sk.xml +++ b/res/xml/latn_qwertz_sk.xml @@ -1,5 +1,5 @@ - + diff --git a/sync_translations.py b/sync_translations.py index 97c0ecc..afc7237 100644 --- a/sync_translations.py +++ b/sync_translations.py @@ -1,5 +1,4 @@ import xml.etree.ElementTree as ET -from xml.sax import saxutils import glob # Edit every strings.xml files: