views:

398

answers:

3

I need to solve a gender translation problem, and Django doesn't seem to have gettext contexts implemented yet...

I need to translate from english:

<p>Welcome, {{ username }}</p>

In two forms of spanish, one for each gender. If user is a male:

<p>Bienvenido, {{ username }}</p>

and if is a female:

<p>Bienvenida, {{ username }}</p>

note the difference (bienvenido/bienvenida)

Is there any way of getting this done?

Thanks,

H.

+2  A: 

Django is just Python so you can use the Python gettext bindings directly if you need to, I don't see any reason you couldn't write a {% gender_trans [gender] %} tag.

Alex Gaynor
"gender_trans" may not be the perfect naming for the tag :-)
Roberto Liffredo
Python gettext library does not support contexts, see http://bugs.python.org/issue2504. Babel does not help here too, since msgctx support is planned for 1.0 release, see http://babel.edgewall.org/milestone/1.0
zgoda
+2  A: 

While waiting for contexts to be supported, an easy alternative would be to slightly change the Spanish sentence and use a greeting that does not vary according to a person's gender. For example, you could use "hola", or some other equivalent term.

Giulio Piancastelli
+1  A: 

The way that I've solved this is:

{% if profile.male %}
{% blocktrans with profile.name as male %}Welcome, {{ male }}{% endblocktrans %}
{% else %}
{% blocktrans with profile.name as female %}Welcome, {{ female }}{% endblocktrans %}
{% endif %}
SmileyChris