Skip to content

Commit

Permalink
raise a warning in the UI when translation is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
amyasnikov committed May 13, 2024
1 parent dadef1b commit c519817
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
9 changes: 7 additions & 2 deletions netbox/netbox/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,20 @@ def get_page_lengths():
),
description=_('Enable dynamic UI navigation'),
default=False,
experimental=True
warning=_('Experimental feature')
),
'locale.language': UserPreference(
label=_('Language'),
choices=(
('', _('Auto')),
*settings.LANGUAGES,
),
description=_('Forces UI translation to the specified language.')
description=_('Forces UI translation to the specified language.'),
warning=(
f"Translation is globally disabled inside configuration.py"
if not settings.ENABLE_TRANSLATION
else ''
)
),
'pagination.per_page': UserPreference(
label=_('Page length'),
Expand Down
4 changes: 3 additions & 1 deletion netbox/netbox/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
DJANGO_ADMIN_ENABLED = getattr(configuration, 'DJANGO_ADMIN_ENABLED', False)
DOCS_ROOT = getattr(configuration, 'DOCS_ROOT', os.path.join(os.path.dirname(BASE_DIR), 'docs'))
EMAIL = getattr(configuration, 'EMAIL', {})
ENABLE_TRANSLATION = getattr(configuration, 'ENABLE_TRANSLATION', True)
EVENTS_PIPELINE = getattr(configuration, 'EVENTS_PIPELINE', (
'extras.events.process_event_queue',
))
Expand Down Expand Up @@ -156,7 +157,6 @@
STORAGE_BACKEND = getattr(configuration, 'STORAGE_BACKEND', None)
STORAGE_CONFIG = getattr(configuration, 'STORAGE_CONFIG', {})
TIME_ZONE = getattr(configuration, 'TIME_ZONE', 'UTC')
USE_I18N = getattr(configuration, 'ENABLE_TRANSLATION', True)

# Load any dynamic configuration parameters which have been hard-coded in the configuration file
for param in CONFIG_PARAMS:
Expand Down Expand Up @@ -446,6 +446,8 @@ def _setting(name, default=None):
# Use timezone-aware datetime objects
USE_TZ = True

USE_I18N = ENABLE_TRANSLATION

# WSGI
WSGI_APPLICATION = 'netbox.wsgi.application'
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
Expand Down
7 changes: 2 additions & 5 deletions netbox/users/forms/model_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@ def __new__(mcs, name, bases, attrs):
help_text = f'<code>{field_name}</code>'
if preference.description:
help_text = f'{preference.description}<br />{help_text}'
if preference.experimental:
help_text = (
f'<span class="text-danger"><i class="mdi mdi-alert"></i> Experimental feature</span><br />'
f'{help_text}'
)
if warning := preference.warning:
help_text = f'<span class="text-danger"><i class="mdi mdi-alert"></i> {warning}</span><br />{help_text}'
field_kwargs = {
'label': preference.label,
'choices': preference.choices,
Expand Down
4 changes: 2 additions & 2 deletions netbox/users/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ class UserPreference:
"""
Represents a configurable user preference.
"""
def __init__(self, label, choices, default=None, description='', coerce=lambda x: x, experimental=False):
def __init__(self, label, choices, default=None, description='', coerce=lambda x: x, warning=''):
self.label = label
self.choices = choices
self.default = default if default is not None else choices[0]
self.description = description
self.coerce = coerce
self.experimental = experimental
self.warning = warning

0 comments on commit c519817

Please sign in to comment.