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

.. only:: not working in gettext builder #13307

Open
nijel opened this issue Feb 6, 2025 · 1 comment
Open

.. only:: not working in gettext builder #13307

nijel opened this issue Feb 6, 2025 · 1 comment
Labels
type:proposal a feature suggestion

Comments

@nijel
Copy link
Contributor

nijel commented Feb 6, 2025

Is your feature request related to a problem? Please describe.
#2874 described reasons why .. only:: should be ignored in gettext builder and #2878 implemented that. I see two issues with that:

  • This behavior is not documented (besides note in changelog entry from 2016).
  • This makes it impossible to exclude certain content from being localized.

Describe the solution you'd like

Let's take this rst:

.. only:: not gettext

   Content not to be localized.

.. only:: html

   Content to be localized.

I'd like the first block not to be extracted and the second one to be.

Describe alternatives you've considered

Any other syntax for excluding content from the generated POT file would do the job as well. Looking at the documentation the obvious way would be using .. only:: and its documentation does not contain any mention that it does not work with the gettext builder.

@nijel nijel added the type:proposal a feature suggestion label Feb 6, 2025
nijel added a commit to nijel/weblate that referenced this issue Feb 6, 2025
There is nothing to translate there, so let's exclude them from
translation.

This needs a bit hacking with Sphinx for now as there doesn't seem to be
a native way to achieve the exclusion, see
sphinx-doc/sphinx#13307.
@nijel
Copy link
Contributor Author

nijel commented Feb 6, 2025

Workaround I'm currently using:

import sphinx.builders.gettext
from sphinx.util.tags import Tags


class WeblateTags(Tags):
    def eval_condition(self, condition):
        # Exclude blocks marked as not gettext
        return condition != "not gettext"


def setup(app) -> None:
    # Monkey path gettext build tags handling, this is workaround until
    # https://github.com/sphinx-doc/sphinx/issues/13307 is addressed.
    sphinx.builders.gettext.I18nTags = WeblateTags

It is definitely not something ready for the inclusion as the text comparing is fragile, but doing something similar and more robust in _eval_node should be doable. I can contribute a PR if this is something acceptable.

nijel added a commit to WeblateOrg/weblate that referenced this issue Feb 6, 2025
There is nothing to translate there, so let's exclude them from
translation.

This needs a bit hacking with Sphinx for now as there doesn't seem to be
a native way to achieve the exclusion, see
sphinx-doc/sphinx#13307.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:proposal a feature suggestion
Projects
None yet
Development

No branches or pull requests

1 participant