gettext localize strings with variables

Thomas Jollans t at jollybox.de
Thu Jul 28 16:36:04 CEST 2011


On 28/07/11 15:33, miamia wrote:
> Hello,
> I have
> variable OUHH and
> print _('This is %(OUHH)s a translatable string.' % locals())
> 
> how can I translate this ?

Get the translation first, insert values second.

_('This string contains a variable: {0}. Amazing').format(OUHH)

Depending on what the actual string is, you may need to consider
plurals. See gettext.ngettext()



More information about the Python-list mailing list