Skip to content

Commit

Permalink
fix(formatter): fixed formatting of plural tag in blocktrans
Browse files Browse the repository at this point in the history
thanks @timoludwig

closes #641
  • Loading branch information
christopherpickering committed May 11, 2023
1 parent 30f8d31 commit 92c083b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/djlint/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ def __init__(

# these tags should be unindented and next line will be indented
self.tag_unindent_line: str = r"""
(?:\{%-?[ ]*?(?:elif|else|empty))
(?:\{%-?[ ]*?(?:elif|else|empty|plural))
| (?:
\{\{[ ]*?
(
Expand Down Expand Up @@ -675,6 +675,7 @@ def __init__(
| block(?!trans)
| endblock(?!trans)
| else
| plural
| spaceless
| endspaceless
| compress
Expand Down
15 changes: 15 additions & 0 deletions tests/test_django/test_blocktrans.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,21 @@
),
id="blocktrans_autoescape_two",
),
pytest.param(
(
"{% blocktranslate count counter=list|length %}\n"
"There is only one {{ name }} object.\n"
" {% plural %} There are {{ counter }} {{ name }} objects.\n"
"{% endblocktranslate %}\n"
),
(
"{% blocktranslate count counter=list|length %}\n"
"There is only one {{ name }} object.\n"
" {% plural %} There are {{ counter }} {{ name }} objects.\n"
"{% endblocktranslate %}\n"
),
id="plural not formatted",
),
]


Expand Down
25 changes: 21 additions & 4 deletions tests/test_django/test_blocktrans_trimmed.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@
" (\n"
" {% blocktranslate count counter=images|length trimmed %}\n"
" {{ counter }} photo\n"
" {% plural %}\n"
" {% plural %}\n"
" {{ counter }} photos\n"
" {% endblocktranslate %}\n"
" )\n"
" (\n"
" {% blocktrans count counter=images|length trimmed %}\n"
" {{ counter }} photo\n"
" {% plural %}\n"
" {% plural %}\n"
" {{ counter }} photos\n"
" {% endblocktrans %}\n"
" )\n"
Expand Down Expand Up @@ -156,15 +156,15 @@
" (\n"
" {% blocktranslate count counter=images|length trimmed %}\n"
" {{ counter }} photo\n"
" {% plural %}\n"
" {% plural %}\n"
" asdf\n"
" {{ counter }} photos\n"
" {% endblocktranslate %}\n"
" )\n"
" (\n"
" {% blocktrans count counter=images|length trimmed %}\n"
" {{ counter }} photo\n"
" {% plural %}\n"
" {% plural %}\n"
" {{ counter }} photos\n"
" {% endblocktrans %}\n"
" )\n"
Expand Down Expand Up @@ -254,6 +254,23 @@
({"max_line_length": 10}),
id="blocktrans_autoescape_two",
),
pytest.param(
(
"{% blocktranslate count counter=list|length trimmed %}\n"
"There is only one {{ name }} object.\n"
" {% plural %} There are {{ counter }} {{ name }} objects.\n"
"{% endblocktranslate %}\n"
),
(
"{% blocktranslate count counter=list|length trimmed %}\n"
" There is only one {{ name }} object.\n"
"{% plural %}\n"
" There are {{ counter }} {{ name }} objects.\n"
"{% endblocktranslate %}\n"
),
({}),
id="plural formatted",
),
]


Expand Down

0 comments on commit 92c083b

Please sign in to comment.