djlint / djLint

✨ HTML Template Linter and Formatter. Django - Jinja - Nunjucks - Handlebars - GoLang
https://djLint.com
GNU General Public License v3.0
686 stars 84 forks source link

[FEATURE] Move 'trans' template tag to 'translate' in django templates #770

Closed frague59 closed 8 months ago

frague59 commented 1 year ago

Feature Request

From django docs, I can see the trans template tag has been renamed to translate from django 3.1.

https://docs.djangoproject.com/en/3.2/topics/i18n/translation/#translate-template-tag

The blocktrans has been moved to blocktranslate too.

Is it possible djLint warn users about these namings ?

Thanks! 🤠

ronanboiteau commented 8 months ago

Hey @frague59! If you have already refactored your code base to use the new names, you can use a .djlint_rules.yaml file to create rules to find the outdated tags and trigger errors. Something like this:

- rule:
    name: CR01
    message: Deprecated template tag 'trans' found. Use 'translate' instead.
    flags: re.DOTALL
    patterns:
      - \{% *trans +
- rule:
    name: CR02
    message: Deprecated template tag 'blocktrans' found. Use 'blocktranslate' instead.
    flags: re.DOTALL
    patterns:
      - \{% *blocktrans +
- rule:
    name: CR03
    message: Deprecated template tag 'endblocktrans' found. Use 'endblocktranslate' instead.
    flags: re.DOTALL
    patterns:
      - \{% *endblocktrans *%}

More details about custom rules: https://djlint.com/docs/linter/

frague59 commented 8 months ago

Thanks for your answer, I'll put this into my projects.