0

我被xgettextHTML 模板中缺少的标签属性所困扰,例如:

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

返回

# 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 ""

whereatitle属性被跳过。

FWIW,模板语言是 PythonbottleSimpleTemplate Engine,与标准不兼容pybabel

(说实话,你会得到相同的结果——即标记属性被忽略——使用pybabel的 javascript 提取器,我宁愿将其与以下内容一起使用babel.cfg

[python: **/**.py]
[javascript: views/**.html]

我做过的其他尝试:使用与 SimpleTemplate Engine 的模板继承语法不兼容的 Jinja2 提取器{{!base}}

4

1 回答 1

0

我最终破解了jinja2.Environment初始化,因此将该{{!base}}命令视为注释。

[python: **/**.py]
[jinja2: views/**.html]
comment_start_string = {{!
comment_end_string = }}
silent=False

这样它就不会在转义的打印中找到任何翻译 - 这{{! ... }}就是 SimpleTemplate Engine 中的用途,应该是您想要转义翻译文本的罕见情况。

还有python中的翻译%并且<% ... %>以某种方式被跳过,我还没有找到修复程序。

于 2021-10-22T07:45:34.540 回答