Package wafadmin :: Package Tools :: Module intltool
[hide private]
[frames] | no frames]

Source Code for Module wafadmin.Tools.intltool

  1  #!/usr/bin/env python 
  2  # encoding: utf-8 
  3  # Thomas Nagy, 2006 (ita) 
  4   
  5  "intltool support" 
  6   
  7  import os, re 
  8  import TaskGen, Task, Utils, Runner, Options, Build 
  9  import cc 
 10  from Logs import error 
 11   
 12  # intltool 
13 -class intltool_in_taskgen(TaskGen.task_gen):
14 - def __init__(self, *k):
15 TaskGen.task_gen.__init__(self, *k) 16 self.source = '' 17 self.flags = '' 18 self.podir = 'po' 19 self.intlcache = '.intlcache' 20 self.tasks = []
21
22 - def apply(self):
23 self.env = self.env.copy() 24 tree = Build.bld 25 for i in self.to_list(self.source): 26 node = self.path.find_resource(i) 27 28 podirnode = self.path.find_dir(self.podir) 29 30 self.env['INTLCACHE'] = os.path.join(self.path.bldpath(self.env), self.podir, self.intlcache) 31 self.env['INTLPODIR'] = podirnode.srcpath(self.env) 32 self.env['INTLFLAGS'] = self.flags 33 34 task = self.create_task('intltool') 35 task.set_inputs(node) 36 task.set_outputs(node.change_ext('')) 37 38 task.install_path = self.install_path
39
40 -class intltool_po_taskgen(TaskGen.task_gen):
41 - def __init__(self, *k, **kw):
42 TaskGen.task_gen.__init__(self, *k) 43 self.chmod = 0644 44 self.default_install_path = '${LOCALEDIR}' 45 self.appname = kw.get('appname', 'set_your_app_name') 46 self.podir = '' 47 self.tasks=[]
48
49 - def apply(self):
50 def install_translation(task): 51 out = task.outputs[0] 52 filename = out.name 53 (langname, ext) = os.path.splitext(filename) 54 inst_file = langname + os.sep + 'LC_MESSAGES' + os.sep + self.appname + '.mo' 55 Build.bld.install_as(self.install_path, out.abspath(self.env), chmod=self.chmod)
56 57 linguas = self.path.find_resource(os.path.join(self.podir, 'LINGUAS')) 58 if linguas: 59 # scan LINGUAS file for locales to process 60 file = open(linguas.abspath()) 61 langs = [] 62 for line in file.readlines(): 63 # ignore lines containing comments 64 if not line.startswith('#'): 65 langs += line.split() 66 file.close() 67 re_linguas = re.compile('[-a-zA-Z_@.]+') 68 for lang in langs: 69 # Make sure that we only process lines which contain locales 70 if re_linguas.match(lang): 71 node = self.path.find_resource(os.path.join(self.podir, re_linguas.match(lang).group() + '.po')) 72 task = self.create_task('po') 73 task.set_inputs(node) 74 task.set_outputs(node.change_ext('.mo')) 75 if Options.is_install: task.install = install_translation 76 else: 77 Utils.pprint('RED', "Error no LINGUAS file found in po directory")
78 79 Task.simple_task_type('po', '${POCOM} -o ${TGT} ${SRC}', color='BLUE') 80 Task.simple_task_type('intltool', 81 '${INTLTOOL} ${INTLFLAGS} -q -u -c ${INTLCACHE} ${INTLPODIR} ${SRC} ${TGT}', 82 color='BLUE', after="cc_link cxx_link") 83
84 -def detect(conf):
85 86 conf.check_tool('checks') 87 88 pocom = conf.find_program('msgfmt') 89 #if not pocom: 90 # conf.fatal('The program msgfmt (gettext) is mandatory!') 91 conf.env['POCOM'] = pocom 92 93 intltool = conf.find_program('intltool-merge') 94 #if not intltool: 95 # conf.fatal('The program intltool-merge (intltool, gettext-devel) is mandatory!') 96 conf.env['INTLTOOL'] = intltool 97 98 def getstr(varname): 99 return getattr(Options.options, varname, '')
100 101 prefix = conf.env['PREFIX'] 102 datadir = getstr('datadir') 103 if not datadir: datadir = os.path.join(prefix,'share') 104 105 conf.define('LOCALEDIR', os.path.join(datadir, 'locale')) 106 conf.define('DATADIR', datadir) 107 108 #Define to 1 if you have the <locale.h> header file. 109 conf.check_header('locale.h', 'HAVE_LOCALE_H') 110
111 -def set_options(opt):
112 opt.add_option('--want-rpath', type='int', default=1, dest='want_rpath', help='set rpath to 1 or 0 [Default 1]') 113 opt.add_option('--datadir', type='string', default='', dest='datadir', help='read-only application data')
114