Skip to content

gh-126609: localize list, allow translation of a phrase, use ge operator character in the availability directive #129597

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

Closed

Conversation

m-aciek
Copy link
Contributor

@m-aciek m-aciek commented Feb 2, 2025

  1. Localizes platform support lists using Babel's format_list().
  2. Exposes translation phrase not {platform} and fetches its translation in the availability directive content. This will allow full translations of availability directive content.
  3. Renders text-based greater-than or equal-to sing >= as UTF-8 .

Tested locally, both make gettext (exposes new phrase in sphinx.pot) and rendering with make html. Examples of renderings:

library/os.rst:2311

  • original:
Zrzut ekranu 2025-02-3 o 11 47 58
  • Traditional Chinese:
Zrzut ekranu 2025-02-3 o 12 06 24
  • Polish:
Zrzut ekranu 2025-02-3 o 12 06 35

📚 Documentation preview 📚: https://cpython-previews--129597.org.readthedocs.build/

@m-aciek m-aciek changed the title Docs: allow translation of a phrase in the availability directive Docs: allow translation of a phrase in the availability directive, use ge operator character Feb 2, 2025
@m-aciek m-aciek changed the title Docs: allow translation of a phrase in the availability directive, use ge operator character Docs: allow translation of a phrase, use ge operator character in the availability directive Feb 2, 2025
@@ -68,14 +69,17 @@ def run(self) -> list[nodes.container]:
refwarn=True,
)
sep = nodes.Text(": ")
parsed, msgs = self.state.inline_text(self.arguments[0], self.lineno)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is somewhat surprising that this doesn't work, as sphinx.util.nodes.extract_messages() should pick up the rawsource attributes -- we shouldn't need to parse & reparse.

Copy link
Contributor Author

@m-aciek m-aciek Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even when I've added not WASI, not Android. translation string by hand, it wasn't picked up in the build process.

@AA-Turner AA-Turner changed the title Docs: allow translation of a phrase, use ge operator character in the availability directive gh-126609: allow translation of a phrase, use ge operator character in the availability directive Feb 2, 2025
parsed, msgs = self.state.inline_text(self.arguments[0], self.lineno)
platforms = self.parse_platforms()
platforms_text = (
f"{', '.join(starmap(_print_platform, platforms.items()))}."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if babel is available here, but format_list might be a better option?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Babel is Sphinx's dependency, it is available. Thank you for the suggestion, I've added it.

@m-aciek m-aciek changed the title gh-126609: allow translation of a phrase, use ge operator character in the availability directive gh-126609: localize list, allow translation of a phrase, use ge operator character in the availability directive Feb 3, 2025
Copy link
Contributor

@StanFromIreland StanFromIreland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than my little nitpick it looks very good!

return platform
if not version:
return sphinx_gettext("not {platform}").format(platform=platform)
return f"{platform} ≥ {version}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return f"{platform} {version}"
return f"{platform} >= {version}"

How well supported is "≥"? Does it render well in pdf outputs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

epub
image

Copy link
Contributor Author

@m-aciek m-aciek Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AA-Turner could you please advise, is there some direct way to recognize epub build in the directive code and fallback to >=? Or should I rather drop the UTF-8 character from here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find no mention of using "≥" or ">=" for versions in the Google, Microsoft and Apple style guides, and they say to use words such as "Use version 2.2 or later" and not "Use version 2.2 or higher":

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @hugovk . This again will require translation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add that >= is currently used.

image

Copy link
Contributor Author

@m-aciek m-aciek Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find Google's style guide contradictory 🤔

A release with the highest version number might not be the latest version. For example, if version 2.0 of an operating system receives a bug-fix update after version 3.0 has been released, then version 2.0.1 might be the latest version, even though its version number is lower than 3.0.

In this meaning we rather want to express "higher" than "later". And later they recommend higher in Android docs. I've filed a feedback to this section.

I agree that the written form may be easier to read than the symbolic one. Though ≥ seems to be inambiguous, contrary to “later”.

I will add that >= is currently used.

I wonder what should be the approach, if we decide to use "Linux 2.6.27 or later", should we rewrite also the availability directives content in .rsts? Or introduce a simplified "syntax", that will be rendered to "or later" from a ">=" specificator? That may be confusing to docs editors. (?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we choose to use words, I'd rewrite the existing ">=" to avoid problems/confusion by automation changing things in unexpected ways.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this in this month's docs workgroup meeting: let's keep the directives compact; they're not prose, and use the single symbol. The Unicode symbol was introduced in 1993, hopefully it renders well on near anything. If there's an issue with Unicode in some of the backends (such as man pages), we should fix that.

(Minutes will appear at https://docs-community.readthedocs.io/en/latest/monthly-meeting/index.html in the near future.)

return platform
if not version:
return sphinx_gettext("not {platform}").format(platform=platform)
return f"{platform} ≥ {version}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find no mention of using "≥" or ">=" for versions in the Google, Microsoft and Apple style guides, and they say to use words such as "Use version 2.2 or later" and not "Use version 2.2 or higher":

m-aciek and others added 2 commits February 3, 2025 22:40
@AA-Turner
Copy link
Member

It would be good to properly investigate why the gettext builder is not picking up the raw text here. In the other part of #126609, there was a fairly simple resolution instead of a partial revert -- the PR as it stands now is duplicative, parsing and re-creating the text provided to the directive, whereas currently we just validate that it is correct. If we fix the source text being picked up by gettext, it would also mean that we don't need babel.lists, as translators can simply translate the source text naturally. As such, I've added the DO-NOT-MERGE label for the time being.

A

@m-aciek m-aciek marked this pull request as draft February 4, 2025 14:26
@m-aciek
Copy link
Contributor Author

m-aciek commented Feb 19, 2025

I'm convinced that we should translate the full text, instead of building it from fragments (vide Prefer WET over DRY for i18n). Therefore I will close this PR. I didn't yet succeed with the correct solution. I will try to write my findings in related discussion thread soon https://github.com/orgs/sphinx-doc/discussions/13280.

@m-aciek m-aciek closed this Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants