使用基于 Python 的 Babel gettext 实用程序,是否有任何技术可以保留译者注释和旧的(“过时的”) ) 跨 .pot
文件更新的 .po
文件中的翻译(用 #~
标记)?
过时的翻译第一次位于 .po
文件中,并且 pybabel update
运行时,翻译会被标记为 #~
。这样一来,一方面,它被视为注释,直到译者检查并更改它后才使用,但另一方面,它不会被删除,因此译者可以参考它,或复制文本从它到他们的其他翻译。
但是,下次运行 pybabel update 时,所有注释都会从文件中永久删除。这意味着那些标有 #~
的翻译也会被删除。
例如,使用 Babel 版本 0.9.6 和 Jinja2 版本 2.6 以及以下文件:
<代码>./babel.ini:
[jinja2: **/templates/**.html]
encoding = utf-8
./templates/test.html
:./i18n/pt_PT/
<html><body>
<h1>{% trans %}My website{% endtrans %}</h1>
</body></html>
LC_MESSAGES/messages.po:
# ... header stuff generated from
# pybabel init -l pt_PT -d i18n -i i18n/messages.pot ...
# Don't forget, I want to remember something about this!
#~ msgid "My web page"
#~ msgstr "A minha página de web"
运行以下命令后:
$ pybabel extract -F babel.ini -o i18n/messages.pot .
$ pybabel update -l pt_PT -d i18n -i i18n/messages.pot
葡萄牙语 messages.po
文件将丢失所有旧注释,仅包含:
./i18n/pt_PT/LC_MESSAGES/messages.po
:
# ... similar header stuff ...
#: templates/test.html:2
msgid "My web site"
msgstr ""
如何更新我的翻译文件而不丢失我的评论和旧翻译?
With the Python-based Babel gettext utilities, are there any techniques to preserve translator comments and old ("obsolete") translations (marked with #~
) in .po
files across updates from the .pot
file?
The first time an obsolete translation is in a .po
file, and pybabel update
is run, the translation is marked with #~
. This is so that on the one hand, it is treated as a comment and not used until a translator looks it over and changes it, yet on the other hand, it is not removed, so a translator can refer to it, or copy text from it into their other translations.
However, the next time pybabel update
is run, all comments are permanently removed from the file. This means those translations marked with #~
are removed, too.
For example, with Babel version 0.9.6 and Jinja2 version 2.6, and the following files:
./babel.ini
:
[jinja2: **/templates/**.html]
encoding = utf-8
./templates/test.html
:
<html><body>
<h1>{% trans %}My website{% endtrans %}</h1>
</body></html>
./i18n/pt_PT/LC_MESSAGES/messages.po
:
# ... header stuff generated from
# pybabel init -l pt_PT -d i18n -i i18n/messages.pot ...
# Don't forget, I want to remember something about this!
#~ msgid "My web page"
#~ msgstr "A minha página de web"
After the following commands are run:
$ pybabel extract -F babel.ini -o i18n/messages.pot .
$ pybabel update -l pt_PT -d i18n -i i18n/messages.pot
The Portuguese messages.po
file loses all its old comments, and contains only:
./i18n/pt_PT/LC_MESSAGES/messages.po
:
# ... similar header stuff ...
#: templates/test.html:2
msgid "My web site"
msgstr ""
How can I update my translation files without losing my comments and old translations?
发布评论
评论(1)
不使用 pybabel 更新,而是使用 msgmerge "noreferrer">gettext 实用程序
在您的情况下,它将是:
msgmerge ./i18n/pt_PT/LC_MESSAGES/messages.po ./i18n/messages.pot -o ./i18n/pt_PT/ LC_MESSAGES/messages.po
示例:
具有
reference.pot
文件:和
pt_previous.po
< /strong> 文件包含您以前的翻译:运行命令:
msgmerge pt_previous.po reference.pot -o pt_new.po
将生成
./pt_new .po
文件如下所示:Instead of using pybabel update use msgmerge from gettext utilities
In your case it would be:
msgmerge ./i18n/pt_PT/LC_MESSAGES/messages.po ./i18n/messages.pot -o ./i18n/pt_PT/LC_MESSAGES/messages.po
Example:
having
reference.pot
file:and
pt_previous.po
file with your previous translations:Running a command:
msgmerge pt_previous.po reference.pot -o pt_new.po
Will make
./pt_new.po
file which looks like this: