Reputation: 441
I'm trying to internationalize my Django site with I18N. When I set the language in my template it doesn't change. This is my code:
# my flow
PROJECT
- LOCALE
- MYSITE
- urls.py
- settings.py
- APP1
- views.py
- APP2
manage.py
# settings.py
LANGUAGES = (
('it', 'Italiano'),
('en', 'English'),
)
LANGUAGE_CODE = 'it'
USE_I18N = True
LOCALE_PATHS = ('home/project/locale/',)
MIDDLEWARE_CLASSES = ( ...
'django.middleware.locale.LocaleMiddleware',
)
TEMPLATE_CONTEXT_PROCESSORS = (...,
'django.core.context_processors.i18n',
)
# views.py
from django.utils.translation import ugettext as _
text = _("this is a text")
...
return render_to_response('index.html', {'text': text,
},
context_instance=RequestContext(request))
# index.html
...
{% trans 'Dashboard' %}
# In index.html I change the language and I
<form action="{{site_url}}i18n/setlang/" method="
{% csrf_token %}
<input name="next" type="hidden" value="" />
<select name="language">
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
<option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE selected="selected"{% endif %}>
{{ language.name_local }} ({{ language.code }})
</option>
{% endfor %}
</select>
<input type="submit" value="Change" />
</form>
# urls.py
urlpatterns = patterns('',
(r'^admin/', include(admin.site.urls)),
(r'^i18n/', include('django.conf.urls.i18n')),
url(r'^$', TemplateView.as_view(template_name="login.html")),
....
When I change the language nothing happens. Where am I doing wrong? Thanks a lot for your help
Upvotes: 0
Views: 5775
Reputation: 75
We have the same problem when moving from PyCHarm to Linux server. On the local server LANGUAGES setting can be found in the form xx-aa but when we try on the Ubuntu with same config it can only find default language in LANGUAGE_CODE settings.
How can I make all LANGUAGES setup in the LANGUAGES array active under Ubuntu Linux.
Upvotes: 1
Reputation: 7460
In your urls.py:
from django.conf.urls.i18n import i18n_patterns
urlpatterns += i18n_patterns('',
)
Or (in case you want all your urls translated:
urlpatterns = i18n_patterns('',
)
To enable change lang url requests add (make sure this is outside i18n_patterns
(r'^i18n/', include('django.conf.urls.i18n'))
Upvotes: 2