Python Forum
Formatted string not translated by gettext
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Formatted string not translated by gettext
#1
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
Reply
#2
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
Reply
#3
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…
Reply
#4
In your original post, you did not specify GNU, so expected you used one of the available packages.
Reply
#5
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.
Reply
#6
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!
Reply
#7
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().
Reply
#8
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!
Reply
#9
I just tried your suggestion but the issues seems to elsewhere…
Reply
#10
Are the problem strings all split?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I write formatted (i.e. bold, italic, change font size, etc.) text to a file? JohnJSal 13 35,360 May-20-2025, 12:26 PM
Last Post: hanmen9527
  Why is the 'meta description' html tag not translated? Melcu54 2 2,001 Oct-15-2022, 10:55 PM
Last Post: Larz60+
  Python convert multi line into single line formatted string karthidec 2 12,689 Dec-23-2019, 12:46 PM
Last Post: karthidec
  How to run a method on an argument in a formatted string Exsul 1 2,585 Aug-30-2019, 01:57 AM
Last Post: Exsul
  How work with formatted text in Python? AlekseyPython 3 4,119 Mar-18-2019, 05:00 AM
Last Post: AlekseyPython
  Want a list utf8 formatted but bytestrings found nikos 28 19,017 Feb-18-2019, 08:26 AM
Last Post: nikos

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.