2

Hi I have a problem with JS translation in Django. I did everything like is said in documentation, so: I made .po then .mo files (django.mo, djangojs.mo). Translated files are in path: *myapp/locale/pl/LC_MESSAGES/* and *myapp/locale/en/LC_MESSAGES/* Translations in .html and .py files work OK. The only problem is that JS translation always displays original phrase, not translated. main urls.py:

urlpatterns += patterns('', (r'^jsi18n/$', 'django.views.i18n.javascript_catalog',{}), )

template file in header (as first JS part):

<script type="text/javascript" src="{% url django.views.i18n.javascript_catalog %}"></script>

All my js files are in path /myapp/site_media/js/ and the only .mo files are in path which I wrote before. I use gettext() in JS strings.

What did I do wrong?

3
  • what do you see when direct you browser at your.site/jsi18n ?
    – seriyPS
    Sep 5, 2011 at 17:40
  • have the same problem, my jsi18n is dpaste.com/755946 - as you can see, only django strings are translated
    – alekwisnia
    Jun 6, 2012 at 12:25
  • can you provide an example of a file with an indicated js translation? JS translatables must be in a .js file, if not you should use the {% trans %} tag. Mar 9, 2017 at 9:46

1 Answer 1

2

To use the jsi18n view you have 2 options:

  1. Specify the desired translation packages in the dict passed to the view, which will be combined (you've specified an empty dict - hence no packages)
  2. Catch the packages parameter in the url pattern, and specify the package names in the url, separated with +.

This is described in the javascript_catalog documentation. Maybe you've missed it. I suggest taking another look:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.