[Python-Dev] The "i" string-prefix: I18n'ed strings

"Martin v. Löwis" martin at v.loewis.de
Sat Apr 8 00:45:19 CEST 2006


Martin Blais wrote:
> I'm not sure all the cases are handled, but for those which aren't I
> can't see why I couldn't hack the pygettext parser to make it do what
> I want, e.g. is the case were the function contains multiple strings
> handled? ::
> 
>   P(A_("Status: ", get_balance(), "dollars", href=".... ")
> 
> 
> (No need to answer to list, this is getting slightly OT, I'll check it
> out in more detail.)

I'll answer it anyway, because this is important enough for anybody to
understand :-)

*Never* try to do i18n that way. Don't combine fragments through
concatenation. Instead, always use placeholders. IOW, the
msgid should be

"Status: %s dollars"

or, if you have multiple placeholders

"Status: %(balance)s placeholders"

If you have many fragments, the translator gets the challenge of
translating "dollars". Now, this might need to be translated differently
in different contexts (and perhaps even depending on the value of
balance); the translator must always get the complete message
as a single piece.

Regards,
Martin


More information about the Python-Dev mailing list