Commit d2ee0103 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@23200 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7d2387b8
...@@ -34,7 +34,8 @@ from StringIO import StringIO ...@@ -34,7 +34,8 @@ from StringIO import StringIO
from TAL.HTMLTALParser import HTMLTALParser from TAL.HTMLTALParser import HTMLTALParser
from TAL.TALParser import TALParser from TAL.TALParser import TALParser
from TAL.TALGenerator import TALGenerator 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): def iterate(node, target_name, function):
if type(node) is list: if type(node) is list:
for i in node: for i in node:
...@@ -59,6 +60,23 @@ def findStaticTranslationText(page_template): ...@@ -59,6 +60,23 @@ def findStaticTranslationText(page_template):
if interpreter._i18n_message_id_dict is not None: if interpreter._i18n_message_id_dict is not None:
text_dict.update(interpreter._i18n_message_id_dict) 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(): if page_template.html():
generator = TALGenerator(xml=0) generator = TALGenerator(xml=0)
parser = HTMLTALParser(generator) parser = HTMLTALParser(generator)
...@@ -67,6 +85,7 @@ def findStaticTranslationText(page_template): ...@@ -67,6 +85,7 @@ def findStaticTranslationText(page_template):
parser = TALParser(generator) parser = TALParser(generator)
parser.parseString(page_template._text) parser.parseString(page_template._text)
iterate(parser.gen.program, 'insertTranslation', addText) iterate(parser.gen.program, 'insertTranslation', addText)
iterate(parser.gen.program, 'insertText', addTextFromPythonExpression)
return text_dict.keys() return text_dict.keys()
# #
...@@ -74,12 +93,12 @@ def findStaticTranslationText(page_template): ...@@ -74,12 +93,12 @@ def findStaticTranslationText(page_template):
# #
from TAL.TALInterpreter import TALInterpreter from TAL.TALInterpreter import TALInterpreter
from TAL.DummyEngine import DummyEngine from TAL.DummyEngine import DummyEngine
class MyDummyEngine(DummyEngine): class MyDummyEngine(DummyEngine):
def evaluate(self, expression): def evaluate(self, expression):
return None return None
class MyDummyTALInterpreter(TALInterpreter): class MyDummyTALInterpreter(TALInterpreter):
_i18n_message_id_dict = None _i18n_message_id_dict = None
......
...@@ -11,8 +11,12 @@ class Visitor(compiler.visitor.ASTVisitor): ...@@ -11,8 +11,12 @@ class Visitor(compiler.visitor.ASTVisitor):
self.result = [] self.result = []
def visitCallFunc(self, node, *args): def visitCallFunc(self, node, *args):
if (isinstance(node.node, compiler.ast.Name) and if ((isinstance(node.node, compiler.ast.Name) and
node.node.name==self.func_name): node.node.name==self.func_name)
or
(isinstance(node.node, compiler.ast.Getattr) and
node.node.attrname==self.func_name)
):
arg = node.args[0] arg = node.args[0]
value = None value = None
if isinstance(arg, compiler.ast.Const): if isinstance(arg, compiler.ast.Const):
......
...@@ -151,7 +151,7 @@ for i in listbox_list:\n ...@@ -151,7 +151,7 @@ for i in listbox_list:\n
#\n #\n
Base_findStaticTranslationText = context.Base_findStaticTranslationText\n Base_findStaticTranslationText = context.Base_findStaticTranslationText\n
for i in page_template_list:\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 add_message(m, portal_url.getRelativeContentURL(i))\n
\n \n
#\n #\n
......
321 323
\ No newline at end of file \ 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