Login

Admin change language

Author:
garcia_marc
Posted:
May 10, 2008
Language:
HTML/template
Version:
Not specified
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. Bootstrap Accordian by Netplay4 5 years, 3 months ago
  2. Bootstrap theme for django-endless-pagination? by se210 8 years, 3 months ago
  3. Bootstrap theme for django-endless-pagination? by se210 8 years, 3 months ago
  4. Reusable form template with generic view by roldandvg 8 years, 4 months ago
  5. Pagination Django with Boostrap by guilegarcia 8 years, 6 months ago

Comments

Please login first before commenting.