具有标签而非<动态元素>的POT文件

2024-09-29 02:29:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试从金字塔项目的模板文件中翻译文本。或多或少如本例所示:http://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/chameleon_i18n.html

现在如何删除.pot文件注释中的<dynamic element>?我想看看代码的其余部分及其标记。在

我的变色龙模板(.pt):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:tal="http://xml.zope.org/namespaces/tal"
  xmlns:i18n="http://xml.zope.org/namespaces/i18n"
  i18n:domain="MyDomain">
<head>
    ...
</head>
<body>
    <div i18n:translate="MyID">
        This will appear in the comments.
        <span>This will NOT.</span>
        While this will again appear.
    </div>
</body>
</html>

我使用Babel和Lingua从我的设置.py公司名称:

^{pr2}$

我的.pot文件中的相关输出如下所示:

#. Default: This will appear in the comments. <dynamic element> While this will
#. again appear.
#: myproject/templates/base.pt:10
msgid "MyID"
msgstr ""

Tags: 文件org模板httphtmldynamicxmlelement
1条回答
网友
1楼 · 发布于 2024-09-29 02:29:25

这是明确不支持的:翻译应该只包含文本-它不应该包含标记。否则你会有两个问题:

  1. 翻译程序可能会插入标记,这可能会破坏您的网站或造成安全问题
  2. 模板工具箱无法确定翻译中是否有字符 需要转义或应按原样输出。在

通常需要翻译包含动态组件或标记的项:对于那些使用i18n:name属性的项。例如,您可以这样做:

<p i18n:translate="">This is <strong i18n:name="very" i18n:translate="">very</strong> important.

这将给您两个要翻译的字符串:This is ${very} string和{}。在

相关问题 更多 >