|
| 1 | +--- |
| 2 | +# This file is auto-generated, please do not update manually. |
| 3 | +id: django_block_translate_trimmed |
| 4 | +title: django_block_translate_trimmed |
| 5 | +custom_edit_url: https://github.com/thibaudcolas/curlylint/edit/main/curlylint/rules/django_block_translate_trimmed/django_block_translate_trimmed.py |
| 6 | +--- |
| 7 | + |
| 8 | +import Tabs from "@theme/Tabs"; |
| 9 | +import TabItem from "@theme/TabItem"; |
| 10 | +import CodeSnippet from "@theme/CodeSnippet"; |
| 11 | + |
| 12 | +> Enforces the use of Django’s `trimmed` option when using `blocktranslate`/`blocktrans` so that translations do not contain leading or trailing whitespace. |
| 13 | +> |
| 14 | +> User impact: **Serious** |
| 15 | +
|
| 16 | +This rule supports the following configuration: |
| 17 | + |
| 18 | +<Tabs |
| 19 | + groupId="config-language" |
| 20 | + defaultValue="toml" |
| 21 | + values={[ |
| 22 | + { label: "TOML", value: "toml" }, |
| 23 | + { label: "Shell", value: "shell" }, |
| 24 | + ]} |
| 25 | +> |
| 26 | + <TabItem value="toml"> |
| 27 | + <CodeSnippet |
| 28 | + snippet={`# Template tags of blocktranslate or blocktrans must use the trimmed option\ndjango_block_translate_trimmed = true`} |
| 29 | + annotations={[]} |
| 30 | + lang="toml" |
| 31 | + /> |
| 32 | + </TabItem> |
| 33 | + <TabItem value="shell"> |
| 34 | + <CodeSnippet |
| 35 | + snippet={`# Template tags of blocktranslate or blocktrans must use the trimmed option\ncurlylint --rule 'django_block_translate_trimmed: true' .`} |
| 36 | + annotations={[]} |
| 37 | + lang="shell" |
| 38 | + /> |
| 39 | + </TabItem> |
| 40 | +</Tabs> |
| 41 | + |
| 42 | +## Success |
| 43 | + |
| 44 | +<Tabs |
| 45 | + groupId="config-language" |
| 46 | + defaultValue="toml" |
| 47 | + values={[ |
| 48 | + { label: "TOML", value: "toml" }, |
| 49 | + { label: "Shell", value: "shell" }, |
| 50 | + ]} |
| 51 | +> |
| 52 | + <TabItem value="toml"> |
| 53 | + <CodeSnippet |
| 54 | + snippet={`<!-- Good: Using blocktranslate with trimmed -->\n<!-- django_block_translate_trimmed = true -->\n{% blocktranslate trimmed %} some value {% endblocktranslate %}\n<!-- Good: Using blocktrans with trimmed -->\n<!-- django_block_translate_trimmed = true -->\n{% blocktrans trimmed %} some value {% endblocktrans %}\n<!-- Good: Using blocktranslate with trimmed and other options -->\n<!-- django_block_translate_trimmed = true -->\n{% blocktranslate trimmed with time_period=revision.created_at|timesince_simple %} some value {% endblocktranslate %}\n<!-- Good: Using blocktrans with other options -->\n<!-- django_block_translate_trimmed = true -->\n{% blocktrans trimmed with book_t=book|title %} some value {% endblocktrans %}`} |
| 55 | + annotations={[]} |
| 56 | + lang="html" |
| 57 | + /> |
| 58 | + </TabItem> |
| 59 | + <TabItem value="shell"> |
| 60 | + <CodeSnippet |
| 61 | + snippet={`<!-- Good: Using blocktranslate with trimmed -->\n<!-- curlylint --rule 'django_block_translate_trimmed: true' . -->\n{% blocktranslate trimmed %} some value {% endblocktranslate %}\n<!-- Good: Using blocktrans with trimmed -->\n<!-- curlylint --rule 'django_block_translate_trimmed: true' . -->\n{% blocktrans trimmed %} some value {% endblocktrans %}\n<!-- Good: Using blocktranslate with trimmed and other options -->\n<!-- curlylint --rule 'django_block_translate_trimmed: true' . -->\n{% blocktranslate trimmed with time_period=revision.created_at|timesince_simple %} some value {% endblocktranslate %}\n<!-- Good: Using blocktrans with other options -->\n<!-- curlylint --rule 'django_block_translate_trimmed: true' . -->\n{% blocktrans trimmed with book_t=book|title %} some value {% endblocktrans %}`} |
| 62 | + annotations={[]} |
| 63 | + lang="html" |
| 64 | + /> |
| 65 | + </TabItem> |
| 66 | +</Tabs> |
| 67 | + |
| 68 | +## Fail |
| 69 | + |
| 70 | +<Tabs |
| 71 | + groupId="config-language" |
| 72 | + defaultValue="toml" |
| 73 | + values={[ |
| 74 | + { label: "TOML", value: "toml" }, |
| 75 | + { label: "Shell", value: "shell" }, |
| 76 | + ]} |
| 77 | +> |
| 78 | + <TabItem value="toml"> |
| 79 | + <CodeSnippet |
| 80 | + snippet={`<!-- Bad: Using blocktranslate without trimmed -->\n<!-- django_block_translate_trimmed = true -->\n{% blocktranslate %} some value {% endblocktranslate %}\n<!-- Bad: Using blocktrans without trimmed -->\n<!-- django_block_translate_trimmed = true -->\n{% blocktrans %} some value {% endblocktrans %}\n<!-- Bad: Using blocktranslate without trimmed but with other options -->\n<!-- django_block_translate_trimmed = true -->\n{% blocktranslate count counter=list|length %} some value {% endblocktranslate %}\n<!-- Bad: Using blocktrans without trimmed but with other options -->\n<!-- django_block_translate_trimmed = true -->\n{% blocktrans with book_t=book|title %} some value {% endblocktrans %}\n\n`} |
| 81 | + annotations={[{"file": "test.html", "column": 1, "line": 3, "code": "django_block_translate_trimmed", "message": "`{% blocktranslate %}` must use the `trimmed` option"}, {"file": "test.html", "column": 1, "line": 6, "code": "django_block_translate_trimmed", "message": "`{% blocktrans %}` must use the `trimmed` option"}, {"file": "test.html", "column": 1, "line": 9, "code": "django_block_translate_trimmed", "message": "`{% blocktranslate count counter=list|length %}` must use the `trimmed` option"}, {"file": "test.html", "column": 1, "line": 12, "code": "django_block_translate_trimmed", "message": "`{% blocktrans with book_t=book|title %}` must use the `trimmed` option"}]} |
| 82 | + lang="html" |
| 83 | + /> |
| 84 | + </TabItem> |
| 85 | + <TabItem value="shell"> |
| 86 | + <CodeSnippet |
| 87 | + snippet={`<!-- Bad: Using blocktranslate without trimmed -->\n<!-- curlylint --rule 'django_block_translate_trimmed: true' . -->\n{% blocktranslate %} some value {% endblocktranslate %}\n<!-- Bad: Using blocktrans without trimmed -->\n<!-- curlylint --rule 'django_block_translate_trimmed: true' . -->\n{% blocktrans %} some value {% endblocktrans %}\n<!-- Bad: Using blocktranslate without trimmed but with other options -->\n<!-- curlylint --rule 'django_block_translate_trimmed: true' . -->\n{% blocktranslate count counter=list|length %} some value {% endblocktranslate %}\n<!-- Bad: Using blocktrans without trimmed but with other options -->\n<!-- curlylint --rule 'django_block_translate_trimmed: true' . -->\n{% blocktrans with book_t=book|title %} some value {% endblocktrans %}\n\n`} |
| 88 | + annotations={[{"file": "test.html", "column": 1, "line": 3, "code": "django_block_translate_trimmed", "message": "`{% blocktranslate %}` must use the `trimmed` option"}, {"file": "test.html", "column": 1, "line": 6, "code": "django_block_translate_trimmed", "message": "`{% blocktrans %}` must use the `trimmed` option"}, {"file": "test.html", "column": 1, "line": 9, "code": "django_block_translate_trimmed", "message": "`{% blocktranslate count counter=list|length %}` must use the `trimmed` option"}, {"file": "test.html", "column": 1, "line": 12, "code": "django_block_translate_trimmed", "message": "`{% blocktrans with book_t=book|title %}` must use the `trimmed` option"}]} |
| 89 | + lang="html" |
| 90 | + /> |
| 91 | + </TabItem> |
| 92 | +</Tabs> |
| 93 | + |
| 94 | +## Resources |
| 95 | + |
| 96 | +- [Django translations](https://docs.djangoproject.com/en/stable/topics/i18n/translation/) |
0 commit comments