summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2021-01-05 14:58:40 +0000
committerCaolán McNamara <caolanm@redhat.com>2021-01-15 10:11:43 +0100
commitd5d905b480c2a9b1db982f2867e87b5c230d1ab9 (patch)
tree7cdda2d3435ebe6367f2e7becafa48c7f369b501 /bin
parentf89b94c280e8d986cdf08271f5cdc6b1dfe09575 (diff)
prep to replace stock button labels
a) as per https://developer.gnome.org/gtk3/stable/gtk3-Stock-Items.html use-stock=gtk-ok is deprecated and plain "OK", "Cancel" are indicated instead. b) to avoid adding thousands of extra labels to translate we'll convert use-stock buttons to use the translatable strings, but give them all the same "stock" translation context. Our translation rules don't like duplicates in the output .po's so strip "stock" contents from the translation collection rules in uiex and add a single set per .po in l10ntools/source/localize.cxx c) a script to rewrite the .uis to the new rules the previously use-stock labels won't appear translated until there has been a round trip of extraction, translations and import of translations Change-Id: Ibe4d0d27f2abbf5aa3df9c63af1561cd01d9fddd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108812 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'bin')
-rwxr-xr-xbin/ui-converter-skeleton.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/bin/ui-converter-skeleton.py b/bin/ui-converter-skeleton.py
index 298b6c024daf..01d3bad26105 100755
--- a/bin/ui-converter-skeleton.py
+++ b/bin/ui-converter-skeleton.py
@@ -34,6 +34,69 @@ def add_truncate_multiline(current):
truncate_multiline.text = "True"
current.insert(insertpos - 1, truncate_multiline)
+def do_replace_button_use_stock(current, use_stock, use_underline, label, insertpos):
+ if not use_underline:
+ underline = etree.Element("property")
+ attributes = underline.attrib
+ attributes["name"] = "use-underline"
+ underline.text = "True"
+ current.insert(insertpos - 1, underline)
+ current.remove(use_stock)
+ attributes = label.attrib
+ attributes["translatable"] = "yes"
+ attributes["context"] = "stock"
+ if label.text == 'gtk-add':
+ label.text = "_Add"
+ elif label.text == 'gtk-apply':
+ label.text = "_Apply"
+ elif label.text == 'gtk-cancel':
+ label.text = "_Cancel"
+ elif label.text == 'gtk-close':
+ label.text = "_Close"
+ elif label.text == 'gtk-delete':
+ label.text = "_Delete"
+ elif label.text == 'gtk-edit':
+ label.text = "_Edit"
+ elif label.text == 'gtk-help':
+ label.text = "_Help"
+ elif label.text == 'gtk-new':
+ label.text = "_New"
+ elif label.text == 'gtk-no':
+ label.text = "_No"
+ elif label.text == 'gtk-ok':
+ label.text = "_OK"
+ elif label.text == 'gtk-remove':
+ label.text = "_Remove"
+ elif label.text == 'gtk-revert-to-saved':
+ label.text = "_Reset"
+ elif label.text == 'gtk-yes':
+ label.text = "_yes"
+ else:
+ raise("unknown label")
+
+def replace_button_use_stock(current):
+ use_underline = False
+ use_stock = None
+ label = None
+ isbutton = current.get('class') == "GtkButton"
+ insertpos = 0
+ for child in current:
+ replace_button_use_stock(child)
+ insertpos = insertpos + 1;
+ if not isbutton:
+ continue
+ if child.tag == "property":
+ attributes = child.attrib
+ if attributes.get("name") == "use_underline" or attributes.get("name") == "use-underline":
+ use_underline = True
+ if attributes.get("name") == "use_stock" or attributes.get("name") == "use-stock":
+ use_stock = child
+ if attributes.get("name") == "label":
+ label = child
+
+ if isbutton and use_stock != None:
+ do_replace_button_use_stock(current, use_stock, use_underline, label, insertpos)
+
with open(sys.argv[1], encoding="utf-8") as f:
header = f.readline()
firstline = f.readline()
@@ -57,6 +120,7 @@ with open(sys.argv[1], encoding="utf-8") as f:
# tdf#138848 Copy-and-Paste in input box should not append an ENTER character
if not sys.argv[1].endswith('/multiline.ui'): # let this one alone not truncate multiline pastes
add_truncate_multiline(root)
+replace_button_use_stock(root)
with open(sys.argv[1], 'wb') as o:
# without encoding='unicode' (and the matching encode("utf8")) we get &#XXXX replacements for non-ascii characters