Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [Formatter] django blocktranslate wrong indentation #493

Closed
vasekch opened this issue Dec 19, 2022 · 6 comments · Fixed by #581
Closed

[BUG] [Formatter] django blocktranslate wrong indentation #493

vasekch opened this issue Dec 19, 2022 · 6 comments · Fixed by #581
Labels

Comments

@vasekch
Copy link

vasekch commented Dec 19, 2022

possible regression of #26

djlint, version 1.19.7

Issue

Something is wrong with blocktranslate formatting, {% endblocktranslate %} is not properly indented.

Code example - desired state

<div>
    <span>
        {% translate "View all" %}
        <br />
        ({% blocktranslate count counter=images|length trimmed %}
            {{ counter }} photo
            {% plural %}
            {{ counter }} photos
        {% endblocktranslate %})
        <br/>
        <span>remark</span>
    </span>
</div>

Formatter output

<div>
    <span>
        {% translate "View all" %}
        <br />
        ({% blocktranslate count counter=images|length trimmed %}
            {{ counter }} photo
            {% plural %}
            {{ counter }} photos
{% endblocktranslate %})
        <br/>
        <span>remark</span>
    </span>
</div>

The example uses complex version of blocktranslate, but result is the same even if I remove count/trimmed args. Also wrapping content brackets (, ) don't seem to play any role in this issue. see the comment

Current workaround is to wrap all code in djlint:off.

Thank you for djLint 💚!


@vasekch vasekch added 🦠 bug Something isn't working 🧽 formatter labels Dec 19, 2022
@vasekch
Copy link
Author

vasekch commented Dec 19, 2022

Ha! My bad.

It is the closing bracket after the end tag {% endblocktranslate %}). If removed all works as it should.

I got confused by the fact that I need to put all spaces in front of endblocktranslate manually as they are part of not formatted content.

I guess in my case the most elegant solution is to put brackets into the translation itself and let blocktranslate start/end tags on separate lines.

I'm not sure if having any content after end tag is in favor of djLint formatting strategy. Feel free to close.

@vasekch
Copy link
Author

vasekch commented Dec 19, 2022

Putting simple space at the end of the line with {% endblocktranslate %} also breaks the indent after formatting, so I think it is the issue.

@christopherpickering
Copy link
Contributor

Hmm, good issue. We can probably get it fixed. In v2, I think will not be an issue, but for now we can probably fix it up.

@christopherpickering
Copy link
Contributor

@vasekch sorry for the delay on this :) I'm going to release an update that allows closing {% endblocktrans...%} tags to be indented if they have a leading space.

@christopherpickering
Copy link
Contributor

commit d667273 fixes this issue.

@christopherpickering
Copy link
Contributor

🎉 This issue has been resolved in version 1.19.17 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants