I am working on a website right now. I have started working on internationalizing it.
The code for the language selection menu is
<form action="/i18n/setlang/" method="post">
<select name="language">
{% for lang in LANGUAGES %}
<option value="{{ lang.0 }}">{{ lang.1 }}</option>
{% endfor %}
</select>
<input type="submit" value="Go" />
</form>
{{ LANGUAGE_CODE }}
But it does not seem to work. It just redirects to the same page
I have added
(r'^i18n/', include('django.conf.urls.i18n')) to urls.py;
'django.middleware.locale.LocaleMiddleware' to
MIDDLEWARE_CLASSES in settings.py
'django.core.context_processors.i18n', to
TEMPLATE_CONTEXT_PROCESSORS in settings.pyShould I import anything?
UPDATE
Wenever I add
LANGUAGES = (
('es', _('Spanish')),
('en-US', _('AmericanEnglish')),
)
to the settings.py I get
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, [no address given] and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Otherwise at least the website works
Redirecting to the same page is the default of django.views.i18n.set_language view (unless you send a different url in next param).
I suggest you to check if the language cookie is set or not (as anonymous user).
If the cookie is not set check that language code you're sending is correct.
Note that a language code is valid (in Django's mind) only if "its" locale code maps to a folder in django/conf/locale (not only a folder but a correct locale folder like locale_code/LC_MESSAGES/django.po)
having a look in django.utils.translations.trans_real.py (language check, lang to locale...) and in django/views/i18n.py helps a lot :)
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