summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorSergey Kolosov <m17.admin@gmail.com>2015-06-05 15:10:28 +0100
committerTim Graham <timograham@gmail.com>2015-08-05 09:05:21 -0400
commit244404227e8a1c5e241658ef0df789a28ed3bbc6 (patch)
tree749c5e86ee0894161e9328e7673561eebaf3a2de /docs
parente8cd65f8297928d3fa7ad3d338953a4423028713 (diff)
Fixed #22404 -- Added a view that exposes i18n catalog as a JSON
Added django.views.i18n.json_catalog() view, which returns a JSON response containing translations, formats, and a plural expression for the specified language.
Diffstat (limited to 'docs')
-rw-r--r--docs/releases/1.9.txt4
-rw-r--r--docs/topics/i18n/translation.txt46
2 files changed, 50 insertions, 0 deletions
diff --git a/docs/releases/1.9.txt b/docs/releases/1.9.txt
index 6f2611f267..1f1183d9a7 100644
--- a/docs/releases/1.9.txt
+++ b/docs/releases/1.9.txt
@@ -357,6 +357,10 @@ Internationalization
for languages which can be written in different scripts, for example Latin
and Cyrillic (e.g. ``be@latin``).
+* Added the :func:`django.views.i18n.json_catalog` view to help build a custom
+ client-side i18n library upon Django translations. It returns a JSON object
+ containing a translations catalog, formatting settings, and a plural rule.
+
* Added the ``name_translated`` attribute to the object returned by the
:ttag:`get_language_info` template tag. Also added a corresponding template
filter: :tfilter:`language_name_translated`.
diff --git a/docs/topics/i18n/translation.txt b/docs/topics/i18n/translation.txt
index d976ddf2ef..974f6d31ce 100644
--- a/docs/topics/i18n/translation.txt
+++ b/docs/topics/i18n/translation.txt
@@ -1213,6 +1213,52 @@ Additionally, if there are complex rules around pluralization, the catalog view
will render a conditional expression. This will evaluate to either a ``true``
(should pluralize) or ``false`` (should **not** pluralize) value.
+The ``json_catalog`` view
+-------------------------
+
+.. versionadded:: 1.9
+
+.. function:: json_catalog(request, domain='djangojs', packages=None)
+
+In order to use another client-side library to handle translations, you may
+want to take advantage of the ``json_catalog()`` view. It's similar to
+:meth:`~django.views.i18n.javascript_catalog` but returns a JSON response.
+
+The JSON object contains i18n formatting settings (those available for
+`get_format`_), a plural rule (as a ``plural`` part of a GNU gettext
+``Plural-Forms`` expression), and translation strings. The translation strings
+are taken from applications or Django's own translations, according to what is
+specified either via ``urlpatterns`` arguments or as request parameters. Paths
+listed in :setting:`LOCALE_PATHS` are also included.
+
+The view is hooked up to your application and configured in the same fashion as
+:meth:`~django.views.i18n.javascript_catalog` (namely, the ``domain`` and
+``packages`` arguments behave identically)::
+
+ from django.views.i18n import json_catalog
+
+ js_info_dict = {
+ 'packages': ('your.app.package',),
+ }
+
+ urlpatterns = [
+ url(r'^jsoni18n/$', json_catalog, js_info_dict),
+ ]
+
+The response format is as follows:
+
+.. code-block:: json
+
+ {
+ "catalog": {
+ # Translations catalog
+ },
+ "formats": {
+ # Language formats for date, time, etc.
+ },
+ "plural": "..." # Expression for plural forms, or null.
+ }
+
Note on performance
-------------------