#7959 cache translations in util.py (rlucchese)
This commit is contained in:
		
							parent
							
								
									2160a80c97
								
							
						
					
					
						commit
						1f6dae2360
					
				| @ -16,6 +16,7 @@ | |||||||
| # Free Software Foundation, Inc., 59 Temple Place - Suite 330, | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||||||
| # Boston, MA 02111-1307, USA. | # Boston, MA 02111-1307, USA. | ||||||
| 
 | 
 | ||||||
|  | import os | ||||||
| import time | import time | ||||||
| import sha | import sha | ||||||
| import random | import random | ||||||
| @ -23,7 +24,6 @@ import binascii | |||||||
| import gettext | import gettext | ||||||
| 
 | 
 | ||||||
| _ = lambda msg: gettext.dgettext('sugar-toolkit', msg) | _ = lambda msg: gettext.dgettext('sugar-toolkit', msg) | ||||||
| _ngettext = lambda m1, m2, n: gettext.dngettext('sugar-toolkit', m1, m2, n) |  | ||||||
| 
 | 
 | ||||||
| def printable_hash(in_hash): | def printable_hash(in_hash): | ||||||
|     """Convert binary hash data into printable characters.""" |     """Convert binary hash data into printable characters.""" | ||||||
| @ -217,6 +217,9 @@ del ngettext | |||||||
| 
 | 
 | ||||||
| # End of plurals hack | # End of plurals hack | ||||||
| 
 | 
 | ||||||
|  | # gettext perfs hack (#7959) | ||||||
|  | _i18n_timestamps_cache = LRU(60) | ||||||
|  | 
 | ||||||
| def timestamp_to_elapsed_string(timestamp, max_levels=2): | def timestamp_to_elapsed_string(timestamp, max_levels=2): | ||||||
|     levels = 0 |     levels = 0 | ||||||
|     time_period = '' |     time_period = '' | ||||||
| @ -229,8 +232,17 @@ def timestamp_to_elapsed_string(timestamp, max_levels=2): | |||||||
|             if levels > 0: |             if levels > 0: | ||||||
|                 time_period += COMMA |                 time_period += COMMA | ||||||
| 
 | 
 | ||||||
|             time_period += _ngettext(name_singular, name_plural, |             key = ''.join((os.environ['LANG'], name_singular, | ||||||
|                                      elapsed_units) % elapsed_units |                            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 |             elapsed_seconds -= elapsed_units * factor | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Tomeu Vizoso
						Tomeu Vizoso