mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-28 08:03:36 +00:00
config: Don't restrict supported languages
- There is no reason to limit the number of languages supported by the application. This is what happens when LANGUAGES is set during Django configuration. Users should be able to set a language using browser preferences and see at least the Django translated messages even if Plinth messages are not translated (example user create/edit form). - If we wish to limit the number of language options shown duing language selection (for quality perception reasons), we should perform the limiting at the time of configuration. - Note that when a new language is requested in translation tool, we create an empty file and that may lead to language being shown but with few strings actually translated. This will have poor impact on user experience. I wonder if we should filter language at all, keeping this in mind.
This commit is contained in:
parent
88c649d310
commit
d72abb8539
@ -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',
|
||||
|
||||
@ -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():
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user