comparison mercurial/i18n.py @ 43673:f0bee3b1b847

i18n: get datapath directly from resourceutil The new resourceutil module is lower in the dependency graph, so we can depend directly on it and won't have to depend on the util module to inject the datapath. Differential Revision: https://phab.mercurial-scm.org/D7435
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 14 Nov 2019 12:41:33 -0800
parents 9f70512ae2cf
children b9f40b743627
comparison
equal deleted inserted replaced
43672:9fb85668ee15 43673:f0bee3b1b847
11 import locale 11 import locale
12 import os 12 import os
13 import sys 13 import sys
14 14
15 from .pycompat import getattr 15 from .pycompat import getattr
16 from .utils import resourceutil
16 from . import ( 17 from . import (
17 encoding, 18 encoding,
18 pycompat, 19 pycompat,
19 ) 20 )
20 21
43 _languages = [locale.windows_locale[langid]] 44 _languages = [locale.windows_locale[langid]]
44 except (ImportError, AttributeError, KeyError): 45 except (ImportError, AttributeError, KeyError):
45 # ctypes not found or unknown langid 46 # ctypes not found or unknown langid
46 pass 47 pass
47 48
48 _ugettext = None
49 49
50 50 datapath = pycompat.fsdecode(resourceutil.datapath)
51 def setdatapath(datapath): 51 localedir = os.path.join(datapath, 'locale')
52 datapath = pycompat.fsdecode(datapath) 52 t = gettextmod.translation('hg', localedir, _languages, fallback=True)
53 localedir = os.path.join(datapath, 'locale') 53 try:
54 t = gettextmod.translation('hg', localedir, _languages, fallback=True) 54 _ugettext = t.ugettext
55 global _ugettext 55 except AttributeError:
56 try: 56 _ugettext = t.gettext
57 _ugettext = t.ugettext
58 except AttributeError:
59 _ugettext = t.gettext
60 57
61 58
62 _msgcache = {} # encoding: {message: translation} 59 _msgcache = {} # encoding: {message: translation}
63 60
64 61