Skip to content

Commit

Permalink
Fix escape codes in translated strings (#6234)
Browse files Browse the repository at this point in the history
* Fix escape codes in translated strings

- Only add escape characters for javascript files

* import fix

* more import fix
  • Loading branch information
SchrodingersGat committed Jan 14, 2024
1 parent d2d59e0 commit f396642
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion InvenTree/InvenTree/api.py
Expand Up @@ -17,7 +17,7 @@
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

Expand Down
File renamed without changes.
Expand Up @@ -41,9 +41,12 @@ def render(self, context):
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
Expand All @@ -52,9 +55,10 @@ def render(self, context):
@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:
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion InvenTree/part/test_part.py
Expand Up @@ -18,6 +18,7 @@
)
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 (
Expand All @@ -30,7 +31,6 @@
PartTestTemplate,
rename_part_image,
)
from .templatetags import inventree_extras


class TemplateTagTest(InvenTreeTestCase):
Expand Down
9 changes: 5 additions & 4 deletions tasks.py
Expand Up @@ -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
Expand Down

0 comments on commit f396642

Please sign in to comment.