~ubuntu-branches/ubuntu/raring/xmms2/raring

« back to all changes in this revision

Viewing changes to waflib/Tools/intltool.py

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2012-11-25 19:23:15 UTC
  • mto: This revision was merged to the branch mainline in revision 51.
  • Revision ID: package-import@ubuntu.com-20121125192315-m9z6nu9wwlzrrz9z
ImportĀ upstreamĀ versionĀ 0.8+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
# encoding: utf-8
 
3
# WARNING! Do not edit! http://waf.googlecode.com/svn/docs/wafbook/single.html#_obtaining_the_waf_file
 
4
 
 
5
import os,re
 
6
from waflib import Configure,TaskGen,Task,Utils,Runner,Options,Build,Logs
 
7
import waflib.Tools.ccroot
 
8
from waflib.TaskGen import feature,before_method
 
9
from waflib.Logs import error
 
10
def apply_intltool_in_f(self):
 
11
        try:self.meths.remove('process_source')
 
12
        except ValueError:pass
 
13
        if not self.env.LOCALEDIR:
 
14
                self.env.LOCALEDIR=self.env.PREFIX+'/share/locale'
 
15
        for i in self.to_list(self.source):
 
16
                node=self.path.find_resource(i)
 
17
                podir=getattr(self,'podir','po')
 
18
                podirnode=self.path.find_dir(podir)
 
19
                if not podirnode:
 
20
                        error("could not find the podir %r"%podir)
 
21
                        continue
 
22
                cache=getattr(self,'intlcache','.intlcache')
 
23
                self.env['INTLCACHE']=os.path.join(self.path.bldpath(),podir,cache)
 
24
                self.env['INTLPODIR']=podirnode.bldpath()
 
25
                self.env['INTLFLAGS']=getattr(self,'flags',['-q','-u','-c'])
 
26
                task=self.create_task('intltool',node,node.change_ext(''))
 
27
                inst=getattr(self,'install_path','${LOCALEDIR}')
 
28
                if inst:
 
29
                        self.bld.install_files(inst,task.outputs)
 
30
def apply_intltool_po(self):
 
31
        try:self.meths.remove('process_source')
 
32
        except ValueError:pass
 
33
        if not self.env.LOCALEDIR:
 
34
                self.env.LOCALEDIR=self.env.PREFIX+'/share/locale'
 
35
        appname=getattr(self,'appname','set_your_app_name')
 
36
        podir=getattr(self,'podir','')
 
37
        inst=getattr(self,'install_path','${LOCALEDIR}')
 
38
        linguas=self.path.find_node(os.path.join(podir,'LINGUAS'))
 
39
        if linguas:
 
40
                file=open(linguas.abspath())
 
41
                langs=[]
 
42
                for line in file.readlines():
 
43
                        if not line.startswith('#'):
 
44
                                langs+=line.split()
 
45
                file.close()
 
46
                re_linguas=re.compile('[-a-zA-Z_@.]+')
 
47
                for lang in langs:
 
48
                        if re_linguas.match(lang):
 
49
                                node=self.path.find_resource(os.path.join(podir,re_linguas.match(lang).group()+'.po'))
 
50
                                task=self.create_task('po',node,node.change_ext('.mo'))
 
51
                                if inst:
 
52
                                        filename=task.outputs[0].name
 
53
                                        (langname,ext)=os.path.splitext(filename)
 
54
                                        inst_file=inst+os.sep+langname+os.sep+'LC_MESSAGES'+os.sep+appname+'.mo'
 
55
                                        self.bld.install_as(inst_file,task.outputs[0],chmod=getattr(self,'chmod',Utils.O644),env=task.env)
 
56
        else:
 
57
                Logs.pprint('RED',"Error no LINGUAS file found in po directory")
 
58
class po(Task.Task):
 
59
        run_str='${MSGFMT} -o ${TGT} ${SRC}'
 
60
        color='BLUE'
 
61
class intltool(Task.Task):
 
62
        run_str='${INTLTOOL} ${INTLFLAGS} ${INTLCACHE} ${INTLPODIR} ${SRC} ${TGT}'
 
63
        color='BLUE'
 
64
def configure(conf):
 
65
        conf.find_program('msgfmt',var='MSGFMT')
 
66
        conf.find_perl_program('intltool-merge',var='INTLTOOL')
 
67
        prefix=conf.env.PREFIX
 
68
        datadir=conf.env.DATADIR
 
69
        if not datadir:
 
70
                datadir=os.path.join(prefix,'share')
 
71
        conf.define('LOCALEDIR',os.path.join(datadir,'locale').replace('\\','\\\\'))
 
72
        conf.define('DATADIR',datadir.replace('\\','\\\\'))
 
73
        if conf.env.CC or conf.env.CXX:
 
74
                conf.check(header_name='locale.h')
 
75
 
 
76
before_method('process_source')(apply_intltool_in_f)
 
77
feature('intltool_in')(apply_intltool_in_f)
 
78
feature('intltool_po')(apply_intltool_po)
 
 
b'\\ No newline at end of file'