Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django makemessages not working for JS files

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?

like image 381
Eduard Luca Avatar asked Nov 11 '22 01:11

Eduard Luca


1 Answers

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
like image 125
Rebecca Meritz Avatar answered Nov 15 '22 09:11

Rebecca Meritz