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

OrderingFilter: internationalization for "(descending)" doesn't work #1556

Open
jnns opened this issue Feb 1, 2023 · 3 comments
Open

OrderingFilter: internationalization for "(descending)" doesn't work #1556

jnns opened this issue Feb 1, 2023 · 3 comments

Comments

@jnns
Copy link
Contributor

jnns commented Feb 1, 2023

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.

Bildschirmfoto vom 2023-02-01 10-00-01

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?

@carltongibson
Copy link
Owner

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.

@carltongibson
Copy link
Owner

Oh, maybe, did the label get cached before the translations were activated? (That's caused a stumble in the past)

@jnns
Copy link
Contributor Author

jnns commented Feb 1, 2023

Thank you, Carlton. I will take a second look at it on the weekend.

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

No branches or pull requests

2 participants