python-babel / babel

The official repository for Babel, the Python Internationalization Library
http://babel.pocoo.org/
BSD 3-Clause "New" or "Revised" License
1.31k stars 438 forks source link

Should not change the line-wrapping of msgstr after .po files are updated #787

Open frostming opened 3 years ago

frostming commented 3 years ago

We are using a setup of sphinx-intl to translate sphinx docs into Chinese, but after updating the PO files, we saw some lines in msgstr get reordered: https://github.com/greyli/flask-docs-zh/pull/35/files

Here I suggest the msgstr should not be touched after update.

greyli commented 3 years ago

Here is the way to reproduce this issue:

$ python
Python 3.9.1 (default, Dec 12 2020, 22:52:49)
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> msgid = ("Flask is flexible. It doesn't require you to use any particular project "
"or code layout. However, when first starting, it's helpful to use a more "
"structured approach. This means that the tutorial will require a bit of "
"boilerplate up front, but it's done to avoid many common pitfalls that "
"new developers encounter, and it creates a project that's easy to expand "
"on. Once you become more comfortable with Flask, you can step out of this"
" structure and take full advantage of Flask's flexibility.")
>>> msgstr = ("Flask 很灵活。它不需要你使用任何特定的项目或代码结构。然而,在刚起步的时候,"
"使用更结构化的代码组织方式会更好一些。这意味着这个教程将会在一开始花费一些"
"时间来创建项目结构和基础代码,不过这样做可以避免很多新手开发者容易遇到的"
"常见错误,而且这样会创建一个容易扩展的项目。一旦你更熟悉 Flask,你就可以"
"跳出这个结构并充分利用 Flask 的灵活性。")
>>>
>>> from babel.messages import Catalog
>>> from babel.messages.pofile import write_po
>>> from babel._compat import BytesIO
>>> catalog = Catalog()
>>> catalog.add((msgid, msgstr))
<Message ("Flask is flexible. It doesn't require you to use any particular project or code layout. However, when first starting, it's helpful to use a more structured approach. This means that the tutorial will require a bit of boilerplate up front, but it's done to avoid many common pitfalls that new developers encounter, and it creates a project that's easy to expand on. Once you become more comfortable with Flask, you can step out of this structure and take full advantage of Flask's flexibility.", 'Flask 很灵活。它不需要你使用任何特定的项目或代码结构。然而,在刚起步的时候,使用更结构化的代码组织方式会更好一些。这意味着这个教程将会在一开始花费一些时间来创建项目结构和基础代码,不过这样做可以避免很多新手开发者容易遇到的常见错误,而且这样会创建一个容易扩展的项目。一旦你更熟悉 Flask,你就可以跳出这个结构并充分利用 Flask 的灵活性。') (flags: [])>
>>> buf = BytesIO()
>>> write_po(buf, catalog, omit_header=True, width=80)
>>> print(buf.getvalue().decode("utf8"))
msgid ""
"Flask is flexible. It doesn't require you to use any particular project or "
"code layout. However, when first starting, it's helpful to use a more "
"structured approach. This means that the tutorial will require a bit of "
"boilerplate up front, but it's done to avoid many common pitfalls that new "
"developers encounter, and it creates a project that's easy to expand on. Once"
" you become more comfortable with Flask, you can step out of this structure "
"and take full advantage of Flask's flexibility."
msgid_plural ""
"Flask "
"很灵活。它不需要你使用任何特定的项目或代码结构。然而,在刚起步的时候,使用更结构化的代码组织方式会更好一些。这意味着这个教程将会在一开始花费一些时间来创建项目结构和基础代码,不过这样做可以避免很多新手开发者容易遇到的常见错误,而且这样会创建一个容易扩展的项目。一旦你更熟悉"
" Flask,你就可以跳出这个结构并充分利用 Flask 的灵活性。"
msgstr[0] ""
msgstr[1] ""
>>> buf = BytesIO()
>>> write_po(buf, catalog, omit_header=True, width=120)
>>> print(buf.getvalue().decode("utf8"))
msgid ""
"Flask is flexible. It doesn't require you to use any particular project or code layout. However, when first starting,"
" it's helpful to use a more structured approach. This means that the tutorial will require a bit of boilerplate up "
"front, but it's done to avoid many common pitfalls that new developers encounter, and it creates a project that's "
"easy to expand on. Once you become more comfortable with Flask, you can step out of this structure and take full "
"advantage of Flask's flexibility."
msgid_plural ""
"Flask "
"很灵活。它不需要你使用任何特定的项目或代码结构。然而,在刚起步的时候,使用更结构化的代码组织方式会更好一些。这意味着这个教程将会在一开始花费一些时间来创建项目结构和基础代码,不过这样做可以避免很多新手开发者容易遇到的常见错误,而且这样会创建一个容易扩展的项目。一旦你更熟悉"
" Flask,你就可以跳出这个结构并充分利用 Flask 的灵活性。"
msgstr[0] ""
msgstr[1] ""