Skip to content

Commit c519817

Browse files
committed
raise a warning in the UI when translation is disabled
1 parent dadef1b commit c519817

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

netbox/netbox/preferences.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,20 @@ def get_page_lengths():
2323
),
2424
description=_('Enable dynamic UI navigation'),
2525
default=False,
26-
experimental=True
26+
warning=_('Experimental feature')
2727
),
2828
'locale.language': UserPreference(
2929
label=_('Language'),
3030
choices=(
3131
('', _('Auto')),
3232
*settings.LANGUAGES,
3333
),
34-
description=_('Forces UI translation to the specified language.')
34+
description=_('Forces UI translation to the specified language.'),
35+
warning=(
36+
f"Translation is globally disabled inside configuration.py"
37+
if not settings.ENABLE_TRANSLATION
38+
else ''
39+
)
3540
),
3641
'pagination.per_page': UserPreference(
3742
label=_('Page length'),

netbox/netbox/settings.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
DJANGO_ADMIN_ENABLED = getattr(configuration, 'DJANGO_ADMIN_ENABLED', False)
9393
DOCS_ROOT = getattr(configuration, 'DOCS_ROOT', os.path.join(os.path.dirname(BASE_DIR), 'docs'))
9494
EMAIL = getattr(configuration, 'EMAIL', {})
95+
ENABLE_TRANSLATION = getattr(configuration, 'ENABLE_TRANSLATION', True)
9596
EVENTS_PIPELINE = getattr(configuration, 'EVENTS_PIPELINE', (
9697
'extras.events.process_event_queue',
9798
))
@@ -156,7 +157,6 @@
156157
STORAGE_BACKEND = getattr(configuration, 'STORAGE_BACKEND', None)
157158
STORAGE_CONFIG = getattr(configuration, 'STORAGE_CONFIG', {})
158159
TIME_ZONE = getattr(configuration, 'TIME_ZONE', 'UTC')
159-
USE_I18N = getattr(configuration, 'ENABLE_TRANSLATION', True)
160160

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

449+
USE_I18N = ENABLE_TRANSLATION
450+
449451
# WSGI
450452
WSGI_APPLICATION = 'netbox.wsgi.application'
451453
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

netbox/users/forms/model_forms.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,8 @@ def __new__(mcs, name, bases, attrs):
4040
help_text = f'<code>{field_name}</code>'
4141
if preference.description:
4242
help_text = f'{preference.description}<br />{help_text}'
43-
if preference.experimental:
44-
help_text = (
45-
f'<span class="text-danger"><i class="mdi mdi-alert"></i> Experimental feature</span><br />'
46-
f'{help_text}'
47-
)
43+
if warning := preference.warning:
44+
help_text = f'<span class="text-danger"><i class="mdi mdi-alert"></i> {warning}</span><br />{help_text}'
4845
field_kwargs = {
4946
'label': preference.label,
5047
'choices': preference.choices,

netbox/users/preferences.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ class UserPreference:
22
"""
33
Represents a configurable user preference.
44
"""
5-
def __init__(self, label, choices, default=None, description='', coerce=lambda x: x, experimental=False):
5+
def __init__(self, label, choices, default=None, description='', coerce=lambda x: x, warning=''):
66
self.label = label
77
self.choices = choices
88
self.default = default if default is not None else choices[0]
99
self.description = description
1010
self.coerce = coerce
11-
self.experimental = experimental
11+
self.warning = warning

0 commit comments

Comments
 (0)