Skip to content

Pygettext: Support translator comments #130057

Closed

Description

@tomasr8

Feature or enhancement

Proposal:

Most gettext extraction tools such as xgettext or pybabel allow one to extract additional comments written by
the programmer which are meant to be read by the translator. These are prefixed with #. in the PO file.

The comments typically look something like this:

# i18n: Translator comment
_('foo')

This can be extracted with e.g. xgettext using xgettext --add-comments=i18n:

#. i18n: Translator comment
msgid "foo"
msgstr ""

Since this is a pretty widely used feature I propose we add this to pygettext as well.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Activity

  1. self-assigned this
    on Feb 12, 2025
  2. added
    triagedThe issue has been accepted as valid by a triager.
    on Feb 14, 2025
  3. StanFromIreland commented on Feb 16, 2025

    @StanFromIreland
  4. serhiy-storchaka commented on Feb 16, 2025

    @serhiy-storchaka
    Member

    There are few more differences from xgettext:

    • xgettext only supports one tag. If you use --add-comments several times, only the last one has effect. The documentation is not clear about this. In Python, implementing either behavior is equally easy, but in C supporting multiple tags would add much complexity.
    • xgettext looks not for a prefix, but for a substring. So --add-comments=8n: will find strings with the "i18n:" prefix and then remove "i1". This is weird, and this contradicts the documentation.
    • xgettext strips initial whitespaces from the tag for some reasons. I think this is the part of the above wart. I do not see reasons for this.
  5. tomasr8 commented on Feb 16, 2025

    @tomasr8
    MemberAuthor

    xgettext only supports one tag. If you use --add-comments several times, only the last one has effect. The documentation is not clear about this. In Python, implementing either behavior is equally easy, but in C supporting multiple tags would add much complexity.

    Yes, xgettext doesn't allow this, and it's quite confusing since it doesn't warn when you specify --add-comments multiple times. I think we should support multiple tags (as babel does) since it's quite easy to do so.

    xgettext looks not for a prefix, but for a substring. So --add-comments=8n: will find strings with the "i18n:" prefix and then remove "i1". This is weird, and this contradicts the documentation.

    Definitely strange, the docs say: "place comment blocks starting with TAG and preceding keyword lines in output file". Again, I think sticking with a prefix is the best option here.

    xgettext strips initial whitespaces from the tag for some reasons. I think this is the part of the above wart. I do not see reasons for this.

    Do you mean whitespace between # and the tag? e.g.

    #       i18n: lots of space
    _('foo')
  6. serhiy-storchaka commented on Feb 16, 2025

    @serhiy-storchaka
    Member

    Do you mean whitespace between # and the tag?

    No, whitespaces at the start of the argument. --add-comments=" i18n:" is the same as --add-comments=i18n:.

  7. serhiy-storchaka commented on Feb 16, 2025

    @serhiy-storchaka
    Member

    I think we should support multiple tags (as babel does) since it's quite easy to do so.

    Well, if babel does this, it is an argument for implementing such behavior.

  8. added a commit that references this issue on Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

triagedThe issue has been accepted as valid by a triager.type-featureA feature request or enhancement

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions