I'm trying to get Django's translation system to work, following the tutorial here.
Here are my two views (one for direct output, one for template), neither one works.
def home(request):
output = _("hello") # (lazy)
return HttpResponse(output)
def with_template(request):
return render(request, 'translation_template.html')
here is the template file for the second view :
{% extends "base_site.html" %}
{% load i18n %}
{% block content %}
<p>{% trans 'hello' %}</p>
{% language 'tr' %}
<p>{% trans 'hello' %}</p>
{% endlanguage %}
{% language 'tr-TR' %}
<p>{% trans 'hello' %}</p>
{% endlanguage %}
{% endblock %}
in my settings file, I added the following: (may add parts from before if requested)
LANGUAGE_CODE = 'en-us'
# also tried LANGUAGE_CODE = 'tr' and LANGUAGE_CODE = 'tr-TR'
PROJECT_DIR = os.path.dirname(__file__)
"""
# tried but didn't work
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS
TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.context_processors.auth",
"django.core.context_processors.i18n",
)
"""
LOCALE_PATHS = ( os.path.join(PROJECT_DIR, 'locale'), )
LANGUAGES = (
('tr', _('Turkish')),
('en', _('English')),
)
after saving these, I executed in the terminal :
python ./manage.py makemessages -l tr
then edited the newly created myproject/locale/tr/LC_MESSAGES/django.po
to have this :
msgid "hello"
msgstr "merhaba"
then executed
python ./manage.py compilemessages
and restarted the server. the terminal commands show no error, but when I load the views, none of the "hello"s are translated.
What am I doing wrong here?
Thanks for any help!
Edit:
I found a suspicious code in en/../django.po, probably not relevant, but maybe it is. This is the very beginning of the file. The fuzzy (empty->empty) translation, could it be the problem?
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
{% get_language_info for LANGUAGE_CODE as current_lang %}
and{{ current_lang.code }}
– Kiblerdjango.middleware.locale.LocaleMiddleware
inMIDDLEWARE_CLASSES
? – Scorchen
. I also added a translation for English, "eng_hello" but it doesn't apply. – Birr{% language 'tr' %}
be doing this for me? Edit : I changed Chrome's settings to Turkish, @Selcuk's code showstr
this time, but again, no translation.. – Birr