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

POEntry eats escape characters #155

Closed
Zsar opened this issue Aug 2, 2024 · 4 comments
Closed

POEntry eats escape characters #155

Zsar opened this issue Aug 2, 2024 · 4 comments

Comments

@Zsar
Copy link

Zsar commented Aug 2, 2024

polib 1.2.0 on Python 3.7 installed via pip.

Expected: I can access the string contained in the .po file.

Sample C# source line:
Catalog.GetString("A configuration profile with name \"{0}\" is already existing.")

Sample .po file entry for that line:

#, csharp-format
msgid "A configuration profile with name \"{0}\" is already existing."
msgstr "A configuration profile with name \"{0}\" already exists."

Content of POEntry.msgid:
'A configuration profile with name "{0}" is already existing.'
Content of POEntry.msgstr:
'A configuration profile with name "{0}" already exists.'

The eaten characters are (through guesswork?) added back when saving the POFile, but this means writing out the content anywhere will not result in the original string.

@stefan6419846
Copy link

The escape characters are required in the .po file itself, as " is used a both places. When displaying/printing it with Python, this is not required as the outer ' is different from the inner ".

@Zsar
Copy link
Author

Zsar commented Jan 9, 2025

This library does not concern itself only with Python however. It concerns itself with .po files and in extension may concern itself with any source language supported by gettext.

When the strings magically change along the way, that is hard to debug and hard to work around.

(E.g. my use case where I discovered this issue was to use Python to bulk-update my msgids in the C# source files - but I could not find them, because Python searched for different strings: The real ones contained the character \ and the search strings did not. I had to guess up my own escape function to recreate characters already present in the .po files .)

@stefan6419846
Copy link

But isn't this just the representation of the strings inside the terminal? Or does this affect generated output files as well?

@izimobil
Copy link
Owner

@Zsar I don't get your problem.

Escaped double quotes are required in the PO file because msgstr and msgid are delimited by double quotes as @stefan6419846 said.

Outside of the PO file context, there's no reason why the escape characters should be kept ! For example, try opening your file with POEdit or any other PO file editor, and you'll see the escape characters are not present, this is the expected behavior.

I'm closing the issue.

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

3 participants