Skip to content

pygettext: Wrapping to width is not implemented for msgids #130703

Open

Description

@StanFromIreland

Bug report

Bug description:

It has been implemented for comments but not for msgids.

Patch soon :-)

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

  1. changed the title [-]pygettext: `width` is not implemented for msgids[/-] [+]pygettext: Wrapping to `width` is not implemented for msgids[/+] on Feb 28, 2025
  2. added
    triagedThe issue has been accepted as valid by a triager.
    on Feb 28, 2025
  3. serhiy-storchaka commented on Feb 28, 2025

    @serhiy-storchaka
    Member

    Does xgettext wrap msgids?

  4. StanFromIreland commented on Feb 28, 2025

    @StanFromIreland
    MemberAuthor

    It wraps everything

    ‘-w number’
    ‘--width=number’
    Set the output page width. Long strings in the output files will be split across multiple lines in order to ensure that each line’s width (= number of screen columns) is less or equal to the given number.

    ‘--no-wrap’
    Do not break long message lines. Message lines whose width exceeds the output page width will not be split into several lines. Only file reference lines which are wider than the output page width will be split.

    but my wrap method is not correct, I cannot simply wrap at x chars.

    Normalize needs to be modified to wrap when over width

  5. serhiy-storchaka commented on Mar 2, 2025

    @serhiy-storchaka
    Member

    The xgettext implementation is much much more complex. It uses a complex function splitting long lines from other library (I think it is something between textwrap and PyICU; it is locale-depending). It ensures that format directives are not split (it needs to parse printf-like and format()-like format strings for this). It splits long "words". It takes into account the width of characters.

    I do not think pygettext needs this. I am not even sure that it needs more fancy algorithm than simply splitting the string by \n -- in most cases the resulting lines have reasonable size, and terminals are wider today.

  6. StanFromIreland commented on Mar 2, 2025

    @StanFromIreland
    MemberAuthor

    I have implemented a modified version of pybabels wrapping implementation, which I can tell you, does not include thoose features, and still behaves like xgettext.

    If the much more popular pybabel (than pygettext) uses it, then there must be a reason for it, and it must work, no?

  7. added
    type-featureA feature request or enhancement
    triagedThe issue has been accepted as valid by a triager.
    and removed
    triagedThe issue has been accepted as valid by a triager.
    type-bugAn unexpected behavior, bug, or error
    on Mar 2, 2025
  8. picnixz commented on Mar 2, 2025

    @picnixz
    Member

    (I'll mark it as a feature)

  9. StanFromIreland commented on Mar 2, 2025

    @StanFromIreland
    MemberAuthor

    @picnixz It was partially implemented a few years ago… so I guess it’s both?

  10. picnixz commented on Mar 2, 2025

    @picnixz
    Member

    Yes, but since it's in the Tools folder, I think it's easier not to change older versions. Even if it was partially implemented, it's a new feature in some sense.

  11. tomasr8 commented on Mar 2, 2025

    @tomasr8
    Member

    If the much more popular pybabel (than pygettext) uses it, then there must be a reason for it, and it must work, no?

    Not to disparage babel here (it's a great library and I frequently contribute to it) but it does have its own issues so I would advise against blindly copying whatever code babel is using

  12. tomasr8 commented on Mar 2, 2025

    @tomasr8
    Member

    I am not even sure that it needs more fancy algorithm than simply splitting the string by \n -- in most cases the resulting lines have reasonable size, and terminals are wider today.

    I think allowing splitting by whitespace (assuming it can be done safely) would be very useful. From my own experience working on a web-based project, we have lots of long strings without newlines because they get rendered by the browser where you normally don't use explicit \n.

  13. serhiy-storchaka commented on Mar 2, 2025

    @serhiy-storchaka
    Member

    Well, it makes sense. But full compatibility with xgettext (or pybabel) should not be the goal.

  14. tomasr8 commented on Mar 2, 2025

    @tomasr8
    Member

    Well, it makes sense. But full compatibility with xgettext (or pybabel) should not be the goal.

    I agree, we shouldn't follow everything, especially if it's not practical to do so.

  15. StanFromIreland commented on Mar 2, 2025

    @StanFromIreland
    MemberAuthor

    +1 on not aiming for full compatibility, just the key features, like this one

    So, Serhiy, what do you think of my white space splitting approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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