OrderingFilter: internationalization for "(descending)" doesn't work
jnns opened this issue · comments
This is an example ordering filter in a fresh Django project using Django 4.1.6 and django-filter-22.1. With LANGUAGE_CODE
set to el
, de
and pl
it shows that translations from django.po
files are applied as expected, but the "(descending)" part is always in English.
Interestingly, there's a test for this particular translation and it passes just fine: test.test_filters.test_translation_default_label
.
I wrote a parametrized test to see if it was just a problem with my particular django.mo
file but it also passes with all available languages:
# django-filter/tests/test_filters.py
from pathlib import Path
LANGUAGES = [
f.name
for f in (Path(__file__).parents[1] / "django_filters" / "locale").iterdir()
if f.is_dir()
]
class OrderingFilterTests(TestCase):
def test_translation_descending_label(self):
for lang in LANGUAGES:
with self.subTest(lang=lang), translation.override(lang):
f = OrderingFilter(fields=["username"])
label = dict(list(f.field.choices))["-username"]
last_word = label.split()[-1]
self.assertNotEqual(last_word, "(descending)")
if lang == "de":
self.assertEqual(last_word, "(absteigend)")
I don't understand why the tests pass but the real application fails. Can you reproduce this issue? Do you know what's wrong with the internationalization here?
Thanks for the report. Immediately I can't say what's going on.
I am planning a release to coincide with Django 4.2 so if you're able to dig more I'm happy to take a fix.
Oh, maybe, did the label get cached before the translations were activated? (That's caused a stumble in the past)
Thank you, Carlton. I will take a second look at it on the weekend.