[Erp5-report] r19436 - in /erp5/trunk/bt5/erp5_forge: ExtensionTemplateItem/ SkinTemplateIt...
nobody at svn.erp5.org
nobody at svn.erp5.org
Wed Feb 20 15:31:45 CET 2008
Author: yusei
Date: Wed Feb 20 15:31:44 2008
New Revision: 19436
URL: http://svn.erp5.org?rev=19436&view=rev
Log:
Support message id extraction from page template.
Added:
erp5/trunk/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/Base_findStaticTranslationText.xml
erp5/trunk/bt5/erp5_forge/bt/template_catalog_local_role_key_list
erp5/trunk/bt5/erp5_forge/bt/template_catalog_role_key_list
Modified:
erp5/trunk/bt5/erp5_forge/ExtensionTemplateItem/Glossary.py
erp5/trunk/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/ERP5Site_getToBeTranslatedMessageListFromEntireSystemAsPot.xml
erp5/trunk/bt5/erp5_forge/bt/revision
Modified: erp5/trunk/bt5/erp5_forge/ExtensionTemplateItem/Glossary.py
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_forge/ExtensionTemplateItem/Glossary.py?rev=19436&r1=19435&r2=19436&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_forge/ExtensionTemplateItem/Glossary.py (original)
+++ erp5/trunk/bt5/erp5_forge/ExtensionTemplateItem/Glossary.py Wed Feb 20 15:31:44 2008
@@ -27,3 +27,60 @@
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)
Added: erp5/trunk/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/Base_findStaticTranslationText.xml
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/Base_findStaticTranslationText.xml?rev=19436&view=auto
==============================================================================
--- erp5/trunk/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/Base_findStaticTranslationText.xml (added)
+++ erp5/trunk/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/Base_findStaticTranslationText.xml Wed Feb 20 15:31:44 2008
@@ -1,0 +1,37 @@
+<?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>
Modified: erp5/trunk/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/ERP5Site_getToBeTranslatedMessageListFromEntireSystemAsPot.xml
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/ERP5Site_getToBeTranslatedMessageListFromEntireSystemAsPot.xml?rev=19436&r1=19435&r2=19436&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/ERP5Site_getToBeTranslatedMessageListFromEntireSystemAsPot.xml (original)
+++ erp5/trunk/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/ERP5Site_getToBeTranslatedMessageListFromEntireSystemAsPot.xml Wed Feb 20 15:31:44 2008
@@ -83,7 +83,7 @@
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 @@
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 @@
\'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 @@
add_message(label, portal_url.getRelativeContentURL(i))\n
\n
#\n
-# ZPT\n
-#\n
-# TODO : To parse html and get static translated text.\n
+# Page Template\n
+#\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 @@
<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 @@
<string>m</string>
<string>value</string>
<string>label</string>
+ <string>Base_findStaticTranslationText</string>
<string>s</string>
<string>t</string>
<string>action_title</string>
Modified: erp5/trunk/bt5/erp5_forge/bt/revision
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_forge/bt/revision?rev=19436&r1=19435&r2=19436&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_forge/bt/revision (original)
+++ erp5/trunk/bt5/erp5_forge/bt/revision Wed Feb 20 15:31:44 2008
@@ -1,1 +1,1 @@
-206
+208
Added: erp5/trunk/bt5/erp5_forge/bt/template_catalog_local_role_key_list
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_forge/bt/template_catalog_local_role_key_list?rev=19436&view=auto
==============================================================================
(empty)
Added: erp5/trunk/bt5/erp5_forge/bt/template_catalog_role_key_list
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_forge/bt/template_catalog_role_key_list?rev=19436&view=auto
==============================================================================
(empty)
More information about the Erp5-report
mailing list