Browse Source

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 <anton.myasnikov@nordigy.ru>
Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
Anton 1 year ago
parent
commit
1feb3742e2

+ 8 - 0
docs/configuration/system.md

@@ -198,3 +198,11 @@ If `STORAGE_BACKEND` is not defined, this setting will be ignored.
 Default: UTC
 Default: UTC
 
 
 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).
 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).
+
+---
+
+## TRANSLATION_ENABLED
+
+Default: True
+
+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.)

+ 7 - 2
netbox/netbox/preferences.py

@@ -23,7 +23,7 @@ PREFERENCES = {
         ),
         ),
         description=_('Enable dynamic UI navigation'),
         description=_('Enable dynamic UI navigation'),
         default=False,
         default=False,
-        experimental=True
+        warning=_('Experimental feature')
     ),
     ),
     'locale.language': UserPreference(
     'locale.language': UserPreference(
         label=_('Language'),
         label=_('Language'),
@@ -31,7 +31,12 @@ PREFERENCES = {
             ('', _('Auto')),
             ('', _('Auto')),
             *settings.LANGUAGES,
             *settings.LANGUAGES,
         ),
         ),
-        description=_('Forces UI translation to the specified language.')
+        description=_('Forces UI translation to the specified language'),
+        warning=(
+            _("Support for translation has been disabled locally")
+            if not settings.TRANSLATION_ENABLED
+            else ''
+        )
     ),
     ),
     'pagination.per_page': UserPreference(
     'pagination.per_page': UserPreference(
         label=_('Page length'),
         label=_('Page length'),

+ 4 - 0
netbox/netbox/settings.py

@@ -156,6 +156,7 @@ SESSION_FILE_PATH = getattr(configuration, 'SESSION_FILE_PATH', None)
 STORAGE_BACKEND = getattr(configuration, 'STORAGE_BACKEND', None)
 STORAGE_BACKEND = getattr(configuration, 'STORAGE_BACKEND', None)
 STORAGE_CONFIG = getattr(configuration, 'STORAGE_CONFIG', {})
 STORAGE_CONFIG = getattr(configuration, 'STORAGE_CONFIG', {})
 TIME_ZONE = getattr(configuration, 'TIME_ZONE', 'UTC')
 TIME_ZONE = getattr(configuration, 'TIME_ZONE', 'UTC')
+TRANSLATION_ENABLED = getattr(configuration, 'TRANSLATION_ENABLED', True)
 
 
 # Load any dynamic configuration parameters which have been hard-coded in the configuration file
 # Load any dynamic configuration parameters which have been hard-coded in the configuration file
 for param in CONFIG_PARAMS:
 for param in CONFIG_PARAMS:
@@ -445,6 +446,9 @@ LOGIN_REDIRECT_URL = f'/{BASE_PATH}'
 # Use timezone-aware datetime objects
 # Use timezone-aware datetime objects
 USE_TZ = True
 USE_TZ = True
 
 
+# Toggle language translation support
+USE_I18N = TRANSLATION_ENABLED
+
 # WSGI
 # WSGI
 WSGI_APPLICATION = 'netbox.wsgi.application'
 WSGI_APPLICATION = 'netbox.wsgi.application'
 SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
 SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

+ 2 - 5
netbox/users/forms/model_forms.py

@@ -40,11 +40,8 @@ class UserConfigFormMetaclass(forms.models.ModelFormMetaclass):
             help_text = f'<code>{field_name}</code>'
             help_text = f'<code>{field_name}</code>'
             if preference.description:
             if preference.description:
                 help_text = f'{preference.description}<br />{help_text}'
                 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 = {
             field_kwargs = {
                 'label': preference.label,
                 'label': preference.label,
                 'choices': preference.choices,
                 'choices': preference.choices,

+ 2 - 2
netbox/users/preferences.py

@@ -2,10 +2,10 @@ class UserPreference:
     """
     """
     Represents a configurable user preference.
     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.label = label
         self.choices = choices
         self.choices = choices
         self.default = default if default is not None else choices[0]
         self.default = default if default is not None else choices[0]
         self.description = description
         self.description = description
         self.coerce = coerce
         self.coerce = coerce
-        self.experimental = experimental
+        self.warning = warning