Django JavaScript translation empty directory (i18n / jsi18n)

I keep ending up with an empty directory in my jsi18n javascript. I tried all the solutions in StackOverflow, including the Empty directory when internationalizing JavaScript code , but the directory 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 directory, so that means

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 application 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 all settings options, etc. I could find, but the directory remains empty.

When I run make messages and compile messages my JavaScript receives text strings that are found and translated. The django.po and .mo files are located in the locale directory.

Is anyone

+7
source share
3 answers

Here's what ended 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 why this works, but I can tell you how I learned how to make it work. If you use the same troubleshooting method, you may also find a way. I used a Python debugger, for example:

 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 entered javascript_catalog until I got to the line:

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

Then I experimented with different values ​​for domain and packages , right there in the debugger, until I found the values ​​I needed.

+5
source

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

+3
source

Do you have any completed translations for the language of your current user, or do you only have stubs? The directory will only contain values ​​for strings that were actually translated.

those. if you have this in your english po file:

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

Nothing appears in the directory (if you access it in English). But if you have this:

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

Then it will be.

+1
source

All Articles