##// 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 global _ugettext
41 global _ugettext
42 _ugettext = t.ugettext
42 _ugettext = t.ugettext
43
43
44 _msgcache = {}
45
44 def gettext(message):
46 def gettext(message):
45 """Translate message.
47 """Translate message.
46
48
@@ -55,6 +57,7 b' def gettext(message):'
55 if message is None or not _ugettext:
57 if message is None or not _ugettext:
56 return message
58 return message
57
59
60 if message not in _msgcache:
58 if type(message) is unicode:
61 if type(message) is unicode:
59 # goofy unicode docstrings in test
62 # goofy unicode docstrings in test
60 paragraphs = message.split(u'\n\n')
63 paragraphs = message.split(u'\n\n')
@@ -69,10 +72,11 b' def gettext(message):'
69 # means u.encode(sys.getdefaultencoding()).decode(enc). Since
72 # means u.encode(sys.getdefaultencoding()).decode(enc). Since
70 # the Python encoding defaults to 'ascii', this fails if the
73 # the Python encoding defaults to 'ascii', this fails if the
71 # translated string use non-ASCII characters.
74 # translated string use non-ASCII characters.
72 return u.encode(encoding.encoding, "replace")
75 _msgcache[message] = u.encode(encoding.encoding, "replace")
73 except LookupError:
76 except LookupError:
74 # An unknown encoding results in a LookupError.
77 # An unknown encoding results in a LookupError.
75 return message
78 _msgcache[message] = message
79 return _msgcache[message]
76
80
77 def _plain():
81 def _plain():
78 if 'HGPLAIN' not in os.environ and 'HGPLAINEXCEPT' not in os.environ:
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