Add a basic language switcher in the home footer

fix #74
This commit is contained in:
Yohan Boniface 2018-06-02 19:04:32 +02:00
parent 27bb306fd3
commit a7ec9b173d
4 changed files with 37 additions and 0 deletions

View file

@ -2,6 +2,7 @@
# Import global settings to make it easier to extend settings.
from django.conf.global_settings import * # pylint: disable=W0614,W0401
from django.template.defaultfilters import slugify
from django.conf.locale import LANG_INFO
# =============================================================================
# Generic Django project settings
@ -10,6 +11,21 @@ from django.template.defaultfilters import slugify
DEBUG = True
SITE_ID = 1
# Add languages we're missing from Django
LANG_INFO.update({
'am-et': {
'bidi': False,
'name': 'Amharic',
'code': 'am-et',
'name_local': 'አማርኛ'
},
'zh': {
'bidi': False,
'code': 'zh',
'name': 'Chinese',
'name_local': '简体中文',
},
})
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
TIME_ZONE = 'UTC'

View file

@ -22,6 +22,12 @@ footer a.branding {
color: #8F96A3;
display: inline-block;
}
footer .i18n_switch {
display: inline-block;
}
.umap-nav {
display: flex;
flex-direction: column;

View file

@ -1,3 +1,17 @@
{% load i18n %}
<footer>
<a href="/" class="branding">umap</a> an OpenStreetMap project (version {{ UMAP_VERSION }})
{% get_language_info_list for LANGUAGES as languages %}
<form action="{% url "set_language" %}" method="post" class="i18n_switch">
{% csrf_token %}
<select name="language" onchange="this.form.submit()">
{% for language in languages %}
<option value="{{ language.code }}"
{% if language.code == LANGUAGE_CODE %}selected="selected"{% endif %}>
{{ language.name_local }}
</option>
{% endfor %}
</select>
</form>
</footer>

View file

@ -31,6 +31,7 @@ urlpatterns = [
url(r'^change-password-done/', auth_views.password_change_done,
{'template_name': 'umap/password_change_done.html'},
name='password_change_done'),
url(r'^i18n/', include('django.conf.urls.i18n')),
]
i18n_urls = [