Skip to content

Commit 55eead8

Browse files
fix(i18n): keep python-format on messages with escaped %%
1 parent 0e893c8 commit 55eead8

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

‎scripts/translations/literal_percent.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@
4848
)
4949

5050
# A percent sign followed by a space and a word, as in "% of" or "50% off".
51-
# A real space-flag directive ("% d") is never followed by more letters.
52-
_LITERAL_PERCENT = re.compile(r"% (?=[A-Za-z]{2})")
51+
# A real space-flag directive ("% d") is never followed by more letters, and
52+
# the second "%" of a "%%" escape is part of a real format string.
53+
_LITERAL_PERCENT = re.compile(r"(?<!%)% (?=[A-Za-z]{2})")
5354

5455

5556
def is_literal_percent(*msgids: str) -> bool:

‎tests/unit_tests/scripts/translations/literal_percent_test.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ def test_is_literal_percent_accepts_percent_followed_by_a_word(msgid: str) -> No
6666
"%(name)s: % of total",
6767
# A bare space-flag directive is not followed by a word.
6868
"% d",
69+
# An escaped "%%" means the string is %-formatted.
70+
"Up 50%% today",
71+
"50%% of rows",
6972
# Not a "% word" pattern, so out of this check's scope.
7073
"Contains text (ILIKE %x%)",
7174
],

0 commit comments

Comments
 (0)