diff --git a/mercurial/i18n.py b/mercurial/i18n.py --- a/mercurial/i18n.py +++ b/mercurial/i18n.py @@ -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 @@ if getattr(sys, 'frozen', None) is not N 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 @@ if (os.name == 'nt' # 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 @@ def gettext(message): """ # 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 @@ def gettext(message): 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 diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -13,7 +13,8 @@ This contains helper routines that are i 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 @@ if mainfrozen(): else: datapath = os.path.dirname(__file__) +i18n.setdatapath(datapath) + _hgexecutable = None def hgexecutable():