[Bf-translations-svn] SVN commit: /data/svn/bf-translations [171] trunk/po/tools/merge_po.py: Better version for merge_po.py fix.

bf-translations at blender.org bf-translations at blender.org
Tue Nov 8 21:02:39 CET 2011


Revision: 171
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-translations&revision=171
Author:   mont29
Date:     2011-11-08 20:02:37 +0000 (Tue, 08 Nov 2011)
Log Message:
-----------
Better version for merge_po.py fix. Also now outputs number of messages replaced in dest po (should be 0 unless you use -r option!).

Modified Paths:
--------------
    trunk/po/tools/merge_po.py

Modified: trunk/po/tools/merge_po.py
===================================================================
--- trunk/po/tools/merge_po.py	2011-11-08 19:57:25 UTC (rev 170)
+++ trunk/po/tools/merge_po.py	2011-11-08 20:02:37 UTC (rev 171)
@@ -62,6 +62,7 @@
     done_msgids = set()
     done_fuzzy_msgids = set()
     nbr_merged = 0
+    nbr_replaced = 0
     nbr_added = 0
     nbr_unfuzzied = 0
 
@@ -72,6 +73,11 @@
     if args.stats:
         print("Dest po, before merging:")
         utils.print_stats(dst_stats, prefix="    ")
+    # If we don’t want to replace existing valid translations, pre-populate
+    # done_msgids and done_fuzzy_msgids.
+    if not args.replace:
+        done_msgids =  dst_states["trans_msg"].copy()
+        done_fuzzy_msgids = dst_states["fuzzy_msg"].copy()
     for po in args.src:
         messages, states, stats = utils.parse_messages(po)
         if states["is_broken"]:
@@ -109,10 +115,8 @@
             elif msgid not in (states["trans_msg"] | states["fuzzy_msg"]):
                 continue
             # From now on, the new message is either translated or fuzzy!
-            # The new message is translated, and either replace is enabled,
-            # or the org message is fuzzy.
-            elif msgid in states["trans_msg"] and \
-                (args.replace or msgid not in dst_states["trans_msg"]):
+            # The new message is translated.
+            elif msgid in states["trans_msg"]:
                 dst_messages[msgid]["msgstr_lines"] = messages[msgid]["msgstr_lines"]
                 done_msgids.add(msgid)
                 done_fuzzy_msgids.discard(msgid)
@@ -124,19 +128,23 @@
                     dst_stats["trans_msg"] += 1
                     if is_ttip:
                         dst_stats["trans_ttips"] += 1
+                else:
+                    nbr_replaced += 1
                 nbr_merged += 1
             # The new message is fuzzy, org one is fuzzy too,
-            # replace is enabled, and this msgid has not yet been merged.
-            elif args.replace and msgid not in (dst_states["trans_msg"] | done_fuzzy_msgids):
+            # and this msgid has not yet been merged.
+            elif msgid not in (dst_states["trans_msg"] | done_fuzzy_msgids):
                 dst_messages[msgid]["msgstr_lines"] = messages[msgid]["msgstr_lines"]
                 done_fuzzy_msgids.add(msgid)
                 dst_states["fuzzy_msg"].add(msgid)
                 nbr_merged += 1
+                nbr_replaced += 1
 
     utils.write_messages(args.dst, dst_messages, dst_states["comm_msg"], dst_states["fuzzy_msg"])
 
-    print("Merged completed. {} messages were merged, {} were added, {} were \"un-fuzzied\"." \
-          "".format(nbr_merged, nbr_added, nbr_unfuzzied))
+    print("Merged completed. {} messages were merged (among which {} were replaced), " \
+          "{} were added, {} were \"un-fuzzied\"." \
+          "".format(nbr_merged, nbr_replaced, nbr_added, nbr_unfuzzied))
     if args.stats:
         print("Final merged po stats:")
         utils.print_stats(dst_stats, prefix="    ")



More information about the Bf-translations-svn mailing list