diff --git a/plinth/forms.py b/plinth/forms.py
index a2e66ab50..548be1345 100644
--- a/plinth/forms.py
+++ b/plinth/forms.py
@@ -20,10 +20,15 @@ Common forms for use by modules.
"""
from django import forms
-from django.utils.translation import ugettext_lazy as _
+from django.conf import settings
+from django.utils import translation
+from django.utils.translation import ugettext_lazy as _, get_language_info
+import plinth
from plinth import utils
+import os
+
class ServiceForm(forms.Form):
"""Generic configuration form for a service."""
@@ -48,3 +53,21 @@ class DomainSelectionForm(forms.Form):
),
choices=[]
)
+
+
+class LanguageSelectionForm(forms.Form):
+ """Form for selecting the user's preferred language """
+
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ supported_languages = []
+ for language_code, language_name in settings.LANGUAGES:
+ locale_code = translation.to_locale(language_code)
+ plinth_dir = os.path.dirname(plinth.__file__)
+ if language_code == 'en' or os.path.exists(
+ os.path.join(plinth_dir, 'locale', locale_code)):
+ supported_languages.append((language_code, get_language_info(language_code)['name_local']))
+
+ self.fields['language'].choices = supported_languages
+
+ language = forms.ChoiceField(label='Language', choices=[])
diff --git a/plinth/templates/base.html b/plinth/templates/base.html
index a7d71d608..64cf7a050 100644
--- a/plinth/templates/base.html
+++ b/plinth/templates/base.html
@@ -172,6 +172,11 @@
{% else %}
+
+
+
+
+
diff --git a/plinth/templates/language-selection.html b/plinth/templates/language-selection.html
new file mode 100644
index 000000000..d47a77aee
--- /dev/null
+++ b/plinth/templates/language-selection.html
@@ -0,0 +1,38 @@
+{% extends 'base.html' %}
+{% comment %}
+#
+# This file is part of Plinth.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+{% endcomment %}
+
+{% load i18n %}
+
+{% load bootstrap %}
+
+{% block content%}
+
+ Choose your language
+
+
+
+{% endblock %}
diff --git a/plinth/urls.py b/plinth/urls.py
index 47d064476..f47413f6d 100644
--- a/plinth/urls.py
+++ b/plinth/urls.py
@@ -28,6 +28,7 @@ from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
+ url(r'^language-selection', public(views.LanguageSelectionView.as_view()), name='language-selection'),
url(r'^apps/$',
TemplateView.as_view(template_name='apps.html'), name='apps'),
url(r'^sys/$', views.system_index, name='system'),
diff --git a/plinth/views.py b/plinth/views.py
index 5f74b6b5a..c6d45e729 100644
--- a/plinth/views.py
+++ b/plinth/views.py
@@ -23,6 +23,11 @@ from django.core.exceptions import ImproperlyConfigured
from django.template.response import TemplateResponse
from django.views.generic import TemplateView
from django.views.generic.edit import FormView
+from django.http import HttpResponseRedirect
+from django.conf import settings
+from django.shortcuts import render
+from django.urls import reverse
+from django.utils import translation
from django.utils.translation import ugettext as _
from stronghold.decorators import public
import time
@@ -63,6 +68,30 @@ def system_index(request):
return TemplateResponse(request, 'system.html')
+class LanguageSelectionView(FormView):
+ """View for language selection"""
+ form_class = forms.LanguageSelectionForm
+ template_name = 'language-selection.html'
+
+ def get(self, request, *args, **kwargs):
+ current_values = {'language': translation.get_language()}
+ form = self.form_class(initial=current_values)
+ return render(request, self.template_name, {'form': form})
+
+ def post(self, request, *args, **kwargs):
+ form = self.form_class(request.POST)
+ if form.is_valid():
+ selected_language = form.cleaned_data['language']
+ translation.activate(selected_language)
+ # set selected language in session
+ request.session[translation.LANGUAGE_SESSION_KEY] = selected_language
+ response = HttpResponseRedirect(reverse('language-selection'))
+ # send a cookie for selected language
+ response.set_cookie(settings.LANGUAGE_COOKIE_NAME, selected_language)
+ return response
+ return render(request, self.template_name, {'form': form})
+
+
class ServiceView(FormView):
"""A generic view for configuring simple services."""
clients = []