From 08a419ec7ae24df64c80a7c10d99ae2a6d621e80 Mon Sep 17 00:00:00 2001 From: Arthur Hanson Date: Thu, 29 Dec 2022 06:04:35 -0800 Subject: [PATCH] 11271 flag to disable localization (#11323) * 11271 flag to disable localization * 11271 change to remove middleware * 11271 update docs for new var * Update docs/configuration/system.md Co-authored-by: kkthxbye <400797+kkthxbye-code@users.noreply.github.com> Co-authored-by: Jeremy Stretch Co-authored-by: kkthxbye <400797+kkthxbye-code@users.noreply.github.com> --- docs/configuration/system.md | 8 ++++++++ netbox/netbox/configuration_example.py | 3 +++ netbox/netbox/settings.py | 11 +++++++++++ 3 files changed, 22 insertions(+) diff --git a/docs/configuration/system.md b/docs/configuration/system.md index 5a7c8bebd..7061274f1 100644 --- a/docs/configuration/system.md +++ b/docs/configuration/system.md @@ -65,6 +65,14 @@ Email is sent from NetBox only for critical events or if configured for [logging --- +## ENABLE_LOCALIZATION + +Default: False + +Determines if localization features are enabled or not. This should only be enabled for development or testing purposes as netbox is not yet fully localized. Turning this on will localize numeric and date formats (overriding what is set for DATE_FORMAT) based on the browser locale as well as translate certain strings from third party modules. + +--- + ## HTTP_PROXIES Default: None diff --git a/netbox/netbox/configuration_example.py b/netbox/netbox/configuration_example.py index f298b35fe..9d9651462 100644 --- a/netbox/netbox/configuration_example.py +++ b/netbox/netbox/configuration_example.py @@ -222,6 +222,9 @@ SESSION_COOKIE_NAME = 'sessionid' # database access.) Note that the user as which NetBox runs must have read and write permissions to this path. SESSION_FILE_PATH = None +# Localization +ENABLE_LOCALIZATION = False + # Time zone (default: UTC) TIME_ZONE = 'UTC' diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index cc0a3c016..3a494093b 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -137,6 +137,7 @@ STORAGE_BACKEND = getattr(configuration, 'STORAGE_BACKEND', None) STORAGE_CONFIG = getattr(configuration, 'STORAGE_CONFIG', {}) TIME_FORMAT = getattr(configuration, 'TIME_FORMAT', 'g:i a') TIME_ZONE = getattr(configuration, 'TIME_ZONE', 'UTC') +ENABLE_LOCALIZATION = getattr(configuration, 'ENABLE_LOCALIZATION', False) # Check for hard-coded dynamic config parameters for param in PARAMS: @@ -356,6 +357,9 @@ MIDDLEWARE = [ 'django_prometheus.middleware.PrometheusAfterMiddleware', ] +if not ENABLE_LOCALIZATION: + MIDDLEWARE.remove("django.middleware.locale.LocaleMiddleware") + ROOT_URLCONF = 'netbox.urls' TEMPLATES_DIR = BASE_DIR + '/templates' @@ -651,6 +655,13 @@ RQ_QUEUES.update({ queue: RQ_PARAMS for queue in set(QUEUE_MAPPINGS.values()) if queue not in RQ_QUEUES }) +# +# Localization +# + +if not ENABLE_LOCALIZATION: + USE_I18N = False + USE_L10N = False # # Plugins