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

List of occurrences wrapped differently than xgettext #137

Open
gamboz opened this issue Apr 28, 2023 · 1 comment
Open

List of occurrences wrapped differently than xgettext #137

gamboz opened this issue Apr 28, 2023 · 1 comment

Comments

@gamboz
Copy link

gamboz commented Apr 28, 2023

I think that xgettext --no-wrap does not apply to the list of occurrences, so polib and xgettext will format the #: lines differently.

If you have a structure like the following:

.
├── f
│   └── c.py
├── folder_medium_length
│   └── b.py
├── folder_name_with_a_very_long_name_and_in_any_case_longer_than_seventy_eight_characters
│   └── a.py

where all the files contain the same string to translate, polib with wrapwidth=0 gives something like

#: /tmp/x/folder_name_with_a_very_long_name_and_in_any_case_longer_than_seventy_eight_characters/a.py:4 /tmp/x/folder_medium_length/b.py:4 /tmp/x/f/c.py:4

while xgettext --no-wrap something like the following (that was somewhat unexpected for me :)

#: /tmp/x/folder_name_with_a_very_long_name_and_in_any_case_longer_than_seventy_eight_characters/a.py:4
#: /tmp/x/folder_medium_length/b.py:4
#: /tmp/x/f/c.py:4

I think this can be changed by editing polib.py l.1037 from

            if wrapwidth > 0 and len(filestr) + 3 > wrapwidth:

to

            if wrapwidth > 1 and len(filestr) + 3 > wrapwidth:

I'm not yet opening a PR, because these are my first steps in the "translations" world and I might be making stupid mistakes (so please be patient 🙂 )

gamboz added a commit to sissamedialab/wjs-profile-project that referenced this issue Apr 28, 2023
- linting to ci/cd (and to all code)
- drop contexts USER FACING and SUBMISSION FLOW and unfuzzy translations
- [OT] polib/gettext differences izimobil/polib#137
@armisael
Copy link

armisael commented Oct 7, 2024

Let me add a few more info on this: we use Django, which underneath uses xgettext; I tried the fix suggested by @gamboz but it didn't work: it is correct that when using --no-wrap, xgettext does still wrap "comments" (the original string location), but what worked for us was not to edit wrapwidth > 1, but rather to hardcode a width of 79 characters in polib.py#L1037:

1037,14c1,11
<             if wrapwidth > 0 and len(filestr) + 3 > wrapwidth:
<                 # textwrap split words that contain hyphen, this is not
<                 # what we want for filenames, so the dirty hack is to
<                 # temporally replace hyphens with a char that a file cannot
<                 # contain, like "*"
<                 ret += [line.replace('*', '-') for line in textwrap.wrap(
<                     filestr.replace('-', '*'),
<                     wrapwidth,
<                     initial_indent='#: ',
<                     subsequent_indent='#: ',
<                     break_long_words=False
<                 )]
<             else:
<                 ret.append('#: ' + filestr)
---
>             # textwrap split words that contain hyphen, this is not
>             # what we want for filenames, so the dirty hack is to
>             # temporally replace hyphens with a char that a file cannot
>             # contain, like "*"
>             ret += [line.replace('*', '-') for line in textwrap.wrap(
>                 filestr.replace('-', '*'),
>                 width=79,
>                 initial_indent='#: ',
>                 subsequent_indent='#: ',
>                 break_long_words=False
>             )]

I'm not sure this works on all use cases, though; with Django it worked.

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

No branches or pull requests

2 participants