Opened 2 months ago
Last modified 2 months ago
#36579 assigned Cleanup/optimization
yesno filter broken for translations that do not respect the ascii comma
| Reported by: | Klaas van Schelven | Owned by: | Klaas van Schelven |
|---|---|---|---|
| Component: | Template system | Version: | dev |
| Severity: | Normal | Keywords: | yesno |
| Cc: | Claude Paroz | Triage Stage: | Accepted |
| Has patch: | yes | Needs documentation: | yes |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
2 related problems:
1: Some languages do not translate the "yes,no,maybe" string including comma's
$ find -name "*.po" | x grep yes,no,maybe -A1 | grep msgstr | grep -v , | grep -v '""' ./django/conf/locale/km/LC_MESSAGES/django.po-msgstr "យល់ព្រម មិនយល់ព្រម ប្រហែល" ./django/conf/locale/zh_Hant/LC_MESSAGES/django.po-msgstr "是、否、也許" ./django/conf/locale/fa/LC_MESSAGES/django.po-msgstr "بله،خیر،شاید" ./django/conf/locale/ur/LC_MESSAGES/django.po-msgstr "ھاں،نہیں،ھوسکتاہے" ./django/conf/locale/ug/LC_MESSAGES/django.po-msgstr "ھەئە، ياق، بەلكىىم" ./django/conf/locale/ckb/LC_MESSAGES/django.po-msgstr "بەڵێ،نەخێر،لەوانەیە" ./django/conf/locale/zh_Hans/LC_MESSAGES/django.po-msgstr "是、否、也许"
- the filter returns the value when the arg is incorrect: https://github.com/django/django/blob/main/django/template/defaultfilters.py#L881
IMHO this is wrong, because it breaks the Maybe(bool) => str type of the function. For the broken arg, it should either:
[a] override the arg to the default "yes,no,maybe"
[b] raise an exception
these 2 things combined make it so that when any of the broken languages is activated, the filter is broken. Consider e.g. yesno(True).capitalize() which will now raise an exception in Chinese.
Change History (11)
comment:1 by , 2 months ago
comment:2 by , 2 months ago
Thank you Klaas van Schelven! Your report makes sense but ideally we would need clear instructions in how to reproduce. Would you be able to provide a failing test case? That would certainly help us with the triage.
comment:3 by , 2 months ago
I've provided a failing test-case which I've then fixed, https://github.com/django/django/pull/19791
As per the PR: that's part of the work; I will leave fixing of the translations to the people who are on that platform (I am not and I don't want to go out of my way to create an account there).
comment:4 by , 2 months ago
| Component: | Uncategorized → Template system |
|---|---|
| Keywords: | yesno added |
| Owner: | set to |
| Status: | new → assigned |
| Triage Stage: | Unreviewed → Accepted |
| Type: | Uncategorized → Cleanup/optimization |
Thank you! The PR certainly helps understanding your goal.
I agree we should return a safe string as default and we should also fix the translations. I'll do the later and review your PR soon.
comment:5 by , 2 months ago
| Summary: | yesno filter broken for some languages → yesno filter broken for translations that do not respect the ascii comma |
|---|
comment:6 by , 2 months ago
| Has patch: | set |
|---|
comment:7 by , 2 months ago
I have updated all translations, the next time we fetch updated translations into Django, these will be available.
comment:8 by , 2 months ago
| Cc: | added |
|---|
Claude, would you have ideas in how we could prevent this issue with the (lack of) ascii commas in the future?
comment:9 by , 2 months ago
| Patch needs improvement: | set |
|---|
comment:10 by , 2 months ago
| Needs documentation: | set |
|---|---|
| Patch needs improvement: | unset |
comment:11 by , 2 months ago
I guess I would:
- make the translator comment clearer about using ascii commas
- program a check in the
manage_translations.pyscript
Looked at this a bit more.
The “missing comma” issue seems to have two causes across translations:
So: