-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
Multiline msgids aren't wrapped the same way that xgettext wraps them #96
Comments
Looking at the docs, gettext starts the msgid with an empty line on purpose for "better alignment":
https://www.gnu.org/software/gettext/manual/gettext.html#PO-Files |
This is due to the differences between python standard library textwrap module and the gettext wrapper. |
This issue of the Python bug tracker seems related. |
Is there a xgettext command that re-textwraps a po file into the same format? That would work for my usecase, I could just call that command after every time I save a file with polib. |
should do the trick. |
For reference, it looks like in the gettext source code, the width is set here and then gets passed to and then the code does some stuff with the result.
documented here https://www.gnu.org/software/libunistring/manual/html_node/unilbrk_002eh.html Ideally, someone would make Python bindings for sed -i 's/charset=CHARSET/charset=UTF-8/' messages.po Then you can just do this: import subprocess
from polib import pofile
filename = "messages.po"
subprocess.run(["bash", "-c", "command msgcat"], check=True) # check that we have the msgcat command available
po = pofile(filename, encoding="utf-8")
po.save()
subprocess.run(["msgcat", filename, "-o", filename], check=True) PS. |
I think that the easiest solution to this problem is to generate Python bindings for the Rust crate textwrap which offers multiplatform Unicode Line Breaking wrapping. |
As a user of a pure python library, I would disagree on this. Adding a dependency to a library which requires a recompilation it's not exactly the easiest solution. |
You can serve wheels for a lot of platforms, is very easy. In fact, I'm thinking on rewriting polib entirely in Rust, it would optimize the library used from Python. |
I'm not sure I understand your point, you're talking of a rust rewrite, how in the earth can this solve this particular issue?! |
Just suggested to write Python bindings for Rust crate textwrap for its usage in polib to solve this problem. Is a very easy solution that does not involve compilation at installation time. I understand that some of you are not receptives to the idea, so since I use polib in several of my projects I'm thinking of rewriting it in Rust creating bindings for Python, which gives me, in addition to solving this problem, a considerable performance improvement. |
xgettext -c somefile.c
can produce a po file with an entry like this:but then if you just re-save it using
from polib import pofile; pofile("messages.po", encoding="utf-8").save()
, it will wrap it differently:polib
(really Python'stextwrap.wrap()
method) puts the space at the beginning of the second line instead of at the end of the first.This is an issue because using a command line tool that uses
polib
on a Django project would cause churn in the git history as it shuffles spaces between lines.I don't know why it's starting msgid with an empty string.
Here's a bash session showing the issue with a code sample that causes xgettext to produce an entry that starts with an empty string:
The text was updated successfully, but these errors were encountered: