Internationalization: In Javascript code
Adding translations to JavaScript poses some problems:
- JavaScript code doesn't have access to a
gettext
implementation. - JavaScript code doesn't have access to
.po
or.mo
files; they need to be delivered by the server. - The translation catalogs for JavaScript should be kept as small as possible.
Django provides an integrated solution for these problems: It passes the translations into JavaScript, so you can call gettext
, and so on, from within JavaScript.
The javascript_catalog view
The main solution to these problems is the django.views.i18n.javascript_catalog()
view, which sends out a JavaScript code library with functions that mimic the gettext
interface, plus an array of translation strings.
Those translation ...
Get Mastering Django: Core now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.