20๐
You can create /en/admin
, /fr/admin/
and so on using i18n_patterns
:
urlpatterns += i18n_patterns(
url(r'^admin/', include(admin.site.urls)),
)
(For Django <= 1.7, you must specify a prefix, use i18n_patterns('', ... )
)
33๐
In your settings.py just add 'django.middleware.locale.LocaleMiddleware'
to your MIDDLEWARE_CLASSES
setting, making sure it appears after 'django.contrib.sessions.middleware.SessionMiddleware'
.
- [Django]-Python / Django โ If statement in template around extends
- [Django]-Single Django model, multiple tables?
- [Django]-How to See if a String Contains Another String in Django Template
14๐
Here is a slightly modified version of a code snippet from the Django docs for admin/base.html
that adds a language selection dropdown:
{% extends "admin/base.html" %}
{% load i18n %}
{% block userlinks %}
{{ block.super }}
/ <form action="{% url 'set_language' %}" method="post" style="display:inline">{% csrf_token %}
<input name="next" type="hidden" value="{{ redirect_to }}">
<select name="language" onchange="this.form.submit()">
{% get_current_language as LANGUAGE_CODE %}
{% get_available_languages as LANGUAGES %}
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
<option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %} selected{% endif %}>
{{ language.name_local }} ({{ language.code }})
</option>
{% endfor %}
</select>
</form>
{% endblock %}
For this to work you also need to add the following to your urlpatterns
:
path('i18n/', include('django.conf.urls.i18n')),
- [Django]-InterfaceError (0, '')
- [Django]-Turn off SQL logging while keeping settings.DEBUG?
- [Django]-What is the easiest way to clear a database from the CLI with manage.py in Django?
1๐
Change your browser default language.
Instead of spoiling the code. E.g.,
Chrome -> Settings -> Language -> Preferred languages: move upper Language you need.
Refresh browser, and the admin panel will change the displayed language.
- [Django]-How to use the 'reverse' of a Django ManyToMany relationship?
- [Django]-Differences between STATICFILES_DIR, STATIC_ROOT and MEDIA_ROOT
- [Django]-How to understand lazy function in Django utils functional module