2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 12:35:46 +00:00

Fix escape codes in translated strings (#6234)

* Fix escape codes in translated strings

- Only add escape characters for javascript files

* import fix

* more import fix
This commit is contained in:
Oliver
2024-01-14 13:29:36 +11:00
committed by GitHub
parent d2d59e0709
commit f396642d16
7 changed files with 16 additions and 11 deletions

View File

@ -17,7 +17,7 @@ import users.models
from InvenTree.filters import SEARCH_ORDER_FILTER
from InvenTree.mixins import ListCreateAPI
from InvenTree.permissions import RolePermission
from part.templatetags.inventree_extras import plugins_info
from InvenTree.templatetags.inventree_extras import plugins_info
from plugin.serializers import MetadataSerializer
from users.models import ApiToken

View File

@ -41,9 +41,12 @@ class CustomTranslateNode(TranslateNode):
for c in ['\\', '`', ';', '|', '&']:
result = result.replace(c, '')
# Escape any quotes contained in the string
result = result.replace("'", r'\'')
result = result.replace('"', r'\"')
# Escape any quotes contained in the string, if the request is for a javascript file
request = context.get('request', None)
if request and request.path.endswith('.js'):
result = result.replace("'", r'\'')
result = result.replace('"', r'\"')
# Return the 'clean' resulting string
return result
@ -52,9 +55,10 @@ class CustomTranslateNode(TranslateNode):
@register.tag('translate')
@register.tag('trans')
def do_translate(parser, token):
"""Custom translation function, lifted from https://github.com/django/django/blob/main/django/templatetags/i18n.py.
"""Custom translation function.
The only difference is that we pass this to our custom rendering node class
- Lifted from https://github.com/django/django/blob/main/django/templatetags/i18n.py.
- The only difference is that we pass this to our custom rendering node class
"""
bits = token.split_contents()
if len(bits) < 2:

View File

@ -18,6 +18,7 @@ from common.models import (
)
from common.notifications import UIMessageNotification, storage
from InvenTree import version
from InvenTree.templatetags import inventree_extras
from InvenTree.unit_test import InvenTreeTestCase
from .models import (
@ -30,7 +31,6 @@ from .models import (
PartTestTemplate,
rename_part_image,
)
from .templatetags import inventree_extras
class TemplateTagTest(InvenTreeTestCase):