From 7271d04e72aca36497f5cc04c5083c7c835cc6ca Mon Sep 17 00:00:00 2001 From: emkael Date: Mon, 31 Oct 2016 21:58:54 +0100 Subject: * adding PHPTAL i18n template tags to locale cache --- bin/prado-locales-build | 2 +- bin/tpl2c.py | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/bin/prado-locales-build b/bin/prado-locales-build index 10ffc0c..8a75f8f 100755 --- a/bin/prado-locales-build +++ b/bin/prado-locales-build @@ -2,7 +2,7 @@ pushd $(realpath $(dirname $0)/..) > /dev/null mkdir -p cache/gettext OUTPUT=$(realpath cache/gettext) -find app/frontend -name \*.page -o -name \*.tpl | while read FILE; do +find app/frontend -name \*.page -o -name \*.tpl -o -name \*.html | while read FILE; do tpl2c.py $FILE $OUTPUT done diff --git a/bin/tpl2c.py b/bin/tpl2c.py index 4fa3eb9..248cdf3 100755 --- a/bin/tpl2c.py +++ b/bin/tpl2c.py @@ -1,6 +1,6 @@ #!/usr/bin/env python2.7 import sys, os, re, json -from lxml import etree +from lxml import etree, html import lxml.html.soupparser as soupparser BASEPATH = os.path.realpath(os.path.join(os.path.dirname(sys.argv[0]), '..')) @@ -12,7 +12,9 @@ FILEPATH = INPUTPATH[len(BASEPATH):].lstrip('/') OUTPUTPATH = os.path.join(sys.argv[2], FILEPATH[0:FILEPATH.rfind('.')] + '.c') namespaces = {'com': 'https://github.com/pradosoft/prado/com', - 'prop': 'https://github.com/pradosoft/prado/prop'} + 'prop': 'https://github.com/pradosoft/prado/prop', + 'i18n': 'http://xml.zope.org/namespaces/i18n', + 'tal': 'http://xml.zope.org/namespaces/tal'} prado_tag_regex = re.compile('<%.*%>') @@ -64,6 +66,29 @@ for ttranslate in xml_content.xpath('//com:TTranslate', namespaces=namespaces): tokens[linelabel] = [] tokens[linelabel].append(token) +for taltag in xml_content.xpath('//*[@i18n:translate]', namespaces=namespaces): + attrib = taltag.attrib['{%s}%s' % (namespaces['i18n'], 'translate')] + if attrib.startswith('string:'): + token = attrib[len('string:'):] + else: + for variable in taltag.xpath('//*[@i18n:name]', namespaces=namespaces): + var_name = variable.attrib['{%s}%s' % (namespaces['i18n'], 'name')] + variable.tail = ('{%s}' % (var_name)) + (variable.tail or '') + parent = variable.getparent() + prev = variable.getprevious() + if prev is not None: + prev.tail = (prev.tail or '') + variable.tail + else: + parent.text = (parent.text or '') + variable.tail + parent.remove(variable) + token = taltag.text.strip() + print token + linelabel = str(taltag.sourceline-1) + if linelabel not in tokens: + tokens[linelabel] = [] + tokens[linelabel].append(token) + + if len(tokens): OUTPUTDIR = os.path.dirname(OUTPUTPATH) if not os.path.exists(OUTPUTDIR): -- cgit v1.2.3