##// 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 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 import encoding
8 import encoding
9 import gettext, sys, os, locale
9 import gettext as gettextmod, sys, os, locale
10
10
11 # modelled after templater.templatepath:
11 # modelled after templater.templatepath:
12 if getattr(sys, 'frozen', None) is not None:
12 if getattr(sys, 'frozen', None) is not None:
@@ -14,11 +14,6 b" if getattr(sys, 'frozen', None) is not N"
14 else:
14 else:
15 module = __file__
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 _languages = None
18 _languages = None
24 if (os.name == 'nt'
19 if (os.name == 'nt'
@@ -38,7 +33,13 b" if (os.name == 'nt'"
38 # ctypes not found or unknown langid
33 # ctypes not found or unknown langid
39 pass
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 def gettext(message):
44 def gettext(message):
44 """Translate message.
45 """Translate message.
@@ -51,7 +52,7 b' def gettext(message):'
51 """
52 """
52 # If message is None, t.ugettext will return u'None' as the
53 # If message is None, t.ugettext will return u'None' as the
53 # translation whereas our callers expect us to return None.
54 # translation whereas our callers expect us to return None.
54 if message is None:
55 if message is None or not _ugettext:
55 return message
56 return message
56
57
57 if type(message) is unicode:
58 if type(message) is unicode:
@@ -61,7 +62,7 b' def gettext(message):'
61 paragraphs = [p.decode("ascii") for p in message.split('\n\n')]
62 paragraphs = [p.decode("ascii") for p in message.split('\n\n')]
62 # Be careful not to translate the empty string -- it holds the
63 # Be careful not to translate the empty string -- it holds the
63 # meta data of the .po file.
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 try:
66 try:
66 # encoding.tolocal cannot be used since it will first try to
67 # encoding.tolocal cannot be used since it will first try to
67 # decode the Unicode string. Calling u.decode(enc) really
68 # decode the Unicode string. Calling u.decode(enc) really
@@ -13,7 +13,8 b' This contains helper routines that are i'
13 hide platform-specific details from the core.
13 hide platform-specific details from the core.
14 """
14 """
15
15
16 from i18n import _
16 import i18n
17 _ = i18n._
17 import error, osutil, encoding
18 import error, osutil, encoding
18 import errno, shutil, sys, tempfile, traceback
19 import errno, shutil, sys, tempfile, traceback
19 import re as remod
20 import re as remod
@@ -467,6 +468,8 b' if mainfrozen():'
467 else:
468 else:
468 datapath = os.path.dirname(__file__)
469 datapath = os.path.dirname(__file__)
469
470
471 i18n.setdatapath(datapath)
472
470 _hgexecutable = None
473 _hgexecutable = None
471
474
472 def hgexecutable():
475 def hgexecutable():
General Comments 0
You need to be logged in to leave comments. Login now