~online-accounts/unity-scope-gdrive/trunk

« back to all changes in this revision

Viewing changes to build_i18n_ext.py

  • Committer: Ken VanDine
  • Date: 2012-09-19 17:57:04 UTC
  • mfrom: (12.2.2 trunk)
  • Revision ID: ken.vandine@canonical.com-20120919175704-wtxmlavm74jcaqp8
merged

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
#
 
3
from DistUtilsExtra.command import build_i18n as build_i18n_orig
 
4
import os
 
5
import os.path
 
6
 
 
7
class build_i18n(build_i18n_orig.build_i18n):
 
8
    user_options = build_i18n_orig.build_i18n.user_options + \
 
9
        [('xml_files_no_trans=', None, '.xml.in files which should be '
 
10
                                       'left with the unlocalised '
 
11
                                       'texts')]
 
12
 
 
13
    def initialize_options(self):
 
14
        build_i18n_orig.build_i18n.initialize_options(self)
 
15
        self.xml_files_no_trans = []
 
16
 
 
17
    def run(self):
 
18
        build_i18n_orig.build_i18n.run(self)
 
19
        data_files = self.distribution.data_files
 
20
 
 
21
        # merge .in with translation
 
22
        try:
 
23
            file_set = eval(self.xml_files_no_trans)
 
24
        except:
 
25
            return
 
26
        for (target, files) in file_set:
 
27
            build_target = os.path.join("build", target)
 
28
            if not os.path.exists(build_target): 
 
29
                os.makedirs(build_target)
 
30
            files_merged = []
 
31
            for file in files:
 
32
                if file.endswith(".in"):
 
33
                    file_merged = os.path.basename(file[:-3])
 
34
                else:
 
35
                    file_merged = os.path.basename(file)
 
36
                file_merged = os.path.join(build_target, file_merged)
 
37
                cmd = ["intltool-merge", "-x", "-u", "--no-translations",
 
38
                       file, file_merged]
 
39
                self.spawn(cmd)
 
40
                files_merged.append(file_merged)
 
41
            data_files.append((target, files_merged))