views.i18n.JavaScriptCatalog

class JavaScriptCatalog [source]

A view that produces a JavaScript code library with functions that mimic the gettext interface, plus an array of translation strings.

Attributes

domain

Translation domain containing strings to add in the view output. Defaults to 'djangojs'.

packages

A list of application names among installed applications. Those apps should contain a locale directory. All those catalogs plus all catalogs found in LOCALE_PATHS (which are always included) are merged into one catalog. Defaults to None, which means that all available translations from all INSTALLED_APPS are provided in the JavaScript output.

Example with default values:

from django.views.i18n import JavaScriptCatalog

urlpatterns = [
    url(r'^jsi18n/$', JavaScriptCatalog.as_view(), name='javascript-catalog'),
]

Example with custom packages:

urlpatterns = [
    url(r'^jsi18n/myapp/$',
        JavaScriptCatalog.as_view(packages=['your.app.label']),
        name='javascript-catalog'),
]

The precedence of translations is such that the packages appearing later in the packages argument have higher precedence than the ones appearing at the beginning. This is important in the case of clashing translations for the same literal.

If you use more than one JavaScriptCatalog view on a site and some of them define the same strings, the strings in the catalog that was loaded last take precedence.

doc_Django
2016-10-09 18:41:14
Comments
Leave a Comment

Please login to continue.