From d2ee01037118dc822969ccf38eca0e5dd889d1d2 Mon Sep 17 00:00:00 2001 From: Yusei Tahara <yusei@nexedi.com> Date: Wed, 27 Aug 2008 14:41:44 +0000 Subject: [PATCH] 2008-08-27 yusei * Improve pot file export. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@23200 20353a03-c40f-0410-a6d1-a30d3c3de9de --- .../ExtensionTemplateItem/Glossary.py | 25 ++++++++++++++++--- .../PythonScriptParserUtility.py | 8 ++++-- ...slatedMessageListFromEntireSystemAsPot.xml | 2 +- bt5/erp5_forge/bt/revision | 2 +- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/bt5/erp5_forge/ExtensionTemplateItem/Glossary.py b/bt5/erp5_forge/ExtensionTemplateItem/Glossary.py index 0bf2952af9..c4ed3a85b7 100644 --- a/bt5/erp5_forge/ExtensionTemplateItem/Glossary.py +++ b/bt5/erp5_forge/ExtensionTemplateItem/Glossary.py @@ -34,7 +34,8 @@ from StringIO import StringIO from TAL.HTMLTALParser import HTMLTALParser from TAL.TALParser import TALParser from TAL.TALGenerator import TALGenerator -def findStaticTranslationText(page_template): +from TAL.DummyEngine import name_match +def findStaticTranslationText(page_template, func_name_list): def iterate(node, target_name, function): if type(node) is list: for i in node: @@ -59,6 +60,23 @@ def findStaticTranslationText(page_template): if interpreter._i18n_message_id_dict is not None: text_dict.update(interpreter._i18n_message_id_dict) + def addTextFromPythonExpression(node): + tal_expression = node[1] + if isinstance(tal_expression, (tuple, list)): + tal_expression = tal_expression[0] + tal_expression = tal_expression[1:-1] + match = name_match(tal_expression) + if match: + type, expression = match.group(1, 2) + if type=='python': + # clean up expression + expression = expression.strip() + expression = expression.replace('\n', ' ') + Base_getFunctionFirstArgumentValue = page_template.Base_getFunctionFirstArgumentValue + for func_name in func_name_list: + for message in Base_getFunctionFirstArgumentValue(func_name, expression): + text_dict[message] = None + if page_template.html(): generator = TALGenerator(xml=0) parser = HTMLTALParser(generator) @@ -67,6 +85,7 @@ def findStaticTranslationText(page_template): parser = TALParser(generator) parser.parseString(page_template._text) iterate(parser.gen.program, 'insertTranslation', addText) + iterate(parser.gen.program, 'insertText', addTextFromPythonExpression) return text_dict.keys() # @@ -74,12 +93,12 @@ def findStaticTranslationText(page_template): # 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 diff --git a/bt5/erp5_forge/ExtensionTemplateItem/PythonScriptParserUtility.py b/bt5/erp5_forge/ExtensionTemplateItem/PythonScriptParserUtility.py index 91fb556217..3aa34686f2 100644 --- a/bt5/erp5_forge/ExtensionTemplateItem/PythonScriptParserUtility.py +++ b/bt5/erp5_forge/ExtensionTemplateItem/PythonScriptParserUtility.py @@ -11,8 +11,12 @@ class Visitor(compiler.visitor.ASTVisitor): self.result = [] def visitCallFunc(self, node, *args): - if (isinstance(node.node, compiler.ast.Name) and - node.node.name==self.func_name): + if ((isinstance(node.node, compiler.ast.Name) and + node.node.name==self.func_name) + or + (isinstance(node.node, compiler.ast.Getattr) and + node.node.attrname==self.func_name) + ): arg = node.args[0] value = None if isinstance(arg, compiler.ast.Const): diff --git a/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/ERP5Site_getToBeTranslatedMessageListFromEntireSystemAsPot.xml b/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/ERP5Site_getToBeTranslatedMessageListFromEntireSystemAsPot.xml index fb47a422b2..f9c11595f1 100644 --- a/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/ERP5Site_getToBeTranslatedMessageListFromEntireSystemAsPot.xml +++ b/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/ERP5Site_getToBeTranslatedMessageListFromEntireSystemAsPot.xml @@ -151,7 +151,7 @@ for i in listbox_list:\n #\n Base_findStaticTranslationText = context.Base_findStaticTranslationText\n for i in page_template_list:\n - for m in Base_findStaticTranslationText(i):\n + for m in Base_findStaticTranslationText(i, FUNC_NAME_LIST):\n add_message(m, portal_url.getRelativeContentURL(i))\n \n #\n diff --git a/bt5/erp5_forge/bt/revision b/bt5/erp5_forge/bt/revision index 9d239ff807..871cae9aa6 100644 --- a/bt5/erp5_forge/bt/revision +++ b/bt5/erp5_forge/bt/revision @@ -1 +1 @@ -321 \ No newline at end of file +323 \ No newline at end of file -- 2.30.9