[Pulp-list] Translatable strings

Jay Dobies jason.dobies at redhat.com
Thu Aug 2 20:41:04 UTC 2012


On 08/02/2012 04:40 PM, Jay Dobies wrote:
> On 08/02/2012 04:34 PM, Bryan Kearney wrote:
>> On 08/02/2012 04:32 PM, James Slagle wrote:
>>> Just a reminder, when you mark a string for translation, you have to
>>> pass the
>>> string itself to _(), not a variable whose value is the string.
>>>
>>> This does not work:
>>>
>>> msg = "some string"
>>> _(msg)
>>>
>>> You have to do:
>>>
>>> msg = _("some string")
>
> Wait, really? Crap, I do that all over the place.

Actually, that makes total sense. Never thought about it as I was doing 
it. I have a lot of fixes to make.

>>> and then use msg wherever you need to.
>>>
>>> If the string is long and you want to wrap it across lines, use python's
>>> built-in string concatenation (don't use + to concatenate strings):
>>>
>>> msg = _("a really really "
>>>          "long string")
>
> Had no idea this existed, good to know.
>
>> And, do parameter substitution outside:
>>
>> msg = ("Some Cool %s") % "stuff"
>>
>> not
>> = ("Some Cool %s" % "stuff")
>
> That one I remember is still not completely correct. I forget the
> reasoning, but substitutions have to be dict based:
>
> m = _("Some string %(foo)s")
> m % {'foo' : 'bar'}
>
>


-- 
Jay Dobies
Freenode: jdob @ #pulp
http://pulpproject.org | http://blog.pulpproject.org




More information about the Pulp-list mailing list