5

My setup

settings.py

INSTALLED_APPS = (
    ...
    'myprojectname',
    ...
)

STATIC_ROOT = '/var/www/a_valid_path/'

LOCALE_PATHS = (
    os.path.join(BASE_DIR, "locale"),
)

urls.py

js_info_dict = {
    'domain': 'djangojs',
    'packages': ('myprojectname',),
}

urlpatterns = patterns('',
    ...
    url(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
    ...
)

My project structure is as follows:

|- projectname
|--- app1
|--- app2
|--- manage.py
|- virtualenv
|- static
|--- js
|--- css

I also have the locale folder in the root folder of my project, where manage.py is located.

What I'm doing

Simply running:

./manage.py -l ro -d djangojs

My problem

It's not working. No .po file is being generated. Server-side translation works, however (views + templates). I've followed all advice, and still nothing. Even tried to create the djangojs.po file myself to see if Django deletes it, or does something with it -- nope.

No error is generated, just processing locale ro is shown (for a really short time -- too short if you ask me), and that's that. Any help?

Edit: Forgot to mention that my folder containing the JS files is not inside each Django app, but in a separate location. Still, shouldn't Django look inside the STATICFILES_DIRS?

Eduard Luca
  • 6,514
  • 16
  • 85
  • 137

4 Answers4

1

Django's makemessages only will make messages from files that are in on one of your TEMPLATE_DIRS. So any files you want to translate need to be in one of those directories.

You can do that in one several ways:

  • Place the *.js files in one of your TEMPLATE_DIRS as is
  • In-lining your JS in the html files
  • Place all the strings that need translation in data-attributes on the dom and grab them from the dom via JS
Rebecca Meritz
  • 722
  • 1
  • 5
  • 15
  • Yes, templates are working, but your solution is not an option, because it would create a huge overhead at this point in the application. – Eduard Luca Oct 01 '14 at 12:52
  • Another (messier) option would be to inline the JS in the html files. – Rebecca Meritz Oct 02 '14 at 09:35
  • I think only the translation only looking in the TEMPLATE_DIRS set in your setting file. So if you want your js files translated they need to be in a file in one of your TEMPLATE_DIRS. – Rebecca Meritz Oct 02 '14 at 09:38
  • You are completely right. I tried moving one of the JS files to the templates dir, and it worked. Would you by any chance know how to set it to look in my static folder too? – Eduard Luca Oct 02 '14 at 11:22
  • 1
    Also, if you'd kindly edit your answer with the info in the comments (regarding `TEMPLATE_DIRS`), I'd gladly accept it and award the bounty. – Eduard Luca Oct 03 '14 at 12:27
0
  1. Are you running makemessages from a directory parent of the ones containing your JavaScript files?
  2. Do your JavaScript file names ends with a .js?
  3. Do you either use django.gettext('string') or _('string') to mark strings requiring translations?
Simon Charette
  • 5,009
  • 1
  • 25
  • 33
  • 1. Nope. As far as I can see, Django only looks in the current directory (wherever you run `django-admin.py` or `manage.py` from), which is not ideal. I can't run the command one level higher, because that's where I have my virtualenv and lots of other stuff. 2. Yes. 3. I'm using `gettext`, since that's what the examples in the docs use. If I run `manage.py` from my JS dir, it works. – Eduard Luca Oct 08 '14 at 07:00
0

I've experienced the same issue. I've discovered that the issue is reported in the Django ticket #23717: https://code.djangoproject.com/ticket/23717

Fixes are in upcoming stable 1.7.2 version: https://docs.djangoproject.com/en/1.7/releases/1.7.2/

I've installed 1.7.2 and confirmed that the issue is fixed.

Waldir Leoncio
  • 10,853
  • 19
  • 77
  • 107
stefanos
  • 73
  • 5
0

I had the same problem when using the Django i18n, after many times trying, I finally got the correct answer: we need to put the .js files into the project directory, which was specified when we assign 'js_info_dict'.
But usually we put the JavaScript files in the same level catalog as project, so there is the problem. (we don't need to put the JavaScript files into templates directory).

geisterfurz007
  • 5,292
  • 5
  • 33
  • 54
s Ray
  • 1