3
# Thomas Nagy, 2006 (ita)
8
import Configure, TaskGen, Task, Utils, Runner, Options, Build, config_c
9
from TaskGen import feature, before, taskgen
10
from Logs import error
15
bld(features='intltool_in', source='a.po b.po', podir='po', cache='.intlcache', flags='')
19
class intltool_in_taskgen(TaskGen.task_gen):
21
def __init__(self, *k, **kw):
22
TaskGen.task_gen.__init__(self, *k, **kw)
25
@feature('intltool_in')
26
def iapply_intltool_in_f(self):
27
try: self.meths.remove('apply_core')
28
except ValueError: pass
30
for i in self.to_list(self.source):
31
node = self.path.find_resource(i)
33
podir = getattr(self, 'podir', 'po')
34
podirnode = self.path.find_dir(podir)
36
error("could not find the podir %r" % podir)
39
cache = getattr(self, 'intlcache', '.intlcache')
40
self.env['INTLCACHE'] = os.path.join(self.path.bldpath(self.env), podir, cache)
41
self.env['INTLPODIR'] = podirnode.srcpath(self.env)
42
self.env['INTLFLAGS'] = getattr(self, 'flags', ['-q', '-u', '-c'])
44
task = self.create_task('intltool', node, node.change_ext(''))
45
task.install_path = self.install_path
47
class intltool_po_taskgen(TaskGen.task_gen):
49
def __init__(self, *k, **kw):
50
TaskGen.task_gen.__init__(self, *k, **kw)
53
@feature('intltool_po')
54
def apply_intltool_po(self):
55
try: self.meths.remove('apply_core')
56
except ValueError: pass
58
self.default_install_path = '${LOCALEDIR}'
59
appname = getattr(self, 'appname', 'set_your_app_name')
60
podir = getattr(self, 'podir', '')
62
def install_translation(task):
65
(langname, ext) = os.path.splitext(filename)
66
inst_file = langname + os.sep + 'LC_MESSAGES' + os.sep + appname + '.mo'
67
self.bld.install_as(os.path.join(self.install_path, inst_file), out, self.env, self.chmod)
69
linguas = self.path.find_resource(os.path.join(podir, 'LINGUAS'))
71
# scan LINGUAS file for locales to process
72
file = open(linguas.abspath())
74
for line in file.readlines():
75
# ignore lines containing comments
76
if not line.startswith('#'):
79
re_linguas = re.compile('[-a-zA-Z_@.]+')
81
# Make sure that we only process lines which contain locales
82
if re_linguas.match(lang):
83
node = self.path.find_resource(os.path.join(podir, re_linguas.match(lang).group() + '.po'))
84
task = self.create_task('po')
86
task.set_outputs(node.change_ext('.mo'))
87
if self.bld.is_install: task.install = install_translation
89
Utils.pprint('RED', "Error no LINGUAS file found in po directory")
91
Task.simple_task_type('po', '${POCOM} -o ${TGT} ${SRC}', color='BLUE', shell=False)
92
Task.simple_task_type('intltool',
93
'${INTLTOOL} ${INTLFLAGS} ${INTLCACHE} ${INTLPODIR} ${SRC} ${TGT}',
94
color='BLUE', after="cc_link cxx_link", shell=False)
97
pocom = conf.find_program('msgfmt')
99
# if msgfmt should not be mandatory, catch the thrown exception in your wscript
100
conf.fatal('The program msgfmt (gettext) is mandatory!')
101
conf.env['POCOM'] = pocom
103
# NOTE: it is possible to set INTLTOOL in the environment, but it must not have spaces in it
105
intltool = conf.find_program('intltool-merge', var='INTLTOOL')
107
# if intltool-merge should not be mandatory, catch the thrown exception in your wscript
108
if Options.platform == 'win32':
109
perl = conf.find_program('perl', var='PERL')
111
conf.fatal('The program perl (required by intltool) could not be found')
113
intltooldir = Configure.find_file('intltool-merge', os.environ['PATH'].split(os.pathsep))
115
conf.fatal('The program intltool-merge (intltool, gettext-devel) is mandatory!')
117
conf.env['INTLTOOL'] = Utils.to_list(conf.env['PERL']) + [intltooldir + os.sep + 'intltool-merge']
118
conf.check_message('intltool', '', True, ' '.join(conf.env['INTLTOOL']))
120
conf.fatal('The program intltool-merge (intltool, gettext-devel) is mandatory!')
123
return getattr(Options.options, varname, '')
125
prefix = conf.env['PREFIX']
126
datadir = getstr('datadir')
127
if not datadir: datadir = os.path.join(prefix,'share')
129
conf.define('LOCALEDIR', os.path.join(datadir, 'locale'))
130
conf.define('DATADIR', datadir)
132
if conf.env['CC'] or conf.env['CXX']:
133
# Define to 1 if <locale.h> is present
134
conf.check(header_name='locale.h')
136
def set_options(opt):
137
opt.add_option('--want-rpath', type='int', default=1, dest='want_rpath', help='set rpath to 1 or 0 [Default 1]')
138
opt.add_option('--datadir', type='string', default='', dest='datadir', help='read-only application data')