Optimized JavaScript in django/views/i18n.py

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3249 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-07-01 03:17:18 +00:00
parent cd7b54aab0
commit 31eb140b5a
1 changed files with 22 additions and 50 deletions

View File

@ -28,21 +28,9 @@ def set_language(request):
NullSource = """ NullSource = """
/* gettext identity library */ /* gettext identity library */
function gettext(msgid) { function gettext(msgid) { return msgid; }
return msgid; function ngettext(singular, plural, count) { return (count == 1) ? singular : plural; }
} function gettext_noop(msgid) { return msgid; }
function ngettext(singular, plural, count) {
if (count == 1) {
return singular;
} else {
return plural;
}
}
function gettext_noop(msgid) {
return msgid;
}
""" """
LibHead = """ LibHead = """
@ -54,53 +42,37 @@ var catalog = new Array();
LibFoot = """ LibFoot = """
function gettext(msgid) { function gettext(msgid) {
var value = catalog[msgid]; var value = catalog[msgid];
if (typeof(value) == 'undefined') { if (typeof(value) == 'undefined') {
return msgid; return msgid;
} else { } else {
if (typeof(value) == 'string') { return (typeof(value) == 'string') ? value : value[0];
return value; }
} else {
return value[0];
}
}
} }
function ngettext(singular, plural, count) { function ngettext(singular, plural, count) {
value = catalog[singular]; value = catalog[singular];
if (typeof(value) == 'undefined') { if (typeof(value) == 'undefined') {
if (count == 1) { return (count == 1) ? singular : plural;
return singular; } else {
} else { return value[pluralidx(count)];
return plural; }
}
} else {
return value[pluralidx(count)];
}
} }
function gettext_noop(msgid) { function gettext_noop(msgid) { return msgid; }
return msgid;
}
""" """
SimplePlural = """ SimplePlural = """
function pluralidx(count) { function pluralidx(count) { return (count == 1) ? 0 : 1; }
if (count == 1) {
return 0;
} else {
return 1;
}
}
""" """
InterPolate = r""" InterPolate = r"""
function interpolate(fmt, obj, named) { function interpolate(fmt, obj, named) {
if (named) { if (named) {
return fmt.replace(/%\(\w+\)s/, function(match){return String(obj[match.slice(2,-2)])}); return fmt.replace(/%\(\w+\)s/, function(match){return String(obj[match.slice(2,-2)])});
} else { } else {
return fmt.replace(/%s/, function(match){return String(obj.shift())}); return fmt.replace(/%s/, function(match){return String(obj.shift())});
} }
} }
""" """