views:

52

answers:

1

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 solution 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.

A: 

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.

rebus
I know it, I do like you, but in my post underscore did not display, I don't know why.Some simply text I can translate but I can't translate list or others structures.
Thomas
ooh, sorry then... :), are using `gender` for choices in models? This seems to work ok for me. What is the exact problem? `woman` and `man` don't appear in *.po files?
rebus
appear there, I made translation and compiled, but still I see english version.
Thomas
So the strings appears in generated *.po but don't appear on site? Have you tried to changed the language in settings?
rebus
OK, I tried use ugettext_lazy and it makes diffrent it is work :)Before I was useing ugettext, in my first post I paste wrong code (ugettext_lazy)...Sorry for problems and thanks
Thomas