mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +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:
parent
d2d59e0709
commit
f396642d16
@ -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
|
||||
|
||||
|
@ -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:
|
@ -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):
|
||||
|
9
tasks.py
9
tasks.py
@ -292,23 +292,24 @@ def translate_stats(c):
|
||||
|
||||
|
||||
@task(post=[translate_stats])
|
||||
def translate(c):
|
||||
def translate(c, ignore_static=False, no_frontend=False):
|
||||
"""Rebuild translation source files. Advanced use only!
|
||||
|
||||
Note: This command should not be used on a local install,
|
||||
it is performed as part of the InvenTree translation toolchain.
|
||||
"""
|
||||
# Translate applicable .py / .html / .js / .tsx files
|
||||
# Translate applicable .py / .html / .js files
|
||||
manage(c, 'makemessages --all -e py,html,js --no-wrap')
|
||||
manage(c, 'compilemessages')
|
||||
|
||||
if node_available():
|
||||
if not no_frontend and node_available():
|
||||
frontend_install(c)
|
||||
frontend_trans(c)
|
||||
frontend_build(c)
|
||||
|
||||
# Update static files
|
||||
static(c)
|
||||
if not ignore_static:
|
||||
static(c)
|
||||
|
||||
|
||||
@task
|
||||
|
Loading…
Reference in New Issue
Block a user