Commit efb9e9d5 authored by Yusei Tahara's avatar Yusei Tahara

2007-08-14 Yusei

* Add utility scripts to collect translation messages.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@15668 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 5401cfd5
import compiler
import compiler.ast
import compiler.visitor
class Visitor(compiler.visitor.ASTVisitor):
def __init__(self, func_name):
self.func_name = func_name
compiler.visitor.ASTVisitor.__init__(self)
self.result = []
def visitCallFunc(self, node, *args):
if (isinstance(node.node, compiler.ast.Name) and
node.node.name==self.func_name):
arg = node.args[0]
value = None
if isinstance(arg, compiler.ast.Const):
value = arg.value
elif isinstance(arg, compiler.ast.Add):
value = concatenate_add_const_value(arg)
if value is not None:
self.result.append(value)
def concatenate_add_const_value(node):
def iterate(nodes):
if not nodes:
return ''
node = nodes[0]
if isinstance(node, compiler.ast.Const):
return node.value + iterate(nodes[1:])
elif isinstance(node, compiler.ast.Add):
if getattr(node, 'nodes', None):
children_nodes = node.nodes
else:
children_nodes = (node.left, node.right)
return iterate(children_nodes)+iterate(nodes[1:])
elif isinstance(node, compiler.ast.Mod):
# we can't handle Mod node statically.
pass
return iterate((node,))
def getFunctionFirstArgumentValue(func_name, source):
ast = compiler.parse(source)
visitor = Visitor(func_name)
compiler.walk(ast, visitor)
return visitor.result
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>Products.ExternalMethod.ExternalMethod</string>
<string>ExternalMethod</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_function</string> </key>
<value> <string>getFunctionFirstArgumentValue</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>PythonScriptParserUtility</string> </value>
</item>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getFunctionFirstArgumentValue</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>Products.PythonScripts.PythonScript</string>
<string>PythonScript</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Python_magic</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>items = []\n
def iterate(obj):\n
for i in obj.objectValues():\n
if i.isPrincipiaFolderish:\n
iterate(i)\n
elif i.meta_type==\'Script (Python)\':\n
items.append(i)\n
\n
iterate(context.portal_skins)\n
\n
FUNC_NAME = \'N_\'\n
CALL_FUNC_NAME = \'%s(\' % FUNC_NAME\n
\n
result = {}\n
for i in items:\n
source = i.body()\n
if CALL_FUNC_NAME in source:\n
for m in context.Base_getFunctionFirstArgumentValue(FUNC_NAME, source):\n
result[m] = None\n
\n
for i in result:\n
print \'msgid "%s"\' % repr(i)[1:-1]\n
print \'msgstr ""\'\n
print\n
return printed\n
</string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_filepath</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>errors</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>func_code</string> </key>
<value>
<object>
<klass>
<global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>_print_</string>
<string>_print</string>
<string>items</string>
<string>iterate</string>
<string>_getattr_</string>
<string>context</string>
<string>FUNC_NAME</string>
<string>CALL_FUNC_NAME</string>
<string>result</string>
<string>_getiter_</string>
<string>i</string>
<string>source</string>
<string>m</string>
<string>None</string>
<string>_write_</string>
<string>_getitem_</string>
<string>repr</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_getToBeTranslatedMessageListFromPythonScriptListAsPot</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>Products.PythonScripts.PythonScript</string>
<string>PythonScript</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Python_magic</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>messages = {}\n
\n
def memo(o, t):\n
return \'%s:::%s\' % (t, o.aq_parent.aq_parent.id)\n
\n
\n
for i in context.portal_workflow.objectValues():\n
if not i.states:\n
continue\n
for s in i.states.values():\n
if s.title:\n
messages[s.title] = None\n
\n
if not i.transitions:\n
continue\n
for t in i.transitions.values():\n
if t.actbox_name:\n
messages[t.actbox_name] = None\n
\n
for i in messages.keys():\n
print \'msgid "%s"\' % i\n
print \'msgstr ""\'\n
print\n
\n
return printed\n
</string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_filepath</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>errors</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>func_code</string> </key>
<value>
<object>
<klass>
<global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>_print_</string>
<string>_print</string>
<string>messages</string>
<string>memo</string>
<string>_getiter_</string>
<string>_getattr_</string>
<string>context</string>
<string>i</string>
<string>s</string>
<string>None</string>
<string>_write_</string>
<string>t</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_getToBeTranslatedMessageListFromWorkflowListAsPot</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
2007-08-14 Yusei
* Add utility scripts to collect translation messages.
2007-08-14 Yusei 2007-08-14 Yusei
* Add glossary module. * Add glossary module.
......
153 158
\ No newline at end of file \ No newline at end of file
Glossary Glossary
PythonScriptParserUtility
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment