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.
精彩评论