I'm quite new to Django and I'm working on a project with i18n, the thing is that I have translated some variables using .manage.py makemessages / compilemessages
on my template file, but when I use {% trans "my string" %}
I got the same "my string"
for all the languages.
What am I doing wrong? Here's the code for the views.py and the idioma.html
#some code here...
def idioma(request):
output = _("Mensaje en espanol")
return render_to_response( 'idioma/idioma.html', { 'idioma' : output }, context_instance = RequestContext(request) )
{% load i18n %}
< form action="/i18n/setlang/" method="post">
{% csrf_token %}
< input name="next" type="hidden" value="{{ redirect_to }}" />
< select name="language" >
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
< option value="{{ language.code }}">
{{ language.name_local }} ({{ language.code }})
< /option>
{% endfor %}
</select>
< input type="submit" value="Go" />
< /form>
La cadena es: {% trans idioma %}
{% trans "carro" %}
But it doesn't translate the {% trans "carro" %} string.
What's going on?
Thanks for your help!!!!
Have you manually translated the string in the .po ?
makemessages
just adds "carro" to the .po, generating something like this in the .po file
#: idioma.html:45
msgid "carro"
msgstr ""
and then you have to edit the .po manually adding the translation for that string, in this way:
#: idioma.html:45
msgid "carro"
msgstr "car"
Then, when you are done translating all the .po strings, you can run compilemessages
: it will compile your translations.
Note: always remember to look for ,fuzzy
translations.
If you have something like this in your .po
#: idioma.html:45
#, fuzzy
msgid "carro"
msgstr "car"
That means that django, for some reason, tried to translate the string by itself (it usually happens when you already used that string in a piece of code that you aren't using anymore).
You have to review the translation and delete the #, fuzzy
line: any translation tagged with #, fuzzy
won't be translated in your pages.
I ran into a similar problem and was able to resolve it by setting LOCALE_PATHS
in my settings file. LOCALE_PATHS
is a tuple of directory paths where django looks for .mo and .po files. Here's an example:
# settings.py
LOCALE_PATHS = (
'/path/to/your/project/locale',
)
Read django's official documentation on LOCALE_PATHS
for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With