views.i18n.json_catalog()

json_catalog(request, domain='djangojs', packages=None) [source]

Deprecated since version 1.10: json_catalog() is deprecated in favor of JSONCatalog and will be removed in Django 2.0.

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 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 LOCALE_PATHS are also included.

The view is hooked up to your application and configured in the same fashion as 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:

{
    "catalog": {
        # Translations catalog
    },
    "formats": {
        # Language formats for date, time, etc.
    },
    "plural": "..."  # Expression for plural forms, or null.
}
doc_Django
2016-10-09 18:41:15
Comments
Leave a Comment

Please login to continue.