django-js-reverse icon indicating copy to clipboard operation
django-js-reverse copied to clipboard

Support for i18n_patterns

Open rotherfuchs opened this issue 9 years ago • 5 comments

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:

  1. read the activated settings.LANGUAGES
  2. Iterate through it and use django.utils.translation.activate to activate it, just before you
  3. pass the list of RegexURLResolver to your generate_js method (which will need to accept multiple resolvers)

This will then generate all possible paths in all possible languages, which is what we want.

Cheers!

rotherfuchs avatar Feb 24 '16 12:02 rotherfuchs

see https://github.com/rotherfuchs/django-js-reverse/commit/0de96a867d4ebf715f8aa13b57bf4f1f0a94a8ad for a solution hint

rotherfuchs avatar Feb 24 '16 18:02 rotherfuchs

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.

rotherfuchs avatar Feb 24 '16 19:02 rotherfuchs

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>

ierror avatar Feb 28 '16 13:02 ierror

Yes, that would be a nice way!

rotherfuchs avatar Feb 29 '16 14:02 rotherfuchs

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

madEng84 avatar Mar 23 '16 17:03 madEng84