From 473ec9586c7b3db023932fb9005c50aaf6550e8f Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 24 Jun 2022 13:37:35 +1000 Subject: [PATCH] Override behaviour of {% load i18n %} - No longer requires custom tag loading - All templates now use escaped translation values - Requires re-ordering of app loading - Revert js_i18n to simply i18n --- InvenTree/InvenTree/settings.py | 24 +++++++++---------- .../part/templatetags/{js_i18n.py => i18n.py} | 19 +++++++++++++++ InvenTree/templates/js/dynamic/calendar.js | 2 +- InvenTree/templates/js/translated/api.js | 2 +- .../templates/js/translated/attachment.js | 2 +- InvenTree/templates/js/translated/barcode.js | 2 +- InvenTree/templates/js/translated/bom.js | 2 +- InvenTree/templates/js/translated/build.js | 2 +- InvenTree/templates/js/translated/company.js | 2 +- InvenTree/templates/js/translated/filters.js | 2 +- InvenTree/templates/js/translated/forms.js | 2 +- InvenTree/templates/js/translated/helpers.js | 2 +- InvenTree/templates/js/translated/label.js | 2 +- InvenTree/templates/js/translated/modals.js | 2 +- .../js/translated/model_renderers.js | 2 +- .../templates/js/translated/notification.js | 2 +- InvenTree/templates/js/translated/order.js | 2 +- InvenTree/templates/js/translated/part.js | 2 +- InvenTree/templates/js/translated/plugin.js | 2 +- InvenTree/templates/js/translated/report.js | 2 +- InvenTree/templates/js/translated/search.js | 2 +- InvenTree/templates/js/translated/stock.js | 2 +- .../templates/js/translated/table_filters.js | 2 +- InvenTree/templates/js/translated/tables.js | 2 +- 24 files changed, 53 insertions(+), 34 deletions(-) rename InvenTree/part/templatetags/{js_i18n.py => i18n.py} (75%) diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index e50c8fceae..d11f0920a0 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -218,18 +218,6 @@ logger.debug(f"STATIC_ROOT: '{STATIC_ROOT}'") INSTALLED_APPS = [ - # Core django modules - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'user_sessions', # db user sessions - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'django.contrib.sites', - - # Maintenance - 'maintenance_mode', - # InvenTree apps 'build.apps.BuildConfig', 'common.apps.CommonConfig', @@ -243,6 +231,18 @@ INSTALLED_APPS = [ 'plugin.apps.PluginAppConfig', 'InvenTree.apps.InvenTreeConfig', # InvenTree app runs last + # Core django modules + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'user_sessions', # db user sessions + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'django.contrib.sites', + + # Maintenance + 'maintenance_mode', + # Third part add-ons 'django_filters', # Extended filter functionality 'rest_framework', # DRF (Django Rest Framework) diff --git a/InvenTree/part/templatetags/js_i18n.py b/InvenTree/part/templatetags/i18n.py similarity index 75% rename from InvenTree/part/templatetags/js_i18n.py rename to InvenTree/part/templatetags/i18n.py index f9fc69fdf1..fcd9df4628 100644 --- a/InvenTree/part/templatetags/js_i18n.py +++ b/InvenTree/part/templatetags/i18n.py @@ -3,6 +3,7 @@ Translated strings are escaped, such that they can be used as string literals in a javascript file. """ +import django.templatetags.i18n from django import template from django.template import TemplateSyntaxError from django.templatetags.i18n import TranslateNode @@ -100,3 +101,21 @@ def do_translate(parser, token): seen.add(option) return CustomTranslateNode(message_string, noop, asvar, message_context) + + +# Re-register tags which we have not explicitly overridden +register.tag("blocktrans", django.templatetags.i18n.do_block_translate) +register.tag("blocktranslate", django.templatetags.i18n.do_block_translate) + +register.tag("language", django.templatetags.i18n.language) + +register.tag("get_available_languages", django.templatetags.i18n.do_get_available_languages) +register.tag("get_language_info", django.templatetags.i18n.do_get_language_info) +register.tag("get_language_info_list", django.templatetags.i18n.do_get_language_info_list) +register.tag("get_current_language", django.templatetags.i18n.do_get_current_language) +register.tag("get_current_language_bidi", django.templatetags.i18n.do_get_current_language_bidi) + +register.filter("language_name", django.templatetags.i18n.language_name) +register.filter("language_name_translated", django.templatetags.i18n.language_name_translated) +register.filter("language_name_local", django.templatetags.i18n.language_name_local) +register.filter("language_bidi", django.templatetags.i18n.language_bidi) diff --git a/InvenTree/templates/js/dynamic/calendar.js b/InvenTree/templates/js/dynamic/calendar.js index 98d4a2ae00..0b0ccc2915 100644 --- a/InvenTree/templates/js/dynamic/calendar.js +++ b/InvenTree/templates/js/dynamic/calendar.js @@ -1,4 +1,4 @@ -{% load js_i18n %} +{% load i18n %} /* globals */ diff --git a/InvenTree/templates/js/translated/api.js b/InvenTree/templates/js/translated/api.js index 18fda0716c..0bb8b2b2ea 100644 --- a/InvenTree/templates/js/translated/api.js +++ b/InvenTree/templates/js/translated/api.js @@ -1,4 +1,4 @@ -{% load js_i18n %} +{% load i18n %} {% load inventree_extras %} /* globals diff --git a/InvenTree/templates/js/translated/attachment.js b/InvenTree/templates/js/translated/attachment.js index 2aa0f4038b..e070cc65b1 100644 --- a/InvenTree/templates/js/translated/attachment.js +++ b/InvenTree/templates/js/translated/attachment.js @@ -1,4 +1,4 @@ -{% load js_i18n %} +{% load i18n %} /* globals makeIconButton, diff --git a/InvenTree/templates/js/translated/barcode.js b/InvenTree/templates/js/translated/barcode.js index 1a93a00368..3c2211e710 100644 --- a/InvenTree/templates/js/translated/barcode.js +++ b/InvenTree/templates/js/translated/barcode.js @@ -1,4 +1,4 @@ -{% load js_i18n %} +{% load i18n %} /* globals imageHoverIcon, diff --git a/InvenTree/templates/js/translated/bom.js b/InvenTree/templates/js/translated/bom.js index 9440a050ff..f800c10d1b 100644 --- a/InvenTree/templates/js/translated/bom.js +++ b/InvenTree/templates/js/translated/bom.js @@ -1,4 +1,4 @@ -{% load js_i18n %} +{% load i18n %} /* globals constructForm, diff --git a/InvenTree/templates/js/translated/build.js b/InvenTree/templates/js/translated/build.js index e44d1bdee5..b1315f1d35 100644 --- a/InvenTree/templates/js/translated/build.js +++ b/InvenTree/templates/js/translated/build.js @@ -1,4 +1,4 @@ -{% load js_i18n %} +{% load i18n %} {% load inventree_extras %} /* globals diff --git a/InvenTree/templates/js/translated/company.js b/InvenTree/templates/js/translated/company.js index 5228a452a5..dd87c2ef83 100644 --- a/InvenTree/templates/js/translated/company.js +++ b/InvenTree/templates/js/translated/company.js @@ -1,4 +1,4 @@ -{% load js_i18n %} +{% load i18n %} /* globals constructForm, diff --git a/InvenTree/templates/js/translated/filters.js b/InvenTree/templates/js/translated/filters.js index 258bbba832..349b3028ed 100644 --- a/InvenTree/templates/js/translated/filters.js +++ b/InvenTree/templates/js/translated/filters.js @@ -1,4 +1,4 @@ -{% load js_i18n %} +{% load i18n %} /* globals getAvailableTableFilters, diff --git a/InvenTree/templates/js/translated/forms.js b/InvenTree/templates/js/translated/forms.js index 3902cf5cab..fb9f422b67 100644 --- a/InvenTree/templates/js/translated/forms.js +++ b/InvenTree/templates/js/translated/forms.js @@ -1,4 +1,4 @@ -{% load js_i18n %} +{% load i18n %} {% load inventree_extras %} /* globals diff --git a/InvenTree/templates/js/translated/helpers.js b/InvenTree/templates/js/translated/helpers.js index 65a07051e4..67a6ccae7f 100644 --- a/InvenTree/templates/js/translated/helpers.js +++ b/InvenTree/templates/js/translated/helpers.js @@ -1,4 +1,4 @@ -{% load js_i18n %} +{% load i18n %} /* exported blankImage, diff --git a/InvenTree/templates/js/translated/label.js b/InvenTree/templates/js/translated/label.js index 93888f7acb..c95962e526 100644 --- a/InvenTree/templates/js/translated/label.js +++ b/InvenTree/templates/js/translated/label.js @@ -1,4 +1,4 @@ -{% load js_i18n %} +{% load i18n %} /* globals attachSelect, diff --git a/InvenTree/templates/js/translated/modals.js b/InvenTree/templates/js/translated/modals.js index 5f006f3561..ebf7a6ea61 100644 --- a/InvenTree/templates/js/translated/modals.js +++ b/InvenTree/templates/js/translated/modals.js @@ -1,4 +1,4 @@ -{% load js_i18n %} +{% load i18n %} /* globals inventreeGet, diff --git a/InvenTree/templates/js/translated/model_renderers.js b/InvenTree/templates/js/translated/model_renderers.js index a61829bb3b..7be7c2d656 100644 --- a/InvenTree/templates/js/translated/model_renderers.js +++ b/InvenTree/templates/js/translated/model_renderers.js @@ -1,4 +1,4 @@ -{% load js_i18n %} +{% load i18n %} /* globals blankImage, diff --git a/InvenTree/templates/js/translated/notification.js b/InvenTree/templates/js/translated/notification.js index cab868e1fd..fcd626fbea 100644 --- a/InvenTree/templates/js/translated/notification.js +++ b/InvenTree/templates/js/translated/notification.js @@ -1,4 +1,4 @@ -{% load js_i18n %} +{% load i18n %} /* exported loadNotificationTable, diff --git a/InvenTree/templates/js/translated/order.js b/InvenTree/templates/js/translated/order.js index 6d4e01a64d..0909c02808 100644 --- a/InvenTree/templates/js/translated/order.js +++ b/InvenTree/templates/js/translated/order.js @@ -1,4 +1,4 @@ -{% load js_i18n %} +{% load i18n %} {% load inventree_extras %} /* globals diff --git a/InvenTree/templates/js/translated/part.js b/InvenTree/templates/js/translated/part.js index f57a12afc6..1cc98fa57c 100644 --- a/InvenTree/templates/js/translated/part.js +++ b/InvenTree/templates/js/translated/part.js @@ -1,4 +1,4 @@ -{% load js_i18n %} +{% load i18n %} {% load inventree_extras %} /* globals diff --git a/InvenTree/templates/js/translated/plugin.js b/InvenTree/templates/js/translated/plugin.js index 7d3213817b..77c31e46d1 100644 --- a/InvenTree/templates/js/translated/plugin.js +++ b/InvenTree/templates/js/translated/plugin.js @@ -1,4 +1,4 @@ -{% load js_i18n %} +{% load i18n %} {% load inventree_extras %} /* globals diff --git a/InvenTree/templates/js/translated/report.js b/InvenTree/templates/js/translated/report.js index 98471d8753..eac707f804 100644 --- a/InvenTree/templates/js/translated/report.js +++ b/InvenTree/templates/js/translated/report.js @@ -1,4 +1,4 @@ -{% load js_i18n %} +{% load i18n %} /* globals attachSelect, diff --git a/InvenTree/templates/js/translated/search.js b/InvenTree/templates/js/translated/search.js index 558574fa5a..fbadaf7fe2 100644 --- a/InvenTree/templates/js/translated/search.js +++ b/InvenTree/templates/js/translated/search.js @@ -1,4 +1,4 @@ -{% load js_i18n %} +{% load i18n %} /* globals */ diff --git a/InvenTree/templates/js/translated/stock.js b/InvenTree/templates/js/translated/stock.js index 5df1be6757..35de58dd97 100644 --- a/InvenTree/templates/js/translated/stock.js +++ b/InvenTree/templates/js/translated/stock.js @@ -1,4 +1,4 @@ -{% load js_i18n %} +{% load i18n %} {% load inventree_extras %} {% load status_codes %} diff --git a/InvenTree/templates/js/translated/table_filters.js b/InvenTree/templates/js/translated/table_filters.js index d9dea01f25..c806afd4b1 100644 --- a/InvenTree/templates/js/translated/table_filters.js +++ b/InvenTree/templates/js/translated/table_filters.js @@ -1,4 +1,4 @@ -{% load js_i18n %} +{% load i18n %} {% load status_codes %} {% load inventree_extras %} diff --git a/InvenTree/templates/js/translated/tables.js b/InvenTree/templates/js/translated/tables.js index 882118e985..b65d46b283 100644 --- a/InvenTree/templates/js/translated/tables.js +++ b/InvenTree/templates/js/translated/tables.js @@ -1,4 +1,4 @@ -{% load js_i18n %} +{% load i18n %} /* global inventreeLoad,