I'm stuck with xgettext
missing tag attributes in HTML templates, eg:
xgettext --keyword=_ --language=Python -o - - <<EOF
<!DOCTYPE html>
<html>
<head>
% msg = _('A translatable string')
<title>{{ _('Page title') }}</title>
</head>
<body>
<a href="#" title="{{ _('title') }}">_('Link text')</a>
</body>
</html>
EOF
returns
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-10-20 11:52+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: standard input:4
msgid "A translatable string"
msgstr ""
#: standard input:5
msgid "Page title"
msgstr ""
#: standard input:8
msgid "Link text"
msgstr ""
where a
's title
attribute is skipped.
FWIW, the template language is Python bottle
's SimpleTemplate Engine which is incompatible with standard pybabel
.
(To tell the truth you'll get the same result -- ie tag attributes ignored -- using pybabel
's javascript extractor, which I would rather use with the following babel.cfg
)
[python: **/**.py]
[javascript: views/**.html]
Other tentative I did: use Jinja2 extractors which are incompatible with SimpleTemplate Engine's template inheritance syntax {{!base}}
I ended up hacking jinja2.Environment
initialization so to consider the {{!base}}
command a comment.
[python: **/**.py]
[jinja2: views/**.html]
comment_start_string = {{!
comment_end_string = }}
silent=False
This way it won't find any translations in escaped prints — that's what {{! ... }}
{{! ... }}
is for in SimpleTemplate Engine, should be a rare case you want to escape a translation text.
Also translations in python %
and <% ... %>
are somehow skipped, I haven't found a fix yet.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.