Prepared ugit for i18n support
[git-cola.git] / buildutils / po2qm.py
blob098f64bd25319cd3e4fec80e31683e5802611a05
1 #!/usr/bin/env python
2 import os
3 import Action
4 import Object
5 import Params
6 import Utils
7 import Common
9 "Converts .po files to the Qt .qm format"
11 NAME='po2qm'
12 class po2qm_obj(Object.genobj):
14 s_default_ext = ['.po']
15 def __init__(self):
16 Object.genobj.__init__(self, 'other')
17 self.inst_var = 'QMDIR'
18 self.prio = 101
19 self.inst_dir = ''
20 self.chmod = 0644
22 def apply(self):
23 # create the nodes corresponding to the sources
24 for filename in self.to_list(self.source):
26 base, ext = os.path.splitext(filename)
27 if not ext in self.s_default_ext:
28 Params.fatal("unknown file " + filename)
30 split_filename = Utils.split_path(filename)
31 node = self.path.find_source_lst(split_filename)
33 task = self.create_task(NAME, self.env, 101)
34 task.set_inputs(node)
35 task.set_outputs(node.change_ext('.qm'))
37 def install(self):
38 for i in self.m_tasks:
39 current = Params.g_build.m_curdirnode
40 lst=[a.relpath_gen(current) for a in i.m_outputs]
41 Common.install_files(self.inst_var, self.inst_dir, lst, chmod=self.chmod)
43 def setup(env):
44 Object.register(NAME, po2qm_obj)
45 Action.simple_action(NAME, '${MSGFMT} ${MSGFMT_FLAGS} -o ${TGT} ${SRC}', color='YELLOW')
47 def detect(conf):
48 if not conf.find_program('msgfmt', var='MSGFMT'):
49 return False
50 conf.env['MSGFMT_FLAGS'] = '--qt'
51 conf.env['MSGFMT_EXT'] = ['.po']
52 conf.env['QMDIR'] = os.path.join(
53 conf.env['PREFIX'], 'share',
54 Utils.g_module.APPNAME, 'qm')
55 return True