Can I use i18n_patterns from a module ?

Hi !

I have a module where some urls have to be prefixed by the country code and other urls must not be prefixed by country code.

In the project urls.py, the module is included with path “”.

It looks like i18n_patterns() cannot be called from the module urls.py :
django.core.exceptions.ImproperlyConfigured: Using i18n_patterns in an included URLconf is not allowed.

So can I declare two lists of urls in one module ? So I can apply i18n_patterns() on one from the project urls.py ?

Or is there a better way to do this ?

Thank you !

I ended up in creating a new file locale_urls.py where the localized URLs are defined.

And then, in the project urls.py :

urlpatterns = [
    path("", include("my_module.urls")),
]

urlpatterns += i18n_patterns(
    path("", include("my_module.locale_urls")),
)

So far, this is working unless a small issue when calling resolve() : it looks like URLs defined in locale_urls.py are not taken into account.