Support for i18n_patterns
Hi,
I'd love to use your fantastic plugin; however, it currently does not seem to support i18n.
In my case, I use django.conf.urls.i18n.i18n_patterns in my url, which will give me a url like /en/foo/bar, where the first part is the language code.
django-js-reverse seems to not take the current language into account, as I receive this Url instead: /None/foo/bar'.
The way to go would IMHO be:
- read the activated
settings.LANGUAGES - Iterate through it and use
django.utils.translation.activateto activate it, just before you - pass the list of
RegexURLResolverto yourgenerate_jsmethod (which will need to accept multiple resolvers)
This will then generate all possible paths in all possible languages, which is what we want.
Cheers!
see https://github.com/rotherfuchs/django-js-reverse/commit/0de96a867d4ebf715f8aa13b57bf4f1f0a94a8ad for a solution hint
Next challenge would be to detect the current language and pick the proper format from the list. One way would be to create one file per language.
Thanks for contributing!
One way would be to create one file per language.
Another solution could be adding a variable on page load:
{% load i18n %}
{% get_current_language as LANGUAGE_CODE %}
<html>
<script>
Urls._set_language(LANGUAGE_CODE);
</script>
<html>
Yes, that would be a nice way!
Hi all, Any update about this topic? I want to integrate django-js-reverse in my multilanguage project but I don't know if pip version of this package supports multilanguage. Thanks