##// END OF EJS Templates
i18n: cache the result of every gettext call...
Augie Fackler -
r23031:3c0983cc default
parent child Browse files
Show More
@@ -41,6 +41,8 b' def setdatapath(datapath):'
41 41 global _ugettext
42 42 _ugettext = t.ugettext
43 43
44 _msgcache = {}
45
44 46 def gettext(message):
45 47 """Translate message.
46 48
@@ -55,6 +57,7 b' def gettext(message):'
55 57 if message is None or not _ugettext:
56 58 return message
57 59
60 if message not in _msgcache:
58 61 if type(message) is unicode:
59 62 # goofy unicode docstrings in test
60 63 paragraphs = message.split(u'\n\n')
@@ -69,10 +72,11 b' def gettext(message):'
69 72 # means u.encode(sys.getdefaultencoding()).decode(enc). Since
70 73 # the Python encoding defaults to 'ascii', this fails if the
71 74 # translated string use non-ASCII characters.
72 return u.encode(encoding.encoding, "replace")
75 _msgcache[message] = u.encode(encoding.encoding, "replace")
73 76 except LookupError:
74 77 # An unknown encoding results in a LookupError.
75 return message
78 _msgcache[message] = message
79 return _msgcache[message]
76 80
77 81 def _plain():
78 82 if 'HGPLAIN' not in os.environ and 'HGPLAINEXCEPT' not in os.environ:
General Comments 0
You need to be logged in to leave comments. Login now