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
This commit is contained in:
Oliver 2022-06-24 13:37:35 +10:00
parent d13eb84448
commit 473ec9586c
24 changed files with 53 additions and 34 deletions

View File

@ -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)

View File

@ -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)

View File

@ -1,4 +1,4 @@
{% load js_i18n %}
{% load i18n %}
/* globals
*/

View File

@ -1,4 +1,4 @@
{% load js_i18n %}
{% load i18n %}
{% load inventree_extras %}
/* globals

View File

@ -1,4 +1,4 @@
{% load js_i18n %}
{% load i18n %}
/* globals
makeIconButton,

View File

@ -1,4 +1,4 @@
{% load js_i18n %}
{% load i18n %}
/* globals
imageHoverIcon,

View File

@ -1,4 +1,4 @@
{% load js_i18n %}
{% load i18n %}
/* globals
constructForm,

View File

@ -1,4 +1,4 @@
{% load js_i18n %}
{% load i18n %}
{% load inventree_extras %}
/* globals

View File

@ -1,4 +1,4 @@
{% load js_i18n %}
{% load i18n %}
/* globals
constructForm,

View File

@ -1,4 +1,4 @@
{% load js_i18n %}
{% load i18n %}
/* globals
getAvailableTableFilters,

View File

@ -1,4 +1,4 @@
{% load js_i18n %}
{% load i18n %}
{% load inventree_extras %}
/* globals

View File

@ -1,4 +1,4 @@
{% load js_i18n %}
{% load i18n %}
/* exported
blankImage,

View File

@ -1,4 +1,4 @@
{% load js_i18n %}
{% load i18n %}
/* globals
attachSelect,

View File

@ -1,4 +1,4 @@
{% load js_i18n %}
{% load i18n %}
/* globals
inventreeGet,

View File

@ -1,4 +1,4 @@
{% load js_i18n %}
{% load i18n %}
/* globals
blankImage,

View File

@ -1,4 +1,4 @@
{% load js_i18n %}
{% load i18n %}
/* exported
loadNotificationTable,

View File

@ -1,4 +1,4 @@
{% load js_i18n %}
{% load i18n %}
{% load inventree_extras %}
/* globals

View File

@ -1,4 +1,4 @@
{% load js_i18n %}
{% load i18n %}
{% load inventree_extras %}
/* globals

View File

@ -1,4 +1,4 @@
{% load js_i18n %}
{% load i18n %}
{% load inventree_extras %}
/* globals

View File

@ -1,4 +1,4 @@
{% load js_i18n %}
{% load i18n %}
/* globals
attachSelect,

View File

@ -1,4 +1,4 @@
{% load js_i18n %}
{% load i18n %}
/* globals
*/

View File

@ -1,4 +1,4 @@
{% load js_i18n %}
{% load i18n %}
{% load inventree_extras %}
{% load status_codes %}

View File

@ -1,4 +1,4 @@
{% load js_i18n %}
{% load i18n %}
{% load status_codes %}
{% load inventree_extras %}

View File

@ -1,4 +1,4 @@
{% load js_i18n %}
{% load i18n %}
/* global
inventreeLoad,