diff options
| author | Moritz Sichert <moritz.sichert@googlemail.com> | 2014-02-23 15:10:31 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-03-20 17:27:41 -0400 |
| commit | 6bb2175ed65456dda2f8ba584f206ba4bbd43dbc (patch) | |
| tree | 0d9ba74e7dd7178b663d7883de50ace2e9485287 /django | |
| parent | 556eb6770146f26a7f01f786034d8b3ec879ed05 (diff) | |
Fixed #22106 -- Allowed using more than one instance of javascript_catalog per project.
Diffstat (limited to 'django')
| -rw-r--r-- | django/views/i18n.py | 134 |
1 files changed, 67 insertions, 67 deletions
diff --git a/django/views/i18n.py b/django/views/i18n.py index 30ecbbeaf3..3df4f47c88 100644 --- a/django/views/i18n.py +++ b/django/views/i18n.py @@ -94,87 +94,87 @@ js_catalog_template = r""" django.pluralidx = function (count) { return (count == 1) ? 0 : 1; }; {% endif %} - {% if catalog_str %} /* gettext library */ - django.catalog = {{ catalog_str }}; + django.catalog = django.catalog || {}; + {% if catalog_str %} + var newcatalog = {{ catalog_str }}; + for (var key in newcatalog) { + django.catalog[key] = newcatalog[key]; + } + {% endif %} - django.gettext = function (msgid) { - var value = django.catalog[msgid]; - if (typeof(value) == 'undefined') { - return msgid; - } else { - return (typeof(value) == 'string') ? value : value[0]; - } - }; + if (!django.jsi18n_initialized) { + django.gettext = function (msgid) { + var value = django.catalog[msgid]; + if (typeof(value) == 'undefined') { + return msgid; + } else { + return (typeof(value) == 'string') ? value : value[0]; + } + }; - django.ngettext = function (singular, plural, count) { - var value = django.catalog[singular]; - if (typeof(value) == 'undefined') { - return (count == 1) ? singular : plural; - } else { - return value[django.pluralidx(count)]; - } - }; + django.ngettext = function (singular, plural, count) { + var value = django.catalog[singular]; + if (typeof(value) == 'undefined') { + return (count == 1) ? singular : plural; + } else { + return value[django.pluralidx(count)]; + } + }; - django.gettext_noop = function (msgid) { return msgid; }; + django.gettext_noop = function (msgid) { return msgid; }; - django.pgettext = function (context, msgid) { - var value = django.gettext(context + '\x04' + msgid); - if (value.indexOf('\x04') != -1) { - value = msgid; - } - return value; - }; + django.pgettext = function (context, msgid) { + var value = django.gettext(context + '\x04' + msgid); + if (value.indexOf('\x04') != -1) { + value = msgid; + } + return value; + }; - django.npgettext = function (context, singular, plural, count) { - var value = django.ngettext(context + '\x04' + singular, context + '\x04' + plural, count); - if (value.indexOf('\x04') != -1) { - value = django.ngettext(singular, plural, count); - } - return value; - }; - {% else %} - /* gettext identity library */ + django.npgettext = function (context, singular, plural, count) { + var value = django.ngettext(context + '\x04' + singular, context + '\x04' + plural, count); + if (value.indexOf('\x04') != -1) { + value = django.ngettext(singular, plural, count); + } + return value; + }; - django.gettext = function (msgid) { return msgid; }; - django.ngettext = function (singular, plural, count) { return (count == 1) ? singular : plural; }; - django.gettext_noop = function (msgid) { return msgid; }; - django.pgettext = function (context, msgid) { return msgid; }; - django.npgettext = function (context, singular, plural, count) { return (count == 1) ? singular : plural; }; - {% endif %} + django.interpolate = function (fmt, obj, named) { + if (named) { + return fmt.replace(/%\(\w+\)s/g, function(match){return String(obj[match.slice(2,-2)])}); + } else { + return fmt.replace(/%s/g, function(match){return String(obj.shift())}); + } + }; - django.interpolate = function (fmt, obj, named) { - if (named) { - return fmt.replace(/%\(\w+\)s/g, function(match){return String(obj[match.slice(2,-2)])}); - } else { - return fmt.replace(/%s/g, function(match){return String(obj.shift())}); - } - }; + /* formatting library */ - /* formatting library */ + django.formats = {{ formats_str }}; - django.formats = {{ formats_str }}; + django.get_format = function (format_type) { + var value = django.formats[format_type]; + if (typeof(value) == 'undefined') { + return format_type; + } else { + return value; + } + }; - django.get_format = function (format_type) { - var value = django.formats[format_type]; - if (typeof(value) == 'undefined') { - return format_type; - } else { - return value; - } - }; + /* add to global namespace */ + globals.pluralidx = django.pluralidx; + globals.gettext = django.gettext; + globals.ngettext = django.ngettext; + globals.gettext_noop = django.gettext_noop; + globals.pgettext = django.pgettext; + globals.npgettext = django.npgettext; + globals.interpolate = django.interpolate; + globals.get_format = django.get_format; - /* add to global namespace */ - globals.pluralidx = django.pluralidx; - globals.gettext = django.gettext; - globals.ngettext = django.ngettext; - globals.gettext_noop = django.gettext_noop; - globals.pgettext = django.pgettext; - globals.npgettext = django.npgettext; - globals.interpolate = django.interpolate; - globals.get_format = django.get_format; + django.jsi18n_initialized = true; + } }(this)); {% endautoescape %} |
