[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56144] trunk/blender/release/scripts/ modules/bl_i18n_utils/utils.py: Some i18n tools fixes (I'm ashamed...), and merge func for I18nMessages objects.

Bastien Montagne montagne29 at wanadoo.fr
Thu Apr 18 17:26:22 CEST 2013


Revision: 56144
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56144
Author:   mont29
Date:     2013-04-18 15:26:22 +0000 (Thu, 18 Apr 2013)
Log Message:
-----------
Some i18n tools fixes (I'm ashamed...), and merge func for I18nMessages objects.

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/bl_i18n_utils/utils.py

Modified: trunk/blender/release/scripts/modules/bl_i18n_utils/utils.py
===================================================================
--- trunk/blender/release/scripts/modules/bl_i18n_utils/utils.py	2013-04-18 15:09:30 UTC (rev 56143)
+++ trunk/blender/release/scripts/modules/bl_i18n_utils/utils.py	2013-04-18 15:26:22 UTC (rev 56144)
@@ -132,7 +132,7 @@
     return tuple(e[0] for e in sorted((e for e in tmp if e[1] is not ... and e[1] >= 0), key=lambda e: e[1]))
 
 
-def get_po_files_from_dir(root_dir, langs=set())
+def get_po_files_from_dir(root_dir, langs=set()):
     """
     Yield tuples (uid, po_path) of translations for each po file found in the given dir, which should be either
     a dir containing po files using language uid's as names (e.g. fr.po, es_ES.po, etc.), or
@@ -140,12 +140,13 @@
     """
     found_uids = set()
     for p in os.listdir(root_dir):
-        uid = po_file = None
-        if p.endswith(".po") and os.path.isfile(p):
+        uid = None
+        po_file = os.path.join(root_dir, p)
+        print(p)
+        if p.endswith(".po") and os.path.isfile(po_file):
             uid = p[:-3]
             if langs and uid not in langs:
                 continue
-            po_file = os.path.join(root_dir, p)
         elif os.path.isdir(p):
             uid = p
             if langs and uid not in langs:
@@ -489,9 +490,27 @@
         for k, t in zip(keys, trans):
             self.msgs[k].msgstr = t
 
-    def merge(self, replace=False, *args):
-        # TODO
-        pass
+    def merge(self, msgs, replace=False):
+        """
+        Merge translations from msgs into self, following those rules:
+            * If a msg is in self and not in msgs, keep self untouched.
+            * If a msg is in msgs and not in self, skip it.
+            * Else (msg both in self and msgs):
+                * If self is not translated and msgs is translated or fuzzy, replace by msgs.
+                * If self is fuzzy, and msgs is translated, replace by msgs.
+                * If self is fuzzy, and msgs is fuzzy, and replace is True, replace by msgs.
+                * If self is translated, and msgs is translated, and replace is True, replace by msgs.
+                * Else, skip it!
+        """
+        for k, m in msgs.msgs.items():
+            if k not in self.msgs:
+                continue
+            sm = self.msgs[k]
+            if (sm.is_commented or m.is_commented or not m.msgstr):
+                continue
+            if (not sm.msgstr or replace or (sm.is_fuzzy and (not m.is_fuzzy or replace))):
+                sm.msgstr = m.msgstr
+                sm.is_fuzzy = m.is_fuzzy
 
     def update(self, ref, use_similar=None, keep_old_commented=True):
         """
@@ -1379,7 +1398,7 @@
             translations = self.trans.keys() - {self.settings.PARSER_TEMPLATE_ID, self.settings.PARSER_PY_ID}
             if langs:
                 translations &= langs
-            translations = [('"' + lng + '"', " " * (len(lng) + 4), self.trans[lng]) for lng in sorted(translations)]
+            translations = [('"' + lng + '"', " " * (len(lng) + 6), self.trans[lng]) for lng in sorted(translations)]
             print(k for k in keys.keys())
             for key in keys.keys():
                 if ref.msgs[key].is_commented:




More information about the Bf-blender-cvs mailing list