Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The reason why it's handled differently is in the <a href="https://docs.djangoproject.com/en/dev/topics/i18n/internationalization/#specifying-translation-strings-in-javascript-code" rel="nofollow">docs</a>. </p> <blockquote> <p>Adding translations to JavaScript poses some problems:</p> <ul> <li>JavaScript code doesn't have access to a gettext implementation.</li> <li>JavaScript code doesn't have access to .po or .mo files; they need to be delivered by the server. </li> <li>The translation catalogs for JavaScript should be kept as small as possible.</li> </ul> </blockquote> <p>So essentially, the internal Python translation is done on the server. But for JS, there's another file served by the server, which contains all the required translations for user's language. And the translation is done on the user's side. So as you can see, it's a completely different strategy. Django helps by adding similar interface for JS files, even though they're handled in a completely different way.</p> <blockquote> <p>I guess it works like this: when rendering a template, Django checks the requested locale, loads the appropriate localisation file and serves the template but JS on the other hand being served as static media doesn't get parsed by Django. Is this it?</p> </blockquote> <p>You are right in the first part, about handling templates. Handling JS works as I've explained above. </p> <p>Note that Django JS translation mechanism, <strong>doesn't</strong> treat JS translations as static files. It uses a Django view to generate the JS file everytime (<code>javascript_catalog</code> mentioned in the docs linked in the first line). That is one of the problems I've encountered. Such files don't need to be generated on every request. There are some projects that actually let you pack those JS translations as static files and enable you to cache them properly (like <a href="http://www.allbuttonspressed.com/projects/django-mediagenerator" rel="nofollow">django-mediagenerator</a>).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload