Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gender problem in a django i18n translation

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.

like image 569
nabucosound Avatar asked Aug 25 '09 15:08

nabucosound


2 Answers

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 %}
like image 184
SmileyChris Avatar answered Oct 27 '22 15:10

SmileyChris


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.

like image 29
Alex Gaynor Avatar answered Oct 27 '22 13:10

Alex Gaynor