Commit 31c716d9 authored by Yusei Tahara's avatar Yusei Tahara

2008-08-27 yusei

* Improve pot file export.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@23197 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 191f84bd
......@@ -11,7 +11,7 @@ def getPropertySheetAttributeList(name):
def getActionTitleListFromAllActionProvider(portal):
result = {}
result = []
provider_list = []
for provider_id in portal.portal_actions.listActionProviders():
if provider_id in ('portal_types', 'portal_workflow'):
......@@ -24,13 +24,16 @@ def getActionTitleListFromAllActionProvider(portal):
for typeinfo in portal.portal_types.objectValues():
provider_list.append(typeinfo)
for provider in provider_list:
for action in provider.listActions():
result[action.title] = None
return result.keys()
result.append((action.title, provider.getId()))
return result
from StringIO import StringIO
from TAL.HTMLTALParser import HTMLTALParser
from TAL.TALParser import TALParser
from TAL.TALGenerator import TALGenerator
def findStaticTranslationText(page_template):
def iterate(node, target_name, function):
if type(node) is list:
......@@ -56,7 +59,12 @@ def findStaticTranslationText(page_template):
if interpreter._i18n_message_id_dict is not None:
text_dict.update(interpreter._i18n_message_id_dict)
parser = HTMLTALParser()
if page_template.html():
generator = TALGenerator(xml=0)
parser = HTMLTALParser(generator)
else:
generator = TALGenerator(xml=1)
parser = TALParser(generator)
parser.parseString(page_template._text)
iterate(parser.gen.program, 'insertTranslation', addText)
return text_dict.keys()
......@@ -92,4 +100,3 @@ def setGuard(self, guard):
self.guard = guard
else:
raise ValueError, "not a TransitionDefinition"
......@@ -21,6 +21,8 @@ class Visitor(compiler.visitor.ASTVisitor):
value = concatenate_add_const_value(arg)
if value is not None:
self.result.append(value)
for child_node in node.args:
self.preorder(child_node, self)
def concatenate_add_const_value(node):
......@@ -47,3 +49,34 @@ def getFunctionFirstArgumentValue(func_name, source):
visitor = Visitor(func_name)
compiler.walk(ast, visitor)
return visitor.result
#
# Collect translation message from products
#
import os.path
import Products.ERP5
def findMessageListFromPythonInProduct(function_name_list):
product_dir = os.path.dirname(Products.ERP5.__path__[0])
erp5_product_list = ('CMFActivity', 'CMFCategory',
'ERP5', 'ERP5Banking', 'ERP5Catalog', 'ERP5Configurator',
'ERP5Form', 'ERP5OOo', 'ERP5Security', 'ERP5Subversion',
'ERP5SyncML', 'ERP5Type', 'ERP5Wizard', 'ERP5Workflow',
'HBTreeFolder2', 'MailTemplates', 'TimerService',
'ZMySQLDA', 'ZMySQLDDA', 'ZSQLCatalog',
)
result = []
def findStaticMessage(file_path):
source = open(file_path).read()
for func_name in function_name_list:
call_func_name = '%s(' % func_name
if call_func_name in source:
for m in getFunctionFirstArgumentValue(func_name, source):
result.append((m, file_path))
def visit(arg, dirname, filename_list):
for filename in filename_list:
if filename.endswith('.py'):
findStaticMessage(os.path.join(dirname, filename))
for product_name in erp5_product_list:
os.path.walk(os.path.join(product_dir, product_name), visit, None)
return result
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_function</string> </key>
<value> <string>findMessageListFromPythonInProduct</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>PythonScriptParserUtility</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_findMessageListFromPythonInProduct</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -92,12 +92,19 @@ def iterate(obj):\n
form_list.append(i)\n
elif i.meta_type==\'ListBox\' or i.id==\'listbox\':\n
listbox_list.append(i)\n
elif i.meta_type==\'Page Template\' and i.content_type.startswith(\'text/html\'):\n
elif i.meta_type in (\'Page Template\',\n
\'ERP5 PDF Template\',\n
\'ERP5 OOo Template\'):\n
page_template_list.append(i)\n
if i.isPrincipiaFolderish:\n
iterate(i)\n
iterate(context.portal_skins)\n
\n
# Collect python script from workflow objects.\n
for workflow in context.portal_workflow.objectValues():\n
for i in workflow.scripts.objectValues():\n
if i.meta_type==\'Script (Python)\':\n
python_script_list.append(i)\n
\n
#\n
# Python Script\n
......@@ -116,6 +123,11 @@ for i in python_script_list:\n
for m in Base_getFunctionFirstArgumentValue(func_name, source):\n
add_message(m, portal_url.getRelativeContentURL(i))\n
\n
#\n
# Python in Products\n
#\n
for message, path in context.Base_findMessageListFromPythonInProduct(FUNC_NAME_LIST):\n
add_message(message, path)\n
\n
#\n
# ERP5 Form title\n
......@@ -129,9 +141,9 @@ for i in form_list:\n
#\n
for i in listbox_list:\n
add_message(i.title(), portal_url.getRelativeContentURL(i))\n
for value, label in i.get_value(\'columns\'):\n
for value, label in i.get_value(\'columns\') or ():\n
add_message(label, portal_url.getRelativeContentURL(i))\n
for value, label in i.get_value(\'all_columns\'):\n
for value, label in i.get_value(\'all_columns\') or ():\n
add_message(label, portal_url.getRelativeContentURL(i))\n
\n
#\n
......@@ -146,6 +158,7 @@ for i in page_template_list:\n
# Workflow\n
#\n
for i in context.portal_workflow.objectValues():\n
add_message(i.title_or_id(), portal_url.getRelativeContentURL(i))\n
if not i.states:\n
continue\n
for s in i.states.values():\n
......@@ -157,6 +170,8 @@ for i in context.portal_workflow.objectValues():\n
for t in i.transitions.values():\n
if t.actbox_name:\n
add_message(t.actbox_name, portal_url.getRelativeContentURL(t))\n
for worklist in i.worklists.objectValues():\n
add_message(worklist.actbox_name, portal_url.getRelativeContentURL(worklist))\n
\n
\n
#\n
......@@ -169,8 +184,8 @@ for i in context.portal_types.objectValues():\n
#\n
# Action\n
#\n
for action_title in context.Base_getActionTitleListFromAllActionProvider(context.getPortalObject()):\n
add_message(action_title, \'action\')\n
for action_title, action_provider_id in context.Base_getActionTitleListFromAllActionProvider(context.getPortalObject()):\n
add_message(action_title, action_provider_id)\n
\n
\n
#\n
......@@ -262,24 +277,28 @@ return printed\n
<string>listbox_list</string>
<string>page_template_list</string>
<string>iterate</string>
<string>FUNC_NAME_LIST</string>
<string>Base_getFunctionFirstArgumentValue</string>
<string>_getiter_</string>
<string>workflow</string>
<string>i</string>
<string>FUNC_NAME_LIST</string>
<string>Base_getFunctionFirstArgumentValue</string>
<string>source</string>
<string>func_name</string>
<string>call_func_name</string>
<string>m</string>
<string>message</string>
<string>path</string>
<string>value</string>
<string>label</string>
<string>Base_findStaticTranslationText</string>
<string>s</string>
<string>t</string>
<string>worklist</string>
<string>action_title</string>
<string>action_provider_id</string>
<string>format</string>
<string>MESSAGE_TEMPLATE</string>
<string>message_list</string>
<string>message</string>
<string>_getitem_</string>
<string>comment_list</string>
<string>append</string>
......@@ -304,6 +323,12 @@ return printed\n
<key> <string>id</string> </key>
<value> <string>ERP5Site_getToBeTranslatedMessageListFromEntireSystemAsPot</string> </value>
</item>
<item>
<key> <string>uid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
......
2008-08-27 yusei
* Improve pot file export.
2008-06-16 Nicolas
Add external Method to see Security for arbitrary user
......
320
\ No newline at end of file
321
\ 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