Login

language switcher in admin

Author:
lawgon
Posted:
November 9, 2009
Language:
HTML/template
Version:
Not specified
Tags:
admin i18n
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. Admin change language by garcia_marc 6 years, 11 months ago
  2. Filter change list by a date range by aruseni 3 years, 2 months ago
  3. pygments stylize by mgiger 7 years, 9 months ago
  4. Regrouping admin models by sleytr 7 years, 2 months ago
  5. GeoDjango maps in admin TabularInlines by alanB 4 years, 6 months 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.