mirror of https://github.com/django/django.git
Merge pull request #1090 from zyegfryed/ticket_20433
Fixed #20433: extracted catalog compilation code from view.
This commit is contained in:
commit
06603d112c
|
@ -184,38 +184,8 @@ def render_javascript_catalog(catalog=None, plural=None):
|
||||||
return http.HttpResponse(template.render(context), 'text/javascript')
|
return http.HttpResponse(template.render(context), 'text/javascript')
|
||||||
|
|
||||||
|
|
||||||
def null_javascript_catalog(request, domain=None, packages=None):
|
def get_javascript_catalog(locale, domain, packages):
|
||||||
"""
|
|
||||||
Returns "identity" versions of the JavaScript i18n functions -- i.e.,
|
|
||||||
versions that don't actually do anything.
|
|
||||||
"""
|
|
||||||
return render_javascript_catalog()
|
|
||||||
|
|
||||||
|
|
||||||
def javascript_catalog(request, domain='djangojs', packages=None):
|
|
||||||
"""
|
|
||||||
Returns the selected language catalog as a javascript library.
|
|
||||||
|
|
||||||
Receives the list of packages to check for translations in the
|
|
||||||
packages parameter either from an infodict or as a +-delimited
|
|
||||||
string from the request. Default is 'django.conf'.
|
|
||||||
|
|
||||||
Additionally you can override the gettext domain for this view,
|
|
||||||
but usually you don't want to do that, as JavaScript messages
|
|
||||||
go to the djangojs domain. But this might be needed if you
|
|
||||||
deliver your JavaScript source from Django templates.
|
|
||||||
"""
|
|
||||||
default_locale = to_locale(settings.LANGUAGE_CODE)
|
default_locale = to_locale(settings.LANGUAGE_CODE)
|
||||||
locale = to_locale(get_language())
|
|
||||||
|
|
||||||
if request.GET and 'language' in request.GET:
|
|
||||||
if check_for_language(request.GET['language']):
|
|
||||||
locale = to_locale(request.GET['language'])
|
|
||||||
|
|
||||||
if packages is None:
|
|
||||||
packages = ['django.conf']
|
|
||||||
if isinstance(packages, six.string_types):
|
|
||||||
packages = packages.split('+')
|
|
||||||
packages = [p for p in packages if p == 'django.conf' or p in settings.INSTALLED_APPS]
|
packages = [p for p in packages if p == 'django.conf' or p in settings.INSTALLED_APPS]
|
||||||
t = {}
|
t = {}
|
||||||
paths = []
|
paths = []
|
||||||
|
@ -296,4 +266,40 @@ def javascript_catalog(request, domain='djangojs', packages=None):
|
||||||
for k, v in pdict.items():
|
for k, v in pdict.items():
|
||||||
catalog[k] = [v.get(i, '') for i in range(maxcnts[msgid] + 1)]
|
catalog[k] = [v.get(i, '') for i in range(maxcnts[msgid] + 1)]
|
||||||
|
|
||||||
|
return catalog, plural
|
||||||
|
|
||||||
|
|
||||||
|
def null_javascript_catalog(request, domain=None, packages=None):
|
||||||
|
"""
|
||||||
|
Returns "identity" versions of the JavaScript i18n functions -- i.e.,
|
||||||
|
versions that don't actually do anything.
|
||||||
|
"""
|
||||||
|
return render_javascript_catalog()
|
||||||
|
|
||||||
|
|
||||||
|
def javascript_catalog(request, domain='djangojs', packages=None):
|
||||||
|
"""
|
||||||
|
Returns the selected language catalog as a javascript library.
|
||||||
|
|
||||||
|
Receives the list of packages to check for translations in the
|
||||||
|
packages parameter either from an infodict or as a +-delimited
|
||||||
|
string from the request. Default is 'django.conf'.
|
||||||
|
|
||||||
|
Additionally you can override the gettext domain for this view,
|
||||||
|
but usually you don't want to do that, as JavaScript messages
|
||||||
|
go to the djangojs domain. But this might be needed if you
|
||||||
|
deliver your JavaScript source from Django templates.
|
||||||
|
"""
|
||||||
|
locale = to_locale(get_language())
|
||||||
|
|
||||||
|
if request.GET and 'language' in request.GET:
|
||||||
|
if check_for_language(request.GET['language']):
|
||||||
|
locale = to_locale(request.GET['language'])
|
||||||
|
|
||||||
|
if packages is None:
|
||||||
|
packages = ['django.conf']
|
||||||
|
if isinstance(packages, six.string_types):
|
||||||
|
packages = packages.split('+')
|
||||||
|
|
||||||
|
catalog, plural = get_javascript_catalog(locale, domain, packages)
|
||||||
return render_javascript_catalog(catalog, plural)
|
return render_javascript_catalog(catalog, plural)
|
||||||
|
|
Loading…
Reference in New Issue