Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@tomeuvizoso.net>2008-08-22 12:33:38 (GMT)
committer Tomeu Vizoso <tomeu@tomeuvizoso.net>2008-08-22 12:33:38 (GMT)
commit1f6dae2360d290a35783dd20fde58ed6ce86488c (patch)
tree965f37b67094b41b6493ab343108e5d41be4cb26 /src
parent2160a80c976baf5dfe616ba1acbfdb77d0834de4 (diff)
#7959 cache translations in util.py (rlucchese)
Diffstat (limited to 'src')
-rw-r--r--src/sugar/util.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/sugar/util.py b/src/sugar/util.py
index 955f4c8..c365dce 100644
--- a/src/sugar/util.py
+++ b/src/sugar/util.py
@@ -16,6 +16,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
+import os
import time
import sha
import random
@@ -23,7 +24,6 @@ import binascii
import gettext
_ = lambda msg: gettext.dgettext('sugar-toolkit', msg)
-_ngettext = lambda m1, m2, n: gettext.dngettext('sugar-toolkit', m1, m2, n)
def printable_hash(in_hash):
"""Convert binary hash data into printable characters."""
@@ -217,6 +217,9 @@ del ngettext
# End of plurals hack
+# gettext perfs hack (#7959)
+_i18n_timestamps_cache = LRU(60)
+
def timestamp_to_elapsed_string(timestamp, max_levels=2):
levels = 0
time_period = ''
@@ -229,8 +232,17 @@ def timestamp_to_elapsed_string(timestamp, max_levels=2):
if levels > 0:
time_period += COMMA
- time_period += _ngettext(name_singular, name_plural,
- elapsed_units) % elapsed_units
+ key = ''.join((os.environ['LANG'], name_singular,
+ str(elapsed_units)))
+ if key in _i18n_timestamps_cache:
+ time_period += _i18n_timestamps_cache[key]
+ else:
+ translation = gettext.dngettext('sugar-toolkit',
+ name_singular,
+ name_plural,
+ elapsed_units) % elapsed_units
+ _i18n_timestamps_cache[key] = translation
+ time_period += translation
elapsed_seconds -= elapsed_units * factor