Преглед на файлове

feat: allow splitting _() function call on multiple lines

version-14
Ankush Menat преди 3 години
родител
ревизия
29ca4d7aaa
променени са 3 файла, в които са добавени 22 реда и са изтрити 5 реда
  1. +4
    -1
      frappe/tests/test_translate.py
  2. +15
    -1
      frappe/tests/translation_test_file.txt
  3. +3
    -3
      frappe/translate.py

+ 4
- 1
frappe/tests/test_translate.py Целия файл

@@ -125,6 +125,9 @@ expected_output = [
('Warning: Unable to find {0} in any table related to {1}', 'This is some context', 15),
('Submit', 'Some DocType', 17),
("You don't have any messages yet.", None, 19),
("You don't have any messages yet.", None, 21)
("You don't have any messages yet.", None, 21),
("Long string that needs its own line because of black formatting.", None, 24),
("Long string with", "context", 28),
("Long string with", "context on newline", 32),
]


+ 15
- 1
frappe/tests/translation_test_file.txt Целия файл

@@ -18,4 +18,18 @@ _('Submit', context="Some DocType")

_("""You don't have any messages yet.""")

_('''You don't have any messages yet.''')
_('''You don't have any messages yet.''')

// allow newline in beginning
_(
"""Long string that needs its own line because of black formatting."""
).format("blah")

_(
"Long string with", context="context"
).format("blah")

_(
"Long string with",
context="context on newline"
).format("blah")

+ 3
- 3
frappe/translate.py Целия файл

@@ -24,7 +24,7 @@ from frappe.query_builder import Field, DocType
from pypika.terms import PseudoColumn

TRANSLATE_PATTERN = re.compile(
r"_\(" # starts with literal `_(` work with both python / JS
r"_\([\s\n]*" # starts with literal `_(`, ignore following whitespace/newlines

# BEGIN: message search
r"([\"']{,3})" # start of message string identifier - allows: ', ", """, '''; 1st capture group
@@ -33,7 +33,7 @@ TRANSLATE_PATTERN = re.compile(
# END: message search

# BEGIN: python context search
r"(\s*,\s*context\s*=\s*" # capture `context=` with ignoring whitespace
r"([\s\n]*,[\s\n]*context\s*=\s*" # capture `context=` with ignoring whitespace
r"([\"'])" # start of context string identifier; 5th capture group
r"(?P<py_context>((?!\5).)*)" # capture context string till closing id is found
r"\5" # match context string closure
@@ -49,7 +49,7 @@ TRANSLATE_PATTERN = re.compile(
r")*" # match one or more context string
# END: JS context search

r"\)" # Closing function call
r"[\s\n]*\)" # Closing function call ignore leading whitespace/newlines
)




Зареждане…
Отказ
Запис