Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Language picker

Pacu2b424bfbb1395
diff --git a/saleor/static/js/storefront.js b/saleor/static/js/storefront.js
index b2dacd1e88..185f3cc8b5 100644
--- a/saleor/static/js/storefront.js
+++ b/saleor/static/js/storefront.js
@@ -8,6 +8,7 @@ import './components/navbar';
import './components/cart';
import './components/sorter';
import './components/variant-picker';
+import './components/language-picker';
import './components/footer';
import './components/product-filters';
import './components/address-form';
diff --git a/saleor/urls.py b/saleor/urls.py
index 92464ed7fa..10da8b73dc 100644
--- a/saleor/urls.py
+++ b/saleor/urls.py
@@ -4,7 +4,7 @@ from django.conf.urls.i18n import i18n_patterns
from django.conf.urls.static import static
from django.contrib.sitemaps.views import sitemap
from django.contrib.staticfiles.views import serve
-from django.views.i18n import JavaScriptCatalog
+from django.views.i18n import JavaScriptCatalog, set_language
from graphene_django.views import GraphQLView
from .account.urls import urlpatterns as account_urls
@@ -26,7 +26,8 @@ urlpatterns = [
url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps},
name='django.contrib.sitemaps.views.sitemap'),
url(r'^graphql', GraphQLView.as_view(
- schema=schema, graphiql=settings.DEBUG), name='api')]
+ schema=schema, graphiql=settings.DEBUG), name='api'),
+ url(r'^i18n/$', set_language, name='set_language')]
new_urlpatterns = [
url(r'^', include(core_urls)),
diff --git a/templates/_language_picker.html b/templates/_language_picker.html
new file mode 100644
index 0000000000..c5bf9461e4
--- /dev/null
+++ b/templates/_language_picker.html
@@ -0,0 +1,17 @@
+{% load i18n %}
+{% load translate_url from urls %}
+
+<li class="dropdown show">
+ {% get_current_language as LANGUAGE_CODE %}
+ <form action="{% url 'set_language' %}" method="post">
+ <input name="next" type="hidden" value="/">
+ {% csrf_token %}
+ {% get_available_languages as LANGUAGES %}
+ {% get_language_info_list for LANGUAGES as languages %}
+ <select class="selectpicker" name="language" id="language-picker">
+ {% for language in languages %}
+ <option value="{{ language.code }}" {% if language.code == LANGUAGE_CODE %} selected{% endif %}>{{ language.name_local }}</option>
+ {% endfor %}
+ </select>
+ </form>
+</li>
diff --git a/templates/base.html b/templates/base.html
index 84c0cdf719..e1d0770c48 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -55,6 +55,7 @@
</div>
<div class="col-6">
<ul class="float-right">
+ {% include "_language_picker.html" %}
{% if user.is_authenticated %}
{% if user.is_staff or request.impersonator.is_staff %}
<li>