1

我的 Jinja2 模板之一中有一个可翻译的字符串:

Project can’t end sooner than it starts

(注意“不能”中的 UTF-8 撇号。)

当我提取消息并更新我的翻译文件时,模板 ( .pot) 和翻译 ( .po) 文件都具有以下内容msgid

msgid "Project canât end sooner than it starts"

Babel 似乎“翻译”了 UTF-8 字符,就好像它们在某种 8 位字符集中一样。

babel.cfg的很短:

[python: **.py]
[jinja2: **/templates/**.html]
extensions=jinja2.ext.autoescape,jinja2.ext.with_,webassets.ext.jinja2.AssetsExtension

Babel 有没有办法注意到模板已经在 UTF-8 中,而不是从它认为的任何字符集转换它?pybabel extract --help我在nor的帮助输出中看不到任何相关选项pybabel extract --help

为了记录,我专门使用 Python3。

4

1 回答 1

2

事实证明它是开箱即用的,它似乎没有记录。我所要做的就是更改配置:

[python: **.py]
[jinja2: **/templates/**.html]
encoding=utf-8
extensions=jinja2.ext.autoescape,jinja2.ext.with_,webassets.ext.jinja2.AssetsExtension

encoding=utf-8部分发挥了作用,所有 HTML 文件现在都被视为 UTF-8 数据。

于 2017-06-22T15:13:57.260 回答