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