Show More
@@ -58,7 +58,7 b' def setdatapath(datapath):' | |||||
58 | except AttributeError: |
|
58 | except AttributeError: | |
59 | _ugettext = t.gettext |
|
59 | _ugettext = t.gettext | |
60 |
|
60 | |||
61 | _msgcache = {} |
|
61 | _msgcache = {} # encoding: {message: translation} | |
62 |
|
62 | |||
63 | def gettext(message): |
|
63 | def gettext(message): | |
64 | """Translate message. |
|
64 | """Translate message. | |
@@ -74,7 +74,8 b' def gettext(message):' | |||||
74 | if message is None or not _ugettext: |
|
74 | if message is None or not _ugettext: | |
75 | return message |
|
75 | return message | |
76 |
|
76 | |||
77 | if message not in _msgcache: |
|
77 | cache = _msgcache.setdefault(encoding.encoding, {}) | |
|
78 | if message not in cache: | |||
78 | if type(message) is unicode: |
|
79 | if type(message) is unicode: | |
79 | # goofy unicode docstrings in test |
|
80 | # goofy unicode docstrings in test | |
80 | paragraphs = message.split(u'\n\n') |
|
81 | paragraphs = message.split(u'\n\n') | |
@@ -90,11 +91,11 b' def gettext(message):' | |||||
90 | # the Python encoding defaults to 'ascii', this fails if the |
|
91 | # the Python encoding defaults to 'ascii', this fails if the | |
91 | # translated string use non-ASCII characters. |
|
92 | # translated string use non-ASCII characters. | |
92 | encodingstr = pycompat.sysstr(encoding.encoding) |
|
93 | encodingstr = pycompat.sysstr(encoding.encoding) | |
93 |
|
|
94 | cache[message] = u.encode(encodingstr, "replace") | |
94 | except LookupError: |
|
95 | except LookupError: | |
95 | # An unknown encoding results in a LookupError. |
|
96 | # An unknown encoding results in a LookupError. | |
96 |
|
|
97 | cache[message] = message | |
97 |
return |
|
98 | return cache[message] | |
98 |
|
99 | |||
99 | def _plain(): |
|
100 | def _plain(): | |
100 | if ('HGPLAIN' not in encoding.environ |
|
101 | if ('HGPLAIN' not in encoding.environ |
@@ -48,3 +48,23 b' tool itself by doctest' | |||||
48 | $ $PYTHON check-translation.py *.po |
|
48 | $ $PYTHON check-translation.py *.po | |
49 | $ $PYTHON check-translation.py --doctest |
|
49 | $ $PYTHON check-translation.py --doctest | |
50 | $ cd $TESTTMP |
|
50 | $ cd $TESTTMP | |
|
51 | ||||
|
52 | Check i18n cache isn't reused after encoding change: | |||
|
53 | ||||
|
54 | $ cat > $TESTTMP/encodingchange.py << EOF | |||
|
55 | > from mercurial import encoding, registrar | |||
|
56 | > from mercurial.i18n import _ | |||
|
57 | > cmdtable = {} | |||
|
58 | > command = registrar.command(cmdtable) | |||
|
59 | > @command(b'encodingchange', norepo=True) | |||
|
60 | > def encodingchange(ui): | |||
|
61 | > for encode in (b'ascii', b'UTF-8', b'ascii', b'UTF-8'): | |||
|
62 | > encoding.encoding = encode | |||
|
63 | > ui.write(b'%s\n' % _(b'(EXPERIMENTAL)')) | |||
|
64 | > EOF | |||
|
65 | ||||
|
66 | $ LANGUAGE=ja hg --config extensions.encodingchange=$TESTTMP/encodingchange.py encodingchange | |||
|
67 | (?????) | |||
|
68 | (\xe5\xae\x9f\xe9\xa8\x93\xe7\x9a\x84\xe5\xae\x9f\xe8\xa3\x85) (esc) | |||
|
69 | (?????) | |||
|
70 | (\xe5\xae\x9f\xe9\xa8\x93\xe7\x9a\x84\xe5\xae\x9f\xe8\xa3\x85) (esc) |
General Comments 0
You need to be logged in to leave comments.
Login now