Commit b3b83622 authored by Yusei Tahara's avatar Yusei Tahara

Support message id extraction from page template.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@19436 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent eb6cb53f
......@@ -27,3 +27,60 @@ def getActionTitleListFromAllActionProvider(portal):
for action in provider.listActions():
result[action.title] = None
return result.keys()
from StringIO import StringIO
from TAL.HTMLTALParser import HTMLTALParser
def findStaticTranslationText(page_template):
def iterate(node, target_name, function):
if type(node) is list:
for i in node:
iterate(i, target_name, function)
elif type(node) is tuple and node:
if node[0]==target_name:
function(node)
else:
for i in node[1:]:
iterate(i, target_name, function)
text_dict = {}
def addText(node):
if len(node)!=2:
node = (node[0], node[1:])
program = [node]
macros = {}
engine = MyDummyEngine(macros)
output = StringIO()
interpreter = MyDummyTALInterpreter(program, macros, engine, output)
interpreter()
if interpreter._i18n_message_id_dict is not None:
text_dict.update(interpreter._i18n_message_id_dict)
parser = HTMLTALParser()
parser.parseString(page_template._text)
iterate(parser.gen.program, 'insertTranslation', addText)
return text_dict.keys()
#
# Utility class for findStaticTranslationText
#
from TAL.TALInterpreter import TALInterpreter
from TAL.DummyEngine import DummyEngine
class MyDummyEngine(DummyEngine):
def evaluate(self, expression):
return None
class MyDummyTALInterpreter(TALInterpreter):
_i18n_message_id_dict = None
_currentTag = None
def translate(self, msgid, default, i18ndict, obj):
try:
self._i18n_message_id_dict[msgid] = None
except TypeError:
self._i18n_message_id_dict = {msgid:None}
return TALInterpreter.translate(self, msgid, default, i18ndict, obj)
<?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>findStaticTranslationText</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>Glossary</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_findStaticTranslationText</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -83,7 +83,7 @@ portal_url = context.portal_url\n
python_script_list = []\n
form_list = []\n
listbox_list = []\n
zpt_list = []\n
page_template_list = []\n
def iterate(obj):\n
for i in obj.objectValues():\n
if i.meta_type==\'Script (Python)\':\n
......@@ -92,8 +92,8 @@ 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\':\n
zpt_list.append(i)\n
elif i.meta_type==\'Page Template\' and i.content_type.startswith(\'text/html\'):\n
page_template_list.append(i)\n
if i.isPrincipiaFolderish:\n
iterate(i)\n
iterate(context.portal_skins)\n
......@@ -107,12 +107,13 @@ FUNC_NAME_LIST = (\'N_\',\n
\'translateString\',\n
)\n
\n
Base_getFunctionFirstArgumentValue = context.Base_getFunctionFirstArgumentValue\n
for i in python_script_list:\n
source = i.body()\n
for func_name in FUNC_NAME_LIST:\n
call_func_name = \'%s(\' % func_name\n
if call_func_name in source:\n
for m in context.Base_getFunctionFirstArgumentValue(func_name, source):\n
for m in Base_getFunctionFirstArgumentValue(func_name, source):\n
add_message(m, portal_url.getRelativeContentURL(i))\n
\n
\n
......@@ -134,9 +135,12 @@ for i in listbox_list:\n
add_message(label, portal_url.getRelativeContentURL(i))\n
\n
#\n
# ZPT\n
# Page Template\n
#\n
# TODO : To parse html and get static translated text.\n
Base_findStaticTranslationText = context.Base_findStaticTranslationText\n
for i in page_template_list:\n
for m in Base_findStaticTranslationText(i):\n
add_message(m, portal_url.getRelativeContentURL(i))\n
\n
#\n
# Workflow\n
......@@ -254,9 +258,10 @@ return printed\n
<string>python_script_list</string>
<string>form_list</string>
<string>listbox_list</string>
<string>zpt_list</string>
<string>page_template_list</string>
<string>iterate</string>
<string>FUNC_NAME_LIST</string>
<string>Base_getFunctionFirstArgumentValue</string>
<string>_getiter_</string>
<string>i</string>
<string>source</string>
......@@ -265,6 +270,7 @@ return printed\n
<string>m</string>
<string>value</string>
<string>label</string>
<string>Base_findStaticTranslationText</string>
<string>s</string>
<string>t</string>
<string>action_title</string>
......
206
\ No newline at end of file
208
\ 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