diff --git a/plinth/__main__.py b/plinth/__main__.py index 0e8db1b73..d23fa1ed1 100644 --- a/plinth/__main__.py +++ b/plinth/__main__.py @@ -21,6 +21,7 @@ import django.conf from django.contrib.messages import constants as message_constants import django.core.management import django.core.wsgi +from django.utils import translation import importlib import logging import os @@ -224,18 +225,6 @@ def configure_django(): if cfg.secure_proxy_ssl_header: secure_proxy_ssl_header = (cfg.secure_proxy_ssl_header, 'https') - # Read translated languages from the 'locale' directory - languages = [('en', 'English')] - locale_dir = os.path.join(os.path.dirname(__file__), 'locale') - if os.path.isdir(locale_dir): - translated_language_codes = next(os.walk(locale_dir))[1] - all_languages = dict(django.conf.global_settings.LANGUAGES) - for code in translated_language_codes: - lang_code = code.replace('_', '-') - if lang_code in all_languages: - languages.append((code, all_languages[lang_code])) - languages = sorted(languages, key=lambda tup: tup[1]) - django.conf.settings.configure( ALLOWED_HOSTS=['*'], CACHES={'default': @@ -245,7 +234,6 @@ def configure_django(): 'NAME': cfg.store_file}}, DEBUG=cfg.debug, INSTALLED_APPS=applications, - LANGUAGES=languages, LOGGING=logging_configuration, LOGIN_URL='users:login', LOGIN_REDIRECT_URL='apps:index', diff --git a/plinth/modules/config/config.py b/plinth/modules/config/config.py index 54c687c2b..4957589bd 100644 --- a/plinth/modules/config/config.py +++ b/plinth/modules/config/config.py @@ -28,9 +28,11 @@ from django.template.response import TemplateResponse from django.utils import translation from django.utils.translation import ugettext as _, ugettext_lazy import logging +import os import re import socket +import plinth from plinth import actions from plinth import cfg from plinth.modules import firewall @@ -77,6 +79,7 @@ class TrimmedCharField(forms.CharField): return super(TrimmedCharField, self).clean(value) + def domain_label_validator(domainname): """Validate domain name labels.""" for label in domainname.split('.'): @@ -123,10 +126,22 @@ class ConfigurationForm(forms.Form): language = forms.ChoiceField( label=ugettext_lazy('Language'), - help_text=\ - ugettext_lazy('Language for this web administration interface'), - required=False, - choices=settings.LANGUAGES) + help_text=ugettext_lazy( + 'Language for this web administration interface'), + required=False) + + def __init__(self, *args, **kwargs): + """Set limited language choices.""" + super().__init__(*args, **kwargs) + 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)): + languages.append((language_code, language_name)) + + self.fields['language'].choices = languages def init():