Login

Admin change language

Author:
garcia_marc
Posted:
May 10, 2008
Language:
HTML/template
Version:
Not specified
Tags:
admin language change
Score:
1 (after 1 ratings)

This snippet adds a select language drop down menu in the admin bar (just after Documentation link).

For this approach it's necessary to copy from admin templates the admin/base.html to the project templates (keeping the admin directory), changing just line 25 ad shown. Then it's necessary to create specified admin/change_language.html template.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
**admin/base.html**

    25 <div id="user-tools">{% trans 'Welcome,' %} <strong>{% if user.first_name %}{{ user.first_name|escape }}{% else %}{{ user.username }}{% endif %}</strong>. {% block userlinks %}<a href="doc/">{% trans 'Documentation' %}</a>{% include 'admin/change_language.html' %} / <a href="password_change/">{% trans 'Change password' %}</a> / <a href="logout/">{% trans 'Log out' %}</a>{% endblock %}</div>


**admin/change_language.html**

    {% load i18n %}
    / {% trans 'Change language' %}
    <form action="/i18n/setlang/" method="post" style="display: inline;">
      <div style="display: inline;">
        <select name="language" onchange="javascript:form.submit()">
          {% for lang in LANGUAGES %}
            <option value="{{ lang.0 }}"{% ifequal LANGUAGE_CODE lang.0 %} selected="selected"{% endifequal %}>{{ lang.1 }}</option>
          {% endfor %}
        </select>
      </div>
    </form>

More like this

  1. language switcher in admin by lawgon 5 years, 5 months ago
  2. Admin Apps Names Translation by Nad 5 years, 3 months ago
  3. Painless link to admin change view for a given object by david_bgk 6 years, 1 month ago
  4. LocaleMiddleware without browser language discovery by ivellios 1 month, 3 weeks ago
  5. Language-aware template inclusion by bartTC 6 years, 1 month ago

Comments

Please login first before commenting.