[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [52518] trunk/blender/release/scripts/ modules/bl_i18n_utils: Handle of new BLF_I18N_MSGID_MULTI_CTXT macro, which allows to define a same msgid in up to 16 different contexts at once .

Bastien Montagne montagne29 at wanadoo.fr
Fri Nov 23 16:35:17 CET 2012


Revision: 52518
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=52518
Author:   mont29
Date:     2012-11-23 15:35:16 +0000 (Fri, 23 Nov 2012)
Log Message:
-----------
Handle of new BLF_I18N_MSGID_MULTI_CTXT macro, which allows to define a same msgid in up to 16 different contexts at once.

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

Modified: trunk/blender/release/scripts/modules/bl_i18n_utils/settings.py
===================================================================
--- trunk/blender/release/scripts/modules/bl_i18n_utils/settings.py	2012-11-23 15:33:44 UTC (rev 52517)
+++ trunk/blender/release/scripts/modules/bl_i18n_utils/settings.py	2012-11-23 15:35:16 UTC (rev 52518)
@@ -114,6 +114,9 @@
 # File type (ext) to parse.
 PYGETTEXT_ALLOWED_EXTS = {".c", ".cpp", ".cxx", ".hpp", ".hxx", ".h"}
 
+# Max number of contexts into a BLF_I18N_MSGID_MULTI_CTXT macro...
+PYGETTEXT_MAX_MULTI_CTXT = 16
+
 # Where to search contexts definitions, relative to SOURCE_DIR (defined below).
 PYGETTEXT_CONTEXTS_DEFSRC = os.path.join("source", "blender", "blenfont",
                                          "BLF_translation.h")
@@ -149,7 +152,10 @@
     # End of loop.
     "))*"
 )
-_ctxt_re = r"(?P<ctxt_raw>(?:" + _str_whole_re.format(_="_ctxt") + r")|(?:[A-Z_0-9]+))"
+_ctxt_re_gen = lambda uid : r"(?P<ctxt_raw{uid}>(?:".format(uid=uid) + \
+                            _str_whole_re.format(_="_ctxt{uid}".format(uid=uid)) + \
+                            r")|(?:[A-Z_0-9]+))"
+_ctxt_re = _ctxt_re_gen("")
 _msg_re = r"(?P<msg_raw>" + _str_whole_re.format(_="_msg") + r")"
 PYGETTEXT_KEYWORDS = (() +
     tuple((r"{}\(\s*" + _msg_re + r"\s*\)").format(it)
@@ -165,7 +171,11 @@
           for it in ("BMO_error_raise",)) +
 
     tuple(("{}\\((?:[^\"',]+,)\\s*" + _msg_re + r"\s*(?:\)|,)").format(it)
-          for it in ("modifier_setError",))
+          for it in ("modifier_setError",)) +
+
+    tuple((r"{}\(\s*" + _msg_re + r"\s*,\s*(?:" + \
+           r"\s*,\s*)?(?:".join(_ctxt_re_gen(i) for i in range(PYGETTEXT_MAX_MULTI_CTXT)) + r")?\s*\)").format(it)
+          for it in ("BLF_I18N_MSGID_MULTI_CTXT",))
 )
 
 ESCAPE_RE = (

Modified: trunk/blender/release/scripts/modules/bl_i18n_utils/update_pot.py
===================================================================
--- trunk/blender/release/scripts/modules/bl_i18n_utils/update_pot.py	2012-11-23 15:33:44 UTC (rev 52517)
+++ trunk/blender/release/scripts/modules/bl_i18n_utils/update_pot.py	2012-11-23 15:35:16 UTC (rev 52518)
@@ -52,6 +52,7 @@
 
 CONTEXT_DEFAULT = settings.CONTEXT_DEFAULT
 PYGETTEXT_ALLOWED_EXTS = settings.PYGETTEXT_ALLOWED_EXTS
+PYGETTEXT_MAX_MULTI_CTXT = settings.PYGETTEXT_MAX_MULTI_CTXT
 
 SVN_EXECUTABLE = settings.SVN_EXECUTABLE
 
@@ -79,6 +80,31 @@
 
 
 def check_file(path, rel_path, messages):
+    def process_entry(ctxt, msg):
+        # Context.
+        if ctxt:
+            if ctxt in CONTEXTS:
+                ctxt = CONTEXTS[ctxt]
+            elif '"' in ctxt or "'" in ctxt:
+                ctxt = clean_str(ctxt)
+            else:
+                print("WARNING: raw context “{}” couldn’t be resolved!"
+                      "".format(ctxt))
+                ctxt = CONTEXT_DEFAULT
+        else:
+            ctxt = CONTEXT_DEFAULT
+        # Message.
+        if msg:
+            if '"' in msg or "'" in msg:
+                msg = clean_str(msg)
+            else:
+                print("WARNING: raw message “{}” couldn’t be resolved!"
+                      "".format(msg))
+                msg = ""
+        else:
+            msg = ""
+        return (ctxt, msg)
+
     with open(path, encoding="utf-8") as f:
         f = f.read()
         for srch in pygettexts:
@@ -86,34 +112,23 @@
             line = pos = 0
             while m:
                 d = m.groupdict()
-                # Context.
-                ctxt = d.get("ctxt_raw")
-                if ctxt:
-                    if ctxt in CONTEXTS:
-                        ctxt = CONTEXTS[ctxt]
-                    elif '"' in ctxt or "'" in ctxt:
-                        ctxt = clean_str(ctxt)
-                    else:
-                        print("WARNING: raw context “{}” couldn’t be resolved!"
-                              "".format(ctxt))
-                        ctxt = CONTEXT_DEFAULT
-                else:
-                    ctxt = CONTEXT_DEFAULT
-                # Message.
+                # Line.
+                line += f[pos:m.start()].count('\n')
                 msg = d.get("msg_raw")
-                if msg:
-                    if '"' in msg or "'" in msg:
-                        msg = clean_str(msg)
-                    else:
-                        print("WARNING: raw message “{}” couldn’t be resolved!"
-                              "".format(msg))
-                        msg = ""
+                # First, try the "multi-contexts" stuff!
+                ctxts = tuple(d.get("ctxt_raw{}".format(i)) for i in range(PYGETTEXT_MAX_MULTI_CTXT))
+                if ctxts[0]:
+                    for ctxt in ctxts:
+                        if not ctxt:
+                            break
+                        ctxt, _msg = process_entry(ctxt, msg)
+                        # And we are done for this item!
+                        messages.setdefault((ctxt, _msg), []).append(":".join((rel_path, str(line))))
                 else:
-                    msg = ""
-                # Line.
-                line += f[pos:m.start()].count('\n')
-                # And we are done for this item!
-                messages.setdefault((ctxt, msg), []).append(":".join((rel_path, str(line))))
+                    ctxt = d.get("ctxt_raw")
+                    ctxt, msg = process_entry(ctxt, msg)
+                    # And we are done for this item!
+                    messages.setdefault((ctxt, msg), []).append(":".join((rel_path, str(line))))
                 pos = m.end()
                 line += f[m.start():pos].count('\n')
                 m = srch(f, pos)
@@ -138,12 +153,12 @@
             rel_path = os.path.relpath(path, SOURCE_DIR)
             if rel_path in forbidden:
                 continue
-            elif rel_path in forced:
-                forced.remove(rel_path)
+            elif rel_path not in forced:
+                forced.add(rel_path)
+    for rel_path in sorted(forced):
+        path = os.path.join(SOURCE_DIR, rel_path)
+        if os.path.exists(path):
             check_file(path, rel_path, messages)
-    for path in forced:
-        if os.path.exists(path):
-            check_file(os.path.join(SOURCE_DIR, path), path, messages)
 
 
 # Spell checking!




More information about the Bf-blender-cvs mailing list