summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2020-08-05 08:08:46 +0200
committerGitHub <noreply@github.com>2020-08-05 08:08:46 +0200
commitb23216d9d0ee783405331b4f4b331ef175073874 (patch)
treef9d10ab2b13a0f8b4cd59e139e6d187dd77b91f4 /django
parentc7e7f176c13b1070c689feb5255c07b524933e12 (diff)
Refs #31493 -- Replaced var with const and let in JavaScriptCatalog template.
Diffstat (limited to 'django')
-rw-r--r--django/views/i18n.py36
1 files changed, 18 insertions, 18 deletions
diff --git a/django/views/i18n.py b/django/views/i18n.py
index c4be394900..d6a29eb8f9 100644
--- a/django/views/i18n.py
+++ b/django/views/i18n.py
@@ -87,14 +87,15 @@ def get_formats():
js_catalog_template = r"""
{% autoescape off %}
-(function(globals) {
-
- var django = globals.django || (globals.django = {});
+'use strict';
+{
+ const globals = this;
+ const django = globals.django || (globals.django = {});
{% if plural %}
django.pluralidx = function(n) {
- var v={{ plural }};
- if (typeof(v) == 'boolean') {
+ const v = {{ plural }};
+ if (typeof v === 'boolean') {
return v ? 1 : 0;
} else {
return v;
@@ -108,25 +109,25 @@ js_catalog_template = r"""
django.catalog = django.catalog || {};
{% if catalog_str %}
- var newcatalog = {{ catalog_str }};
- for (var key in newcatalog) {
+ const newcatalog = {{ catalog_str }};
+ for (const key in newcatalog) {
django.catalog[key] = newcatalog[key];
}
{% endif %}
if (!django.jsi18n_initialized) {
django.gettext = function(msgid) {
- var value = django.catalog[msgid];
- if (typeof(value) == 'undefined') {
+ const value = django.catalog[msgid];
+ if (typeof value === 'undefined') {
return msgid;
} else {
- return (typeof(value) == 'string') ? value : value[0];
+ return (typeof value === 'string') ? value : value[0];
}
};
django.ngettext = function(singular, plural, count) {
- var value = django.catalog[singular];
- if (typeof(value) == 'undefined') {
+ const value = django.catalog[singular];
+ if (typeof value === 'undefined') {
return (count == 1) ? singular : plural;
} else {
return value.constructor === Array ? value[django.pluralidx(count)] : value;
@@ -136,7 +137,7 @@ js_catalog_template = r"""
django.gettext_noop = function(msgid) { return msgid; };
django.pgettext = function(context, msgid) {
- var value = django.gettext(context + '\x04' + msgid);
+ let value = django.gettext(context + '\x04' + msgid);
if (value.includes('\x04')) {
value = msgid;
}
@@ -144,7 +145,7 @@ js_catalog_template = r"""
};
django.npgettext = function(context, singular, plural, count) {
- var value = django.ngettext(context + '\x04' + singular, context + '\x04' + plural, count);
+ let value = django.ngettext(context + '\x04' + singular, context + '\x04' + plural, count);
if (value.includes('\x04')) {
value = django.ngettext(singular, plural, count);
}
@@ -165,8 +166,8 @@ js_catalog_template = r"""
django.formats = {{ formats_str }};
django.get_format = function(format_type) {
- var value = django.formats[format_type];
- if (typeof(value) == 'undefined') {
+ const value = django.formats[format_type];
+ if (typeof value === 'undefined') {
return format_type;
} else {
return value;
@@ -185,8 +186,7 @@ js_catalog_template = r"""
django.jsi18n_initialized = true;
}
-
-}(this));
+};
{% endautoescape %}
"""