Mercurial > hg
changeset 22638:0d0350cfc7ab
i18n: use datapath for i18n like for templates and help
To avoid circular module dependencies we initialize i18n from util when
datapath is found.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Sun, 28 Sep 2014 16:57:47 +0200 |
parents | 149141c3a25f |
children | 79c4178b2169 |
files | mercurial/i18n.py mercurial/util.py |
diffstat | 2 files changed, 14 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/i18n.py Sun Sep 28 16:57:47 2014 +0200 +++ b/mercurial/i18n.py Sun Sep 28 16:57:47 2014 +0200 @@ -6,7 +6,7 @@ # GNU General Public License version 2 or any later version. import encoding -import gettext, sys, os, locale +import gettext as gettextmod, sys, os, locale # modelled after templater.templatepath: if getattr(sys, 'frozen', None) is not None: @@ -14,11 +14,6 @@ else: module = __file__ -base = os.path.dirname(module) -for dir in ('.', '..'): - localedir = os.path.join(base, dir, 'locale') - if os.path.isdir(localedir): - break _languages = None if (os.name == 'nt' @@ -38,7 +33,13 @@ # ctypes not found or unknown langid pass -t = gettext.translation('hg', localedir, _languages, fallback=True) +_ugettext = None + +def setdatapath(datapath): + localedir = os.path.join(datapath, 'locale') + t = gettextmod.translation('hg', localedir, _languages, fallback=True) + global _ugettext + _ugettext = t.ugettext def gettext(message): """Translate message. @@ -51,7 +52,7 @@ """ # If message is None, t.ugettext will return u'None' as the # translation whereas our callers expect us to return None. - if message is None: + if message is None or not _ugettext: return message if type(message) is unicode: @@ -61,7 +62,7 @@ paragraphs = [p.decode("ascii") for p in message.split('\n\n')] # Be careful not to translate the empty string -- it holds the # meta data of the .po file. - u = u'\n\n'.join([p and t.ugettext(p) or '' for p in paragraphs]) + u = u'\n\n'.join([p and _ugettext(p) or '' for p in paragraphs]) try: # encoding.tolocal cannot be used since it will first try to # decode the Unicode string. Calling u.decode(enc) really
--- a/mercurial/util.py Sun Sep 28 16:57:47 2014 +0200 +++ b/mercurial/util.py Sun Sep 28 16:57:47 2014 +0200 @@ -13,7 +13,8 @@ hide platform-specific details from the core. """ -from i18n import _ +import i18n +_ = i18n._ import error, osutil, encoding import errno, shutil, sys, tempfile, traceback import re as remod @@ -467,6 +468,8 @@ else: datapath = os.path.dirname(__file__) +i18n.setdatapath(datapath) + _hgexecutable = None def hgexecutable():