sphinx-doc / sphinx-intl

A Sphinx utility that make it easy to translate and to apply translations.
https://sphinx-intl.readthedocs.io/
BSD 2-Clause "Simplified" License
71 stars 37 forks source link

The "sphinx-intl update" command should not change existing msgstr #50

Open greyli opened 3 years ago

greyli commented 3 years ago

Hi! I followed the instructions in the Sphinx docs to generate the .pot and .po files in this repo.

Now after the .rst source has changed, I tried to update the .po files with the following commands:

$ make gettext
$ sphinx-intl update -p _build/gettext

But I found some unexpected changes (https://github.com/greyli/flask-docs-zh/pull/35):

The last one brings quite a bit messy (see the ref for the example). Is there any method to disable the update command to change the existing msgstr? I didn't found any related issues or documentation. And the -w option only changes the max line length of msgid.

Sphinx: 4.0.2 sphinx-intl: 2.0.1 Python: 3.8 (Windows 10)

Thanks!

tk0miya commented 3 years ago

Some Chinese words added as msgid for the API reference docs (ref). The msgid of alt of images was replaced with the translated msgstr (ref).

At present, your .pot file is built with language=zh_CN. So it contains Chinese text as msgid. Please generate .pot file with language=en (or None).

Some multiline msgstr was reordered based on the position of the English word (ref).

This is a bug of babel; a library that sphinx-intl uses to re-generate .po file. And I don't know a workaround for this topic:

$ 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] ""

Could you file an issue to the project, please?

greyli commented 3 years ago

Could you file an issue to the project, please?

My colleague in the translation team has already submitted the issue to babel (https://github.com/python-babel/babel/issues/787). Thanks!

sak1 commented 3 years ago

Hi ,I use these command for translate trino document :

make gettext language=en 
sphinx-intl update -p build/locale -l zh-CN

I get lot of .po files,but msgstr "" could you help me? thanks

sachin-suresh-rapyuta commented 1 year ago

@sak1 is it supposed to be sphinx-intl update -p build/gettext -l zh-CN ?