Empty catalog when internationalizing JavaScript code

天涯浪子 提交于 2019-12-05 02:16:13

I also had some problems with. This is how it works for me:

Add this to yr root urls.py:

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


urlpatterns = patterns('',                   

    #enable using translation strings in javascript
    #source: https://docs.djangoproject.com/en/dev/topics/i18n/translation/#module-django.views.i18n
    (r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),

)

In JS files use:

var somevar = gettext('Text to translate');

To compile django translation files: In a shell/terminal run from the project root (where 'apps', 'settings', etc lie):

#for "normal django files" (.py, .html):
django-admin.py makemessages --locale=de
#for javascript files. source: http://stackoverflow.com/a/3571954/268125
django-admin.py makemessages -a -d djangojs --locale=de
#to compile the translation files to machine code
django-admin.py compilemessages --locale=de

i added my_project to INSTALLED APPS in settings.py and that seemed to do the trick

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!