Python Forum

Full Version: Formatted string not translated by gettext
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi,

I am using gettext successfully for my program, except for one string that needs formatting. Program runs properly, but the string remains untranslated (while others are). I tried different syntax but none has worked… Any idea would be very welcome!

Here is the recalcitrant string:
…
dialog.format_secondary_text(
                _("Some changes where made for {first_name} {last_name}. "
                  "Do you want to save these changes?").format(
                      first_name=self.people[self.personIndex][2],
                      last_name=self.people[self.personIndex][1]))
…
The relevant section in .po file:
msgid ""
"Some changes where made for {first_name} {last_name}. Do you want to save "
"these changes?"
msgstr ""
"Des modifications ont été faites pour {first_name} {last_name} : voulez-vous les enregistrer ?"
Regards,
Yvan
Please see the GitHub page for this package.
The author recommends http://pypi.python.org/pypi/Babel
And the author states
Quote:The idea for this project had been rather ambitious, but never lived up to what is was supposed to do
Thanks Larz60+ for the suggestion, but for the time being I would really prefer to stay on GNU Gettext, as my needs are simple and my time very limited on this personal project. I am not a developer, but I would be surprised if Gettext is not able to handle this…
In your original post, you did not specify GNU, so expected you used one of the available packages.
You are right, what you have written makes me think that I might be mixing different things:
- my code uses "import gettext" (from the standard library)
- I use GNU Gettext to create .pot, .po et .mo files

Hope this is more understandable.
I think you are correct, and I am wrong, I don't much use the gettext module, so immediately went to PyPi,
when I should of first looked for standard library!
Is this the only line where you use format()?

Have you tried this?
text = _("Some changes where made for {first_name} {last_name}.  Do you want to save these changes?")
dialog.format_secondary_text(
    text.format(
        first_name=self.people[self.personIndex][2],
        last_name=self.people[self.personIndex][1])
I'll be surprised if that makes any difference. The gettext function (_) should execute before the .format().
I just checked, there are indeed other places where I use format(). As those are error messages, I had never seen before now that it was not translated either… I will try your suggestion as soon as possible and let you know!
I just tried your suggestion but the issues seems to elsewhere…
Are the problem strings all split?
Pages: 1 2