diff --git c/django/views/i18n.py w/django/views/i18n.py
index 140dc54..66ca940 100644
|
c
|
w
|
def get_formats():
|
| 53 | 53 | src = [] |
| 54 | 54 | for k, v in result.items(): |
| 55 | 55 | if isinstance(v, (basestring, int)): |
| 56 | | src.append("formats['%s'] = '%s';\n" % (javascript_quote(k), javascript_quote(smart_unicode(v)))) |
| | 56 | src.append(" formats['%s'] = '%s';\n" % (javascript_quote(k), javascript_quote(smart_unicode(v)))) |
| 57 | 57 | elif isinstance(v, (tuple, list)): |
| 58 | 58 | v = [javascript_quote(smart_unicode(value)) for value in v] |
| 59 | | src.append("formats['%s'] = ['%s'];\n" % (javascript_quote(k), "', '".join(v))) |
| | 59 | src.append(" formats['%s'] = ['%s'];\n" % (javascript_quote(k), "', '".join(v))) |
| 60 | 60 | return ''.join(src) |
| 61 | 61 | |
| 62 | 62 | NullSource = """ |
| … |
… |
function npgettext(context, singular, plural, count) { return (count == 1) ? sin
|
| 72 | 72 | LibHead = """ |
| 73 | 73 | /* gettext library */ |
| 74 | 74 | |
| 75 | | var catalog = new Array(); |
| | 75 | (function (globals) { |
| | 76 | var catalog = {}; |
| 76 | 77 | """ |
| 77 | 78 | |
| 78 | 79 | LibFoot = """ |
| 79 | 80 | |
| 80 | | function gettext(msgid) { |
| 81 | | var value = catalog[msgid]; |
| 82 | | if (typeof(value) == 'undefined') { |
| 83 | | return msgid; |
| 84 | | } else { |
| 85 | | return (typeof(value) == 'string') ? value : value[0]; |
| | 81 | globals.gettext = function (msgid) { |
| | 82 | var value = catalog[msgid]; |
| | 83 | if (typeof(value) == 'undefined') { |
| | 84 | return msgid; |
| | 85 | } else { |
| | 86 | return (typeof(value) == 'string') ? value : value[0]; |
| | 87 | } |
| 86 | 88 | } |
| 87 | | } |
| 88 | 89 | |
| 89 | | function ngettext(singular, plural, count) { |
| 90 | | value = catalog[singular]; |
| 91 | | if (typeof(value) == 'undefined') { |
| 92 | | return (count == 1) ? singular : plural; |
| 93 | | } else { |
| 94 | | return value[pluralidx(count)]; |
| | 90 | globals.ngettext = function (singular, plural, count) { |
| | 91 | value = catalog[singular]; |
| | 92 | if (typeof(value) == 'undefined') { |
| | 93 | return (count == 1) ? singular : plural; |
| | 94 | } else { |
| | 95 | return value[pluralidx(count)]; |
| | 96 | } |
| 95 | 97 | } |
| 96 | | } |
| 97 | 98 | |
| 98 | | function gettext_noop(msgid) { return msgid; } |
| | 99 | globals.gettext_noop = function (msgid) { return msgid; } |
| 99 | 100 | |
| 100 | | function pgettext(context, msgid) { |
| 101 | | var value = gettext(context + '\x04' + msgid); |
| 102 | | if (value.indexOf('\x04') != -1) { |
| 103 | | value = msgid; |
| | 101 | globals.pgettext = function (context, msgid) { |
| | 102 | var value = gettext(context + '\x04' + msgid); |
| | 103 | if (value.indexOf('\x04') != -1) { |
| | 104 | value = msgid; |
| | 105 | } |
| | 106 | return value; |
| 104 | 107 | } |
| 105 | | return value; |
| 106 | | } |
| 107 | 108 | |
| 108 | | function npgettext(context, singular, plural, count) { |
| 109 | | var value = ngettext(context + '\x04' + singular, context + '\x04' + plural, count); |
| 110 | | if (value.indexOf('\x04') != -1) { |
| 111 | | value = ngettext(singular, plural, count); |
| | 109 | globals.npgettext = function (context, singular, plural, count) { |
| | 110 | var value = ngettext(context + '\x04' + singular, context + '\x04' + plural, count); |
| | 111 | if (value.indexOf('\x04') != -1) { |
| | 112 | value = ngettext(singular, plural, count); |
| | 113 | } |
| | 114 | return value; |
| 112 | 115 | } |
| 113 | | return value; |
| 114 | | } |
| | 116 | }(this)); |
| 115 | 117 | """ |
| 116 | 118 | |
| 117 | 119 | LibFormatHead = """ |
| 118 | 120 | /* formatting library */ |
| 119 | 121 | |
| 120 | | var formats = new Array(); |
| | 122 | (function (globals) { |
| | 123 | var formats = {}; |
| 121 | 124 | |
| 122 | 125 | """ |
| 123 | 126 | |
| 124 | 127 | LibFormatFoot = """ |
| 125 | | function get_format(format_type) { |
| | 128 | globals.get_format = function (format_type) { |
| 126 | 129 | var value = formats[format_type]; |
| 127 | 130 | if (typeof(value) == 'undefined') { |
| 128 | 131 | return msgid; |
| 129 | 132 | } else { |
| 130 | 133 | return value; |
| 131 | 134 | } |
| 132 | | } |
| | 135 | } |
| | 136 | }(this)); |
| 133 | 137 | """ |
| 134 | 138 | |
| 135 | 139 | SimplePlural = """ |
| 136 | | function pluralidx(count) { return (count == 1) ? 0 : 1; } |
| | 140 | globals.pluralidx = function (count) { return (count == 1) ? 0 : 1; } |
| 137 | 141 | """ |
| 138 | 142 | |
| 139 | 143 | InterPolate = r""" |
| … |
… |
function interpolate(fmt, obj, named) {
|
| 147 | 151 | """ |
| 148 | 152 | |
| 149 | 153 | PluralIdx = r""" |
| 150 | | function pluralidx(n) { |
| 151 | | var v=%s; |
| 152 | | if (typeof(v) == 'boolean') { |
| 153 | | return v ? 1 : 0; |
| 154 | | } else { |
| 155 | | return v; |
| | 154 | globals.pluralidx = function (n) { |
| | 155 | var v=%s; |
| | 156 | if (typeof(v) == 'boolean') { |
| | 157 | return v ? 1 : 0; |
| | 158 | } else { |
| | 159 | return v; |
| | 160 | } |
| 156 | 161 | } |
| 157 | | } |
| 158 | 162 | """ |
| 159 | 163 | |
| 160 | 164 | def null_javascript_catalog(request, domain=None, packages=None): |
| … |
… |
def javascript_catalog(request, domain='djangojs', packages=None):
|
| 259 | 263 | if k == '': |
| 260 | 264 | continue |
| 261 | 265 | if isinstance(k, basestring): |
| 262 | | csrc.append("catalog['%s'] = '%s';\n" % (javascript_quote(k), javascript_quote(v))) |
| | 266 | csrc.append(" catalog['%s'] = '%s';\n" % (javascript_quote(k), javascript_quote(v))) |
| 263 | 267 | elif isinstance(k, tuple): |
| 264 | 268 | if k[0] not in pdict: |
| 265 | 269 | pdict[k[0]] = k[1] |
| 266 | 270 | else: |
| 267 | 271 | pdict[k[0]] = max(k[1], pdict[k[0]]) |
| 268 | | csrc.append("catalog['%s'][%d] = '%s';\n" % (javascript_quote(k[0]), k[1], javascript_quote(v))) |
| | 272 | csrc.append(" catalog['%s'][%d] = '%s';\n" % (javascript_quote(k[0]), k[1], javascript_quote(v))) |
| 269 | 273 | else: |
| 270 | 274 | raise TypeError(k) |
| 271 | 275 | csrc.sort() |