Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django JavaScript translation empty catalog (i18n/jsi18n) [closed]

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?

like image 501
dyve Avatar asked Nov 07 '12 10:11

dyve


1 Answers

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.

like image 126
Flimm Avatar answered Sep 24 '22 02:09

Flimm