summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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):