[Bf-translations-svn] SVN commit: /data/svn/bf-translations [124] trunk/po/tools/_update_msg.py: Fixed a bug in messages.txt generation code, strings in subscript expressions (like foo in bar["foo"] were also " captured" as msgids?\226?\128?\166 Only 4 msgids less, but that?\226?\128? \153s good anyway!
bf-translations at blender.org
bf-translations at blender.org
Sun Oct 23 12:05:56 CEST 2011
Revision: 124
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-translations&revision=124
Author: mont29
Date: 2011-10-23 10:05:55 +0000 (Sun, 23 Oct 2011)
Log Message:
-----------
Fixed a bug in messages.txt generation code, strings in subscript expressions (like foo in bar["foo"] were also "captured" as msgids?\226?\128?\166 Only 4 msgids less, but that?\226?\128?\153s good anyway!
Modified Paths:
--------------
trunk/po/tools/_update_msg.py
Modified: trunk/po/tools/_update_msg.py
===================================================================
--- trunk/po/tools/_update_msg.py 2011-10-23 08:48:13 UTC (rev 123)
+++ trunk/po/tools/_update_msg.py 2011-10-23 10:05:55 UTC (rev 124)
@@ -238,6 +238,10 @@
# so far only 'text' keywords, but we may want others translated later
translate_kw = ("text", )
+ # Break recursive nodes look up on some kind of nodes.
+ # E.g. we don’t want to get strings inside subscripts (blah["foo"])!
+ stopper_nodes = {ast.Subscript,}
+
for func_id, func in bpy.types.UILayout.bl_rna.functions.items():
# check it has a 'text' argument
for (arg_pos, (arg_kw, arg)) in enumerate(func.parameters.items()):
@@ -252,19 +256,23 @@
# -------------------------------------------------------------------------
# Function definitions
- def extract_strings(fp_rel, node_container):
- """ Recursively get strings, needed incase we have "Blah" + "Blah",
+ def extract_strings(fp_rel, node):
+ """ Recursively get strings, needed in case we have "Blah" + "Blah",
passed as an argument in that case it wont evaluate to a string.
+ However, break on some kind of stopper nodes, like e.g. Subscript.
"""
- for node in ast.walk(node_container):
- if type(node) == ast.Str:
- eval_str = ast.literal_eval(node)
- if eval_str:
- # print("%s:%d: %s" % (fp, node.lineno, eval_str))
- msgsrc = "%s:%s" % (fp_rel, node.lineno)
- messages.setdefault(eval_str, []).append(msgsrc)
+ if type(node) == ast.Str:
+ eval_str = ast.literal_eval(node)
+ if eval_str:
+ msgsrc = "%s:%s" % (fp_rel, node.lineno)
+ messages.setdefault(eval_str, []).append(msgsrc)
+ return
+ for nd in ast.iter_child_nodes(node):
+ if type(nd) not in stopper_nodes:
+ extract_strings(fp_rel, nd)
+
def extract_strings_from_file(fp):
filedata = open(fp, 'r', encoding="utf8")
root_node = ast.parse(filedata.read(), fp, 'exec')
More information about the Bf-translations-svn
mailing list