##// END OF EJS Templates
i18n: use datapath for i18n like for templates and help...
Mads Kiilerich -
r22638:0d0350cf default
parent child Browse files
Show More
@@ -6,7 +6,7 b''
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 import encoding
9 import gettext, sys, os, locale
9 import gettext as gettextmod, sys, os, locale
10 10
11 11 # modelled after templater.templatepath:
12 12 if getattr(sys, 'frozen', None) is not None:
@@ -14,11 +14,6 b" if getattr(sys, 'frozen', None) is not N"
14 14 else:
15 15 module = __file__
16 16
17 base = os.path.dirname(module)
18 for dir in ('.', '..'):
19 localedir = os.path.join(base, dir, 'locale')
20 if os.path.isdir(localedir):
21 break
22 17
23 18 _languages = None
24 19 if (os.name == 'nt'
@@ -38,7 +33,13 b" if (os.name == 'nt'"
38 33 # ctypes not found or unknown langid
39 34 pass
40 35
41 t = gettext.translation('hg', localedir, _languages, fallback=True)
36 _ugettext = None
37
38 def setdatapath(datapath):
39 localedir = os.path.join(datapath, 'locale')
40 t = gettextmod.translation('hg', localedir, _languages, fallback=True)
41 global _ugettext
42 _ugettext = t.ugettext
42 43
43 44 def gettext(message):
44 45 """Translate message.
@@ -51,7 +52,7 b' def gettext(message):'
51 52 """
52 53 # If message is None, t.ugettext will return u'None' as the
53 54 # translation whereas our callers expect us to return None.
54 if message is None:
55 if message is None or not _ugettext:
55 56 return message
56 57
57 58 if type(message) is unicode:
@@ -61,7 +62,7 b' def gettext(message):'
61 62 paragraphs = [p.decode("ascii") for p in message.split('\n\n')]
62 63 # Be careful not to translate the empty string -- it holds the
63 64 # meta data of the .po file.
64 u = u'\n\n'.join([p and t.ugettext(p) or '' for p in paragraphs])
65 u = u'\n\n'.join([p and _ugettext(p) or '' for p in paragraphs])
65 66 try:
66 67 # encoding.tolocal cannot be used since it will first try to
67 68 # decode the Unicode string. Calling u.decode(enc) really
@@ -13,7 +13,8 b' This contains helper routines that are i'
13 13 hide platform-specific details from the core.
14 14 """
15 15
16 from i18n import _
16 import i18n
17 _ = i18n._
17 18 import error, osutil, encoding
18 19 import errno, shutil, sys, tempfile, traceback
19 20 import re as remod
@@ -467,6 +468,8 b' if mainfrozen():'
467 468 else:
468 469 datapath = os.path.dirname(__file__)
469 470
471 i18n.setdatapath(datapath)
472
470 473 _hgexecutable = None
471 474
472 475 def hgexecutable():
General Comments 0
You need to be logged in to leave comments. Login now