[Bf-translations-svn] SVN commit: /data/svn/bf-translations [277] trunk/po/tools: Small complements to previous commit, tools should now be fully ok again!

bf-translations at blender.org bf-translations at blender.org
Thu Dec 22 21:57:17 CET 2011


Revision: 277
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-translations&revision=277
Author:   mont29
Date:     2011-12-22 20:57:07 +0000 (Thu, 22 Dec 2011)
Log Message:
-----------
Small complements to previous commit, tools should now be fully ok again!

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

Modified: trunk/po/tools/clean_po.py
===================================================================
--- trunk/po/tools/clean_po.py	2011-12-22 20:35:14 UTC (rev 276)
+++ trunk/po/tools/clean_po.py	2011-12-22 20:57:07 UTC (rev 277)
@@ -42,8 +42,8 @@
         print("    ERROR! This .po file is broken!")
         return 1
 
-    for msgid in states["comm_msg"]:
-        del messages[msgid]
+    for msgkey in states["comm_msg"]:
+        del messages[msgkey]
     utils.write_messages(po, messages, states["comm_msg"], states["fuzzy_msg"])
     print("    Removed {} commented messages.".format(len(states["comm_msg"])))
     return 0

Modified: trunk/po/tools/merge_po.py
===================================================================
--- trunk/po/tools/merge_po.py	2011-12-22 20:35:14 UTC (rev 276)
+++ trunk/po/tools/merge_po.py	2011-12-22 20:57:07 UTC (rev 277)
@@ -21,7 +21,7 @@
 # <pep8 compliant>
 
 # Merge one or more .po files into the first dest one.
-# If a msgid is present in more than one merged po, the one in the first file wins, unless 
+# If a msgkey is present in more than one merged po, the one in the first file wins, unless 
 # it’s marked as fuzzy and one later is not.
 # The fuzzy flag is removed if necessary.
 # All other comments are never modified.
@@ -38,9 +38,9 @@
     import argparse
     parser = argparse.ArgumentParser(description="" \
                     "Merge one or more .po files into the first dest one.\n" \
-                    "If a msgid is present in more than one merged po, the " \
-                    "one in the first file wins, unless it’s marked as " \
-                    "fuzzy and one later is not.\n" \
+                    "If a msgkey (msgid, msgctxt) is present in more than " \
+                    "one merged po, the one in the first file wins, unless " \
+                    "it’s marked as fuzzy and one later is not.\n" \
                     "The fuzzy flag is removed if necessary.\n" \
                     "All other comments are never modified.\n" \
                     "Commented messages in dst will always remain " \
@@ -58,8 +58,8 @@
 
 
     ret = 0
-    done_msgids = set()
-    done_fuzzy_msgids = set()
+    done_msgkeys = set()
+    done_fuzzy_msgkeys = set()
     nbr_merged = 0
     nbr_replaced = 0
     nbr_added = 0
@@ -73,10 +73,10 @@
         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.
+    # done_msgkeys and done_fuzzy_msgkeys.
     if not args.replace:
-        done_msgids =  dst_states["trans_msg"].copy()
-        done_fuzzy_msgids = dst_states["fuzzy_msg"].copy()
+        done_msgkeys =  dst_states["trans_msg"].copy()
+        done_fuzzy_msgkeys = dst_states["fuzzy_msg"].copy()
     for po in args.src:
         messages, states, stats = utils.parse_messages(po)
         if states["is_broken"]:
@@ -87,21 +87,22 @@
         if args.stats:
             print("    Merged po stats:")
             utils.print_stats(stats, prefix="        ")
-        for msgid, val in messages.items():
-            # This msgid has already been completely merged, or is a commented one,
+        for msgkey, val in messages.items():
+            msgid, msgctxt = msgkey
+            # This msgkey has already been completely merged, or is a commented one,
             # or the new message is commented, skip it.
-            if msgid in (done_msgids | dst_states["comm_msg"] | states["comm_msg"]):
+            if msgkey in (done_msgkeys | dst_states["comm_msg"] | states["comm_msg"]):
                 continue
             is_ttip = utils.is_tooltip(msgid)
             # New messages does not yet exists in dest.
-            if msgid not in dst_messages:
-                dst_messages[msgid] = messages[msgid]
-                if msgid in states["fuzzy_msg"]:
-                    done_fuzzy_msgids.add(msgid)
-                    dst_states["fuzzy_msg"].add(msgid)
-                elif msgid in states["trans_msg"]:
-                    done_msgids.add(msgid)
-                    dst_states["trans_msg"].add(msgid)
+            if msgkey not in dst_messages:
+                dst_messages[msgkey] = messages[msgkey]
+                if msgkey in states["fuzzy_msg"]:
+                    done_fuzzy_msgkeys.add(msgkey)
+                    dst_states["fuzzy_msg"].add(msgkey)
+                elif msgkey in states["trans_msg"]:
+                    done_msgkeys.add(msgkey)
+                    dst_states["trans_msg"].add(msgkey)
                     dst_stats["trans_msg"] += 1
                     if is_ttip:
                         dst_stats["trans_ttips"] += 1
@@ -111,19 +112,19 @@
                     dst_stats["tot_ttips"] += 1
             # From now on, the new messages is already in dst.
             # New message is neither translated nor fuzzy, skip it.
-            elif msgid not in (states["trans_msg"] | states["fuzzy_msg"]):
+            elif msgkey 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.
-            elif msgid in states["trans_msg"]:
-                dst_messages[msgid]["msgstr_lines"] = messages[msgid]["msgstr_lines"]
-                done_msgids.add(msgid)
-                done_fuzzy_msgids.discard(msgid)
-                if msgid in dst_states["fuzzy_msg"]:
-                    dst_states["fuzzy_msg"].remove(msgid)
+            elif msgkey in states["trans_msg"]:
+                dst_messages[msgkey]["msgstr_lines"] = messages[msgkey]["msgstr_lines"]
+                done_msgkeys.add(msgkey)
+                done_fuzzy_msgkeys.discard(msgkey)
+                if msgkey in dst_states["fuzzy_msg"]:
+                    dst_states["fuzzy_msg"].remove(msgkey)
                     nbr_unfuzzied += 1
-                if msgid not in dst_states["trans_msg"]:
-                    dst_states["trans_msg"].add(msgid)
+                if msgkey not in dst_states["trans_msg"]:
+                    dst_states["trans_msg"].add(msgkey)
                     dst_stats["trans_msg"] += 1
                     if is_ttip:
                         dst_stats["trans_ttips"] += 1
@@ -131,11 +132,11 @@
                     nbr_replaced += 1
                 nbr_merged += 1
             # The new message is fuzzy, org one is fuzzy too,
-            # 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)
+            # and this msgkey has not yet been merged.
+            elif msgkey not in (dst_states["trans_msg"] | done_fuzzy_msgkeys):
+                dst_messages[msgkey]["msgstr_lines"] = messages[msgkey]["msgstr_lines"]
+                done_fuzzy_msgkeys.add(msgkey)
+                dst_states["fuzzy_msg"].add(msgkey)
                 nbr_merged += 1
                 nbr_replaced += 1
 



More information about the Bf-translations-svn mailing list