8

I keep ending up with an empty catalog in my jsi18n JavaScript. I have tried all the solutions on StackOverflow including Empty catalog when internationalizing JavaScript code, but the catalog is still empty.

My setup is this:

project_dir
- locale
  - nl (contains LC_MESSAGES with django.po and djangojs.po)
- app1
- app2
- main_app
  - settings.py
  - urls.py
  - wsgi.py

In settings.py I have

# Where to find locale
LOCALE_PATHS = (
    os.path.join(SITE_ROOT, 'locale'),
)

SITE_ROOT is the absolute path to my project dir, so this translates to

In urls.py I have

# i18n
js_info_dict = {
    'domain': 'djangojs',
    'packages': ('wrnpro', ),
}

and

    (r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),

as part of my urls.

If I run the app and call http://localhost:8000/jsi18n/ I get

/* gettext library */
var catalog = new Array();
function pluralidx(count) { return (count == 1) ? 0 : 1; }
… 

So far I have tried every variation of settings etc. I could find, but the catalog remains empty.

When running make messages and compile messages my JavaScript get text strings are found and translated. The django.po and .mo files are in the locale directory.

Anyone?

Community
  • 1
  • 1
dyve
  • 5,893
  • 2
  • 30
  • 44
  • None of the suggestions seemed to work. I left it alone for a week or so, installed several updates to almost everything, and when I sat down on a Friday morning to finally get rid of this problem, it had fixed itself. Completely flabbergasted I saw that JavaScript translations were now working, and they have been working since. I have no idea what triggered this. My locale directory is still on project level. – dyve Jan 03 '13 at 11:36

3 Answers3

5

This is what ended up working for me:

js_info_dict = {
   'domain': 'django',
   'packages': None,
}

urlpatterns = [
    url(r'^jsi18n/$', javascript_catalog, js_info_dict, name='javascript-catalog'),
    # ...
]

Still not working? Troubleshooting tips:

I don't know particularly why this works, but I can tell you how I found out how to make it work. If you use the same troubleshooting technique, maybe you'll find a way too. I used Python debugger, like this:

def javascript_catalog_pdb(*args, **kwargs):
    import pdb
    pdb.set_trace()
    return javascript_catalog(*args, **kwargs)

url_patterns = [
    url(r'^jsi18n/$', javascript_catalog_pdb, js_info_dict, name='javascript-catalog'),
    ...
]

Then using PDB, I stepped into javascript_catalog, until I got to the line:

catalog, plural = get_javascript_catalog(locale, domain, packages)

I then experimented with different values for domain and packages, right there in the debugger, until I discovered the values I needed.

Flimm
  • 136,138
  • 45
  • 251
  • 267
3

I had the same problem and when I moved my locale directory from my project folder to my app folder it worked, so it seems makemessages needs to be run at the app level. I don't think you will need LOCALE_PATHS in your settings file.

Nilesh
  • 20,521
  • 16
  • 92
  • 148
Paul
  • 31
  • 2
2

For the language of your current user, do you have any completed translations, or do you just have stubs? The catalogue will only contain values for strings which have actually been translated.

ie, if you have this in your english po file:

#: static/js/events.js:159
msgid "Open side panel"
msgstr ""

Nothing will appear in the catalogue (if you're accessing it in english). But if you have this:

#: static/js/events.js:159
msgid "Open side panel"
msgstr "Open side panel"

Then there will be.

Andrew Ingram
  • 5,160
  • 2
  • 25
  • 37
  • I have 100% translation on both the django and djanojs catalog, I translate from English (en) to Dutch (nl). – dyve Nov 07 '12 at 10:59