summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2006-07-01 03:17:18 +0000
committerAdrian Holovaty <adrian@holovaty.com>2006-07-01 03:17:18 +0000
commit31eb140b5a38844114b1647d62c2496cef740a84 (patch)
tree6f252ffcee5e5f5e39cfa7917cbb202a03dbc426
parentcd7b54aab0c087ba6efd4a86ae0ecb6ed55d7e4b (diff)
Optimized JavaScript in django/views/i18n.py
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3249 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/views/i18n.py72
1 files changed, 22 insertions, 50 deletions
diff --git a/django/views/i18n.py b/django/views/i18n.py
index 80fc04d170..b5eb32bda3 100644
--- a/django/views/i18n.py
+++ b/django/views/i18n.py
@@ -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())});
+ }
}
"""