Skip to content

Commit 1feb374

Browse files
amyasnikovAnton Myasnikovjeremystretch
authored
add ENABLE_TRANSLATION setting to optionally turn translation off (#16096)
* add USE_I18N setting * change setting name to ENABLE_TRANSLATION * raise a warning in the UI when translation is disabled * Misc cleanup * Rename to TRANSLATION_ENABLED for consistency with other settings --------- Co-authored-by: Anton Myasnikov <[email protected]> Co-authored-by: Jeremy Stretch <[email protected]>
1 parent 829bae6 commit 1feb374

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

docs/configuration/system.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,11 @@ If `STORAGE_BACKEND` is not defined, this setting will be ignored.
198198
Default: UTC
199199

200200
The time zone NetBox will use when dealing with dates and times. It is recommended to use UTC time unless you have a specific need to use a local time zone. Please see the [list of available time zones](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
201+
202+
---
203+
204+
## TRANSLATION_ENABLED
205+
206+
Default: True
207+
208+
Enables language translation for the user interface. (This parameter maps to Django's [USE_I18N](https://docs.djangoproject.com/en/stable/ref/settings/#std-setting-USE_I18N) setting.)

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+
_("Support for translation has been disabled locally")
37+
if not settings.TRANSLATION_ENABLED
38+
else ''
39+
)
3540
),
3641
'pagination.per_page': UserPreference(
3742
label=_('Page length'),

netbox/netbox/settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
STORAGE_BACKEND = getattr(configuration, 'STORAGE_BACKEND', None)
157157
STORAGE_CONFIG = getattr(configuration, 'STORAGE_CONFIG', {})
158158
TIME_ZONE = getattr(configuration, 'TIME_ZONE', 'UTC')
159+
TRANSLATION_ENABLED = getattr(configuration, 'TRANSLATION_ENABLED', True)
159160

160161
# Load any dynamic configuration parameters which have been hard-coded in the configuration file
161162
for param in CONFIG_PARAMS:
@@ -445,6 +446,9 @@ def _setting(name, default=None):
445446
# Use timezone-aware datetime objects
446447
USE_TZ = True
447448

449+
# Toggle language translation support
450+
USE_I18N = TRANSLATION_ENABLED
451+
448452
# WSGI
449453
WSGI_APPLICATION = 'netbox.wsgi.application'
450454
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)