summaryrefslogtreecommitdiff
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
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>
-rwxr-xr-xbin/ui-converter-skeleton.py64
-rw-r--r--l10ntools/source/localize.cxx33
-rwxr-xr-xsolenv/bin/uiex4
3 files changed, 100 insertions, 1 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
diff --git a/l10ntools/source/localize.cxx b/l10ntools/source/localize.cxx
index 9b1ac7f14308..3cb8c8df2657 100644
--- a/l10ntools/source/localize.cxx
+++ b/l10ntools/source/localize.cxx
@@ -213,13 +213,18 @@ bool handleFile(const OString& rProject, const OUString& rUrl, const OString& rP
sInPath = OUStringToOString( sInPathTmp, RTL_TEXTENCODING_UTF8 );
}
OString sOutPath;
- if (commands[i].executable == "uiex" || commands[i].executable == "hrcex")
+ bool bCreatedFile = false;
+ bool bSimpleModuleCase = commands[i].executable == "uiex" || commands[i].executable == "hrcex";
+ if (bSimpleModuleCase)
sOutPath = gDestRoot + "/" + rProject + "/messages.pot";
else
sOutPath = rPotDir + ".pot";
if (!fileExists(sOutPath))
+ {
InitPoFile(rProject, sInPath, rPotDir, sOutPath);
+ bCreatedFile = true;
+ }
handleCommand(sInPath, sOutPath, commands[i].executable);
{
@@ -229,6 +234,7 @@ bool handleFile(const OString& rProject, const OUString& rUrl, const OString& rP
aPOStream.readEntry( aPO );
bool bDel = aPOStream.eof();
aPOStream.close();
+
if (bDel)
{
if ( system(OString("rm " + sOutPath).getStr()) != 0 )
@@ -239,8 +245,33 @@ bool handleFile(const OString& rProject, const OUString& rUrl, const OString& rP
throw false; //TODO
}
}
+ else if (bCreatedFile && bSimpleModuleCase)
+ {
+ // add one stock Add, Cancel, Close, Help, No, OK, Yes entry to each module.po
+ // and duplicates in .ui files then filtered out by solenv/bin/uiex
+
+ std::ofstream aOutPut;
+ aOutPut.open(sOutPath.getStr(), std::ios_base::out | std::ios_base::app);
+
+ aOutPut << "#. wH3TZ\nmsgctxt \"stock\"\nmsgid \"_Add\"\nmsgstr \"\"\n\n";
+ aOutPut << "#. S9dsC\nmsgctxt \"stock\"\nmsgid \"_Apply\"\nmsgstr \"\"\n\n";
+ aOutPut << "#. TMo6G\nmsgctxt \"stock\"\nmsgid \"_Cancel\"\nmsgstr \"\"\n\n";
+ aOutPut << "#. MRCkv\nmsgctxt \"stock\"\nmsgid \"_Close\"\nmsgstr \"\"\n\n";
+ aOutPut << "#. nvx5t\nmsgctxt \"stock\"\nmsgid \"_Delete\"\nmsgstr \"\"\n\n";
+ aOutPut << "#. YspCj\nmsgctxt \"stock\"\nmsgid \"_Edit\"\nmsgstr \"\"\n\n";
+ aOutPut << "#. imQxr\nmsgctxt \"stock\"\nmsgid \"_Help\"\nmsgstr \"\"\n\n";
+ aOutPut << "#. RbjyB\nmsgctxt \"stock\"\nmsgid \"_New\"\nmsgstr \"\"\n\n";
+ aOutPut << "#. dx2yy\nmsgctxt \"stock\"\nmsgid \"_No\"\nmsgstr \"\"\n\n";
+ aOutPut << "#. M9DsL\nmsgctxt \"stock\"\nmsgid \"_OK\"\nmsgstr \"\"\n\n";
+ aOutPut << "#. VtJS9\nmsgctxt \"stock\"\nmsgid \"_Remove\"\nmsgstr \"\"\n\n";
+ aOutPut << "#. C69Fy\nmsgctxt \"stock\"\nmsgid \"_Reset\"\nmsgstr \"\"\n\n";
+ aOutPut << "#. mgpxh\nmsgctxt \"stock\"\nmsgid \"_Yes\"\nmsgstr \"\"\n";
+
+ aOutPut.close();
+ }
}
+
return true;
}
break;
diff --git a/solenv/bin/uiex b/solenv/bin/uiex
index c9b00b2e062c..ba47d8e2f9a8 100755
--- a/solenv/bin/uiex
+++ b/solenv/bin/uiex
@@ -27,6 +27,10 @@ with open(ofile, "a") as output:
if len(po) != 0:
print >> output, ""
for entry in po:
+ # skip 'stock' entries like "cancel", "help", "ok", etc
+ # l10ntools/source/localize.cxx will insert one entry for each stock per .po
+ if entry.msgctxt == "stock":
+ continue
keyid = entry.msgctxt + '|' + entry.msgid
print >> output, '#. ' + polib.genKeyId(keyid)
for i, occurrence in enumerate(entry.occurrences):