开发者

How can I make list or set translatable using gettext?

开发者 https://www.devze.com 2022-12-30 22:39 出处:网络
I have some structure in Python: > gender=( (\'0\',\'woman\'), (\'1\',\'man\') ) I want to translate it before I will display it in Django template. Unfortunately, below so开发者_如何学JAVAlutio

I have some structure in Python:

> gender=( ('0','woman'), ('1','man') )

I want to translate it before I will display it in Django template. Unfortunately, below so开发者_如何学JAVAlution doesn't work:

> from django.utils.translation import
> ugettext_lazy as _
> 
> gender=( ('0',_('woman')),
> ('1',_('man')) )

What shall I do to translate this? I read the docs, but I can't understand what I should do.


Try like this:

gender=( ('0',_('woman')), ('1',_('man')) )

When you import gettext:

from django.utils.translation import ugettext_lazy as _

you need to wrap the string in gettext function:

_('some_string')

If underscore is confiusing you, this is same as writing:

from django.utils.translation import ugettext_lazy
ugettext_lazy('some_string')

but using _ is shorter.

After you have marked strings for translation call makemessages django command.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号