[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48712] trunk/blender/release/scripts/ modules/bl_i18n_utils: Update/fixes (was escaping more chars than needed!)

Bastien Montagne montagne29 at wanadoo.fr
Sat Jul 7 16:28:50 CEST 2012


Revision: 48712
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48712
Author:   mont29
Date:     2012-07-07 14:28:49 +0000 (Sat, 07 Jul 2012)
Log Message:
-----------
Update/fixes (was escaping more chars than needed!)

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/bl_i18n_utils/settings.py
    trunk/blender/release/scripts/modules/bl_i18n_utils/update_po.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-07-07 13:51:07 UTC (rev 48711)
+++ trunk/blender/release/scripts/modules/bl_i18n_utils/settings.py	2012-07-07 14:28:49 UTC (rev 48712)
@@ -100,9 +100,12 @@
     tuple((r"{}\(\s*" + _ctxt_re + r"\s*,\s*"+ _msg_re + r"\s*\)").format(it)
           for it in ("CTX_IFACE_", "CTX_TIP_", "CTX_N_"))
 )
-#GETTEXT_KEYWORDS = ("IFACE_", "CTX_IFACE_:1c,2", "TIP_", "CTX_TIP_:1c,2",
-#                    "N_", "CTX_N_:1c,2")
 
+ESCAPE_RE = (
+    ('((?<!\\\\)"|(?<!\\\\)\\\\(?!\\\\|"))', r"\\\1"),
+    ('\t', r"\\t"),
+)
+
 # Should po parser warn when finding a first letter not capitalized?
 WARN_MSGID_NOT_CAPITALIZED = True
 

Modified: trunk/blender/release/scripts/modules/bl_i18n_utils/update_po.py
===================================================================
--- trunk/blender/release/scripts/modules/bl_i18n_utils/update_po.py	2012-07-07 13:51:07 UTC (rev 48711)
+++ trunk/blender/release/scripts/modules/bl_i18n_utils/update_po.py	2012-07-07 14:28:49 UTC (rev 48712)
@@ -71,6 +71,8 @@
     # update po file
     cmd = (GETTEXT_MSGMERGE_EXECUTABLE,
            "--update",
+           "-w", "1",  # XXX Ugly hack to prevent msgmerge merging
+                       #     short source comments together!
            "--no-wrap",
            "--backup=none",
            "--lang={}".format(lang),

Modified: trunk/blender/release/scripts/modules/bl_i18n_utils/update_pot.py
===================================================================
--- trunk/blender/release/scripts/modules/bl_i18n_utils/update_pot.py	2012-07-07 13:51:07 UTC (rev 48711)
+++ trunk/blender/release/scripts/modules/bl_i18n_utils/update_pot.py	2012-07-07 14:28:49 UTC (rev 48712)
@@ -59,16 +59,6 @@
 SPELL_CACHE = settings.SPELL_CACHE
 
 
-#def generate_valid_potfiles(final_potfiles):
-#    "Generates a temp potfiles.in with aboslute paths."
-#    with open(FILE_NAME_POTFILES, 'r', 'utf-8') as f, \
-#         open(final_potfiles, 'w', 'utf-8') as w:
-#        for line in f:
-#            line = utils.stripeol(line)
-#            if line:
-#                w.write("".join((os.path.join(SOURCE_DIR,
-#                                              os.path.normpath(line)), "\n")))
-
 # Do this only once!
 # Get contexts defined in blf.
 CONTEXTS = {}
@@ -79,7 +69,7 @@
     # (key=C_macro_name, value=C_string).
     CONTEXTS = dict(m.groups() for m in reg.finditer(f))
 
-# Build regexes to extract messages (with optinal contexts) from C source.
+# Build regexes to extract messages (with optional contexts) from C source.
 pygettexts = tuple(re.compile(r).search
                    for r in settings.PYGETTEXT_KEYWORDS)
 _clean_str = re.compile(settings.str_clean_re).finditer
@@ -203,6 +193,8 @@
     return utils.gen_empty_messages(blender_rev, time_str, year_str)
 
 
+escape_re = tuple(re.compile(r[0]) for r in settings.ESCAPE_RE)
+escape = lambda s, n: escape_re[n].sub(settings.ESCAPE_RE[n][1], s)
 def merge_messages(msgs, states, messages, do_checks, spell_cache):
     num_added = num_present = 0
     for (context, msgid), srcs in messages.items():
@@ -214,9 +206,8 @@
                 print("\tFrom:\n\t\t" + "\n\t\t".join(srcs))
 
         # Escape some chars in msgid!
-        msgid = msgid.replace("\\", "\\\\")
-        msgid = msgid.replace("\"", "\\\"")
-        msgid = msgid.replace("\t", "\\t")
+        for n in range(len(escape_re)):
+            msgid = escape(msgid, n)
 
         srcs = [COMMENT_PREFIX_SOURCE + s for s in srcs]
 




More information about the Bf-blender-cvs mailing list