Django 5 translate route with param

I have troubles to translate properly a route that needs a param. this works fine if the uri has /fr/ or /en/:

urlpatterns = [
    path(_('CATEGORY'), views.category, name='app-category'),
]

But as long as I need to add a param like:

urlpatterns = [
    path(f"{_('CATEGORY')}/<slug:uuid>", views.category, name='app-category'),
]

or

urlpatterns = [
    path(_('CATEGORY') + "/<slug:uuid>", views.category, name='app-category'),
]

The translation stuck with 'category' so the route /fr/categorie/ is not working. _('CATEGORY') = 'categorie' for fr or 'category' for en.

Any idea about how to bypass the issue? Thanks

Have you tried making a custom URL dispatcher to return a view depending on the language?

https://docs.djangoproject.com/en/5.1/topics/http/urls/#registering-custom-path-converters

Вернуться на верх