Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
greyli opened this issue May 27, 2021 · 4 comments
Open

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

greyli opened this issue May 27, 2021 · 4 comments
Labels

Comments

@greyli
Copy link

greyli commented May 27, 2021

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 (flaskcwg/flask-docs-zh#35):

  • 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).
  • Some multiline msgstr was reordered based on the position of the English word (ref).

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
Copy link
Member

tk0miya commented May 29, 2021

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?

@tk0miya tk0miya added the bug label May 29, 2021
@greyli
Copy link
Author

greyli commented May 29, 2021

Could you file an issue to the project, please?

My colleague in the translation team has already submitted the issue to babel (python-babel/babel#787). Thanks!

@sak1
Copy link

sak1 commented Sep 1, 2021

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants