Login

language switcher in admin

Author:
lawgon
Posted:
November 9, 2009
Language:
HTML/template
Version:
Not specified
Score:
3 (after 3 ratings)

you have a multilingual site and need to change languages in admin. Previously this was easy in the site itself and more difficult in admin. Now it is dead easy. Set up your languages in settings.py. Make a directory called 'admin' in your templates directory, copy ~/django/contrib/admin/templates/base.html to that directory. Add the following code (below breadcrumbs is a good place)

this will give you a switcher for all installed languages. You would need to refresh the browser on changing the language.

1
2
3
4
5
6
7
8
9
<form action="/i18n/setlang/" method="post">
                <select name="language">
                {% for lang in LANGUAGES %}
                <option value="{{ lang.0 }}" {% ifequal lang.0 request.LANGUAGE_CODE           %}selected="yes"
                {% endifequal %}>{{ lang.1 }}</option>
                {% endfor %}
                </select>
                <input type="submit" value="Go" />
            </form>

More like this

  1. Bootstrap Accordian by Netplay4 3 years, 10 months ago
  2. Bootstrap theme for django-endless-pagination? by se210 6 years, 11 months ago
  3. Bootstrap theme for django-endless-pagination? by se210 6 years, 11 months ago
  4. Reusable form template with generic view by roldandvg 6 years, 12 months ago
  5. Pagination Django with Boostrap by guilegarcia 7 years, 1 month ago

Comments

simon_w (on November 29, 2010):

This wouldn't work for me (Django 1.2.3) without adding 'django.middleware.locale.LocaleMiddleware', to MIDDLEWARE_CLASSES

#

Please login first before commenting.