[Bf-translations-svn] SVN commit: /data/svn/bf-translations [458] trunk/po/tools: Updated/ enhanced update_po. py script to avoid new contexts creating hundreds of dummy fuzzy messages.

bf-translations at blender.org bf-translations at blender.org
Mon Mar 19 20:04:09 CET 2012


Revision: 458
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-translations&revision=458
Author:   mont29
Date:     2012-03-19 19:04:09 +0000 (Mon, 19 Mar 2012)
Log Message:
-----------
Updated/enhanced update_po.py script to avoid new contexts creating hundreds of dummy fuzzy messages.

The new Operator context obviously invalidate all previous operator's labels translations (or rather, make them fuzzy with their new context). So rather than forcing everyone to spend hours on manual "validations" of those "new" msgids (like I stupidely did :/ ), add an option to update_po (and hence update_branches) to pre-add those "new" msgids in the po's before actually updating them from latest pot.

The only "problem" remaining is a huge bunch of commented messages (all old no-context ops msgids), but that's another problem.

Also did some cleanup/update of comments in some scripts...

Modified Paths:
--------------
    trunk/po/tools/update_branches.py
    trunk/po/tools/update_mo.py
    trunk/po/tools/update_po.py
    trunk/po/tools/utils.py

Modified: trunk/po/tools/update_branches.py
===================================================================
--- trunk/po/tools/update_branches.py	2012-03-18 19:49:42 UTC (rev 457)
+++ trunk/po/tools/update_branches.py	2012-03-19 19:04:09 UTC (rev 458)
@@ -41,6 +41,10 @@
                                  "* Generate a temp messages.txt file.\n" \
                                  "* Use it to generate a temp .pot file.\n" \
                                  "* Use it to update all .po’s in /branches.")
+    parser.add_argument('--pproc-contexts', action="store_true",
+                        help="Pre-process po’s to avoid having plenty of "
+                             "fuzzy msgids just because a context was "
+                             "added/changed!")
     parser.add_argument('-a', '--add', action="store_true",
                         help="Add missing po’s (useful only when one or " \
                              "more languages are given!).")
@@ -81,6 +85,8 @@
         if args.add:
             cmd.append("-a")
         cmd += args.langs
+    if args.pproc_contexts:
+        cmd.append("--pproc-contexts")
     t = subprocess.call(cmd)
     if t:
         ret = t

Modified: trunk/po/tools/update_mo.py
===================================================================
--- trunk/po/tools/update_mo.py	2012-03-18 19:49:42 UTC (rev 457)
+++ trunk/po/tools/update_mo.py	2012-03-19 19:04:09 UTC (rev 458)
@@ -66,7 +66,6 @@
                         help="Restrict processed languages to those.")
     args = parser.parse_args()
 
-
     ret = 0
 
     if args.langs:
@@ -86,6 +85,7 @@
                     ret = t
     return ret
 
+
 if __name__ == "__main__":
     print("\n\n *** Running {} *** \n".format(__file__))
     sys.exit(main())

Modified: trunk/po/tools/update_po.py
===================================================================
--- trunk/po/tools/update_po.py	2012-03-18 19:49:42 UTC (rev 457)
+++ trunk/po/tools/update_po.py	2012-03-19 19:04:09 UTC (rev 458)
@@ -29,6 +29,7 @@
 import shutil
 
 import settings
+import utils
 
 GETTEXT_MSGMERGE_EXECUTABLE = settings.GETTEXT_MSGMERGE_EXECUTABLE
 BRANCHES_DIR  = settings.BRANCHES_DIR
@@ -36,6 +37,34 @@
 FILE_NAME_POT = settings.FILE_NAME_POT
 
 
+def pproc_newcontext_po(po, pot_messages, pot_stats):
+    print("Adding new contexts to {}...".format(po))
+    messages, state, stats = utils.parse_messages(po)
+    known_ctxt = stats["contexts"]
+    print("Already known (present) context(s): {}".format(str(known_ctxt)))
+
+    new_ctxt = set()
+    added = 0
+    # Only use valid already translated messages!
+    allowed_keys = state["trans_msg"] - state["fuzzy_msg"] - state["comm_msg"]
+    for (msgid, ctxt), dummy in pot_messages.items():
+        if ctxt in known_ctxt:
+            continue
+        new_ctxt.add(ctxt)
+        for t_ctxt in known_ctxt:
+            # XXX The first match will win, this might not be optimal...
+            if (msgid, t_ctxt) in allowed_keys:
+                # Wrong comments (sources) will be removed by msgmerge...
+                messages[(msgid, ctxt)] = messages[(msgid, t_ctxt)]
+                messages[(msgid, ctxt)]["msgctxt_lines"] = [ctxt]
+                added += 1
+
+    utils.write_messages(po, messages, state["comm_msg"], state["fuzzy_msg"])
+    print("Finished!\n    {} new context(s) was/were added {}, adding {} new "
+          "messages.\n".format(len(new_ctxt), str(new_ctxt), added))
+    return 0
+
+
 def process_po(po, lang):
     # update po file
     cmd = (GETTEXT_MSGMERGE_EXECUTABLE,
@@ -56,14 +85,18 @@
 
 def main():
     import argparse
-    parser = argparse.ArgumentParser(description="Write out messages.txt " \
+    parser = argparse.ArgumentParser(description="Write out messages.txt "
                                                  "from Blender.")
     parser.add_argument('-t', '--trunk', action="store_true",
                         help="Update po’s in /trunk/po rather than /branches.")
     parser.add_argument('-i', '--input', metavar="File",
                         help="Input pot file path.")
+    parser.add_argument('--pproc-contexts', action="store_true",
+                        help="Pre-process po’s to avoid having plenty of "
+                             "fuzzy msgids just because a context was "
+                             "added/changed!")
     parser.add_argument('-a', '--add', action="store_true",
-                        help="Add missing po’s (useful only when one or " \
+                        help="Add missing po’s (useful only when one or "
                              "more languages are given!).")
     parser.add_argument('langs', metavar='ISO_code', nargs='*',
                         help="Restrict processed languages to those.")
@@ -74,6 +107,13 @@
         FILE_NAME_POT = args.input
     ret = 0
 
+    if args.pproc_contexts:
+        _ctxt_proc = pproc_newcontext_po
+        pot_messages, dummy, pot_stats = utils.parse_messages(FILE_NAME_POT)
+    else:
+        _ctxt_proc = lambda a, b, c: 0
+        pot_messages, pot_stats = None, None
+
     if args.langs:
         for lang in args.langs:
             if args.trunk:
@@ -88,6 +128,9 @@
                 if not os.path.exists(po):
                     shutil.copy(FILE_NAME_POT, po)
             if args.add or os.path.exists(po):
+                t = _ctxt_proc(po, pot_messages, pot_stats)
+                if t:
+                    ret = t
                 t = process_po(po, lang)
                 if t:
                     ret = t
@@ -96,6 +139,9 @@
             if po.endswith(".po"):
                 lang = os.path.basename(po)[:-3]
                 po = os.path.join(TRUNK_PO_DIR, po)
+                t = _ctxt_proc(po, pot_messages, pot_stats)
+                if t:
+                    ret = t
                 t = process_po(po, lang)
                 if t:
                     ret = t
@@ -103,6 +149,9 @@
         for lang in os.listdir(BRANCHES_DIR):
             po = os.path.join(BRANCHES_DIR, lang, ".".join((lang, "po")))
             if os.path.exists(po):
+                t = _ctxt_proc(po, pot_messages, pot_stats)
+                if t:
+                    ret = t
                 t = process_po(po, lang)
                 if t:
                     ret = t

Modified: trunk/po/tools/utils.py
===================================================================
--- trunk/po/tools/utils.py	2012-03-18 19:49:42 UTC (rev 457)
+++ trunk/po/tools/utils.py	2012-03-19 19:04:09 UTC (rev 458)
@@ -43,12 +43,14 @@
     """
     Returns a tupple (messages, states, stats).
     messages is an odereddict of dicts
-        {ctxt: {msgid: {msgid_lines:, msgstr_lines:, comment_lines:}}}.
-    states is a dict of three sets of msgid, and a boolean flag indicating the
-        .po is somewhat broken {trans_msg:, fuzzy_msg:, comm_msg:, is_broken:}.
+        {(msgid, ctxt): {msgid_lines:, msgstr_lines:,
+                         comment_lines:, msgctxt_lines:}}.
+    states is a dict of three sets of (msgid, ctxt), and a boolean flag
+        indicating the .po is somewhat broken
+        {trans_msg:, fuzzy_msg:, comm_msg:, is_broken:}.
     stats is a dict of values
         {tot_msg:, trans_msg:, tot_ttips:, trans_ttips:, comm_msg:,
-         nbr_signs:, nbr_trans_signs:}.
+         nbr_signs:, nbr_trans_signs:, contexts: set()}.
     Note: This function will silently "arrange" mis-formated entries, thus
         using afterward write_messages() should always produce a po-valid file,
         though not correct!



More information about the Bf-translations-svn mailing list