tags:

views:

139

answers:

2

From django documentation:

js_info_dict = { 'packages': ('your.app.package',), }

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

Each string in packages should be in Python dotted-package syntax (the same format as the strings in INSTALLED_APPS) and should refer to a package that contains a locale directory.

It says "a package that contains a locale directory." , but i created translation files with djangoadmin.py makemessages -a and it creates locale just inside project directory. Not under any of my application directories. And i try to set packages as

js_info_dict = { 'packages': ('my_project_dir',), }

Apparently that's not working for me. Every string from django domain gets translated but i get an empty translation catalog in javascript from javascript_catalog view. What am i missing here?

+1  A: 

Try adding 'my_project_dir' to INSTALLED_APPS in settings.py

daonb
Hi, I have the same problem. What do you mean with that adding project name to INSTALLED_APPS?
pocoa
Yeah, it has to solve the problem, but it doesn't. http://code.djangoproject.com/attachment/ticket/5494/root-locale-js-catalog.diff
pocoa
The patch on that ticket is cleaner than adding the project to INSTALLED_APP. Still, it solved the problem in my project.
daonb
A: 

First you need to be sure that your js_info_dict is like this:

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

And as @daonb suggested, add 'my_project_name' to your INSTALLED_APPS in settings.py.

Make sure that you compile your messages like this:

django-admin.py makemessages -a -d djangojs

That's all!

I don't know why Django doesn't have that information into its documentation. I could find the solution with using these articles below:

http://www.aminche.com/blog/2010/07/06/playground-editor http://code.djangoproject.com/ticket/5494 http://osdir.com/ml/django-users/2010-04/msg00231.html

pocoa
Thanks. My mistake was to call django-admin.py makemessages in the top level of project directory. That created translation catalogs for the entrire project. But it turns out that javascript catalog needs locale directories on django app dir basis. So after using1. cd /home/my_project/my_app2. mkdir locale3. django-admin.py makemessages -d djangojs -l enIt creates translation strings just for my_app dir and I can use :js_info_dict = { 'domain': 'djangojs', 'packages': ('my_app',),}
hamdiakoguz
You're welcome. Normally it has to support application locales. So, it's not your fault, it's a bug: http://code.djangoproject.com/ticket/5494Cheers!
pocoa