[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [51044] trunk/blender/release/scripts/ modules/bl_i18n_utils/rtl_preprocess.py: Fix for rtl processing of menu strings...

Bastien Montagne montagne29 at wanadoo.fr
Thu Oct 4 15:49:39 CEST 2012


Revision: 51044
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=51044
Author:   mont29
Date:     2012-10-04 13:49:39 +0000 (Thu, 04 Oct 2012)
Log Message:
-----------
Fix for rtl processing of menu strings...

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

Modified: trunk/blender/release/scripts/modules/bl_i18n_utils/rtl_preprocess.py
===================================================================
--- trunk/blender/release/scripts/modules/bl_i18n_utils/rtl_preprocess.py	2012-10-04 13:44:24 UTC (rev 51043)
+++ trunk/blender/release/scripts/modules/bl_i18n_utils/rtl_preprocess.py	2012-10-04 13:49:39 UTC (rev 51044)
@@ -34,6 +34,7 @@
 
 import sys
 import ctypes
+import re
 
 try:
     import settings
@@ -87,44 +88,64 @@
                        FRIBIDI_FLAG_SHAPE_ARAB_LIGA
 
 
+MENU_DETECT_REGEX = re.compile("%x\\d+\\|")
+
+
 ##### Kernel processing funcs. #####
 def protect_format_seq(msg):
     """
     Find some specific escaping/formating sequences (like \", %s, etc.,
     and protect them from any modification!
     """
+#    LRM = "\u200E"
+#    RLM = "\u200F"
     LRE = "\u202A"
+    RLE = "\u202B"
     PDF = "\u202C"
+    LRO = "\u202D"
+    RLO = "\u202E"
+    uctrl = {LRE, RLE, PDF, LRO, RLO}
     # Most likely incomplete, but seems to cover current needs.
     format_codes = set("tslfd")
     digits = set(".0123456789")
 
+    if not msg:
+        return msg
+    elif MENU_DETECT_REGEX.search(msg):
+        # An ugly "menu" message, just force it whole LRE if not yet done.
+        if msg[0] not in {LRE, LRO}:
+            msg = LRE + msg
+
     idx = 0
     ret = []
     ln = len(msg)
     while idx < ln:
         dlt = 1
+#        # If we find a control char, skip any additional protection!
+#        if msg[idx] in uctrl:
+#            ret.append(msg[idx:])
+#            break
         # \" or \'
         if idx < (ln - 1) and msg[idx] == '\\' and msg[idx + 1] in "\"\'":
             dlt = 2
-        # %x12
-        elif idx < (ln - 2) and msg[idx] == '%' and msg[idx + 1] in "x" and \
-             msg[idx + 2] in digits:
+        # %x12|
+        elif idx < (ln - 2) and msg[idx] == '%' and msg[idx + 1] in "x" and msg[idx + 2] in digits:
             dlt = 2
-            while (idx + dlt + 1) < ln and msg[idx + dlt + 1] in digits:
+            while (idx + dlt) < ln and msg[idx + dlt] in digits:
                 dlt += 1
+            if (idx + dlt) < ln  and msg[idx + dlt] is '|':
+                dlt += 1
         # %.4f
         elif idx < (ln - 3) and msg[idx] == '%' and msg[idx + 1] in digits:
             dlt = 2
-            while (idx + dlt + 1) < ln and msg[idx + dlt + 1] in digits:
+            while (idx + dlt) < ln and msg[idx + dlt] in digits:
                 dlt += 1
-            if (idx + dlt + 1) < ln and msg[idx + dlt + 1] in format_codes:
+            if (idx + dlt) < ln and msg[idx + dlt] in format_codes:
                 dlt += 1
             else:
                 dlt = 1
         # %s
-        elif idx < (ln - 1) and msg[idx] == '%' and \
-             msg[idx + 1] in format_codes:
+        elif idx < (ln - 1) and msg[idx] == '%' and msg[idx + 1] in format_codes:
             dlt = 2
 
         if dlt > 1:




More information about the Bf-blender-cvs mailing list