1
"""distutils_extra.command.build_i18n
3
Implements the Distutils 'build_i18n' command."""
11
import distutils.command.build
13
class build_i18n(distutils.cmd.Command):
15
description = "integrate the gettext framework"
17
user_options = [('desktop-files=', None, '.desktop.in files that '
19
('xml-files=', None, '.xml.in files that should be '
21
('schemas-files=', None, '.schemas.in files that '
23
('ba-files=', None, 'bonobo-activation files that '
25
('rfc822deb-files=', None, 'RFC822 files that should '
27
('key-files=', None, '.key.in files that should be '
29
('domain=', 'd', 'gettext domain'),
30
('merge-po', 'm', 'merge po files against template'),
31
('po-dir=', 'p', 'directory that holds the i18n files'),
32
('bug-contact=', None, 'contact address for msgid bugs')]
34
boolean_options = ['merge-po']
36
def initialize_options(self):
37
self.desktop_files = []
40
self.schemas_files = []
42
self.rfc822deb_files = []
45
self.bug_contact = None
48
def finalize_options(self):
49
if self.domain is None:
50
self.domain = self.distribution.metadata.name
51
if self.po_dir is None:
56
Update the language files, generate mo files and add them
57
to the to be installed files
59
data_files = self.distribution.data_files
61
if self.bug_contact is not None:
62
os.environ["XGETTEXT_ARGS"] = "--msgid-bugs-address=%s " % \
65
# Print a warning if there is a Makefile that would overwrite our
67
if os.path.exists("%s/Makefile" % self.po_dir):
69
WARNING: Intltool will use the values specified from the
70
existing po/Makefile in favor of the vaules
72
Remove the Makefile to avoid problems.""")
74
# Update po(t) files and print a report
75
# We have to change the working dir to the po dir for intltool
76
cmd = ["intltool-update", (self.merge_po and "-r" or "-p"), "-g", self.domain]
82
for po_file in glob.glob("%s/*.po" % self.po_dir):
83
lang = os.path.basename(po_file[:-3])
84
mo_dir = os.path.join("build", "mo", lang, "LC_MESSAGES")
85
mo_file = os.path.join(mo_dir, "%s.mo" % self.domain)
86
if not os.path.exists(mo_dir):
88
cmd = ["msgfmt", po_file, "-o", mo_file]
91
targetpath = os.path.join("share/locale", lang, "LC_MESSAGES")
92
data_files.append((targetpath, (mo_file,)))
94
# merge .in with translation
95
for (option, switch) in ((self.xml_files, "-x"),
96
(self.desktop_files, "-d"),
97
(self.schemas_files, "-s"),
98
(self.rfc822deb_files, "-r"),
99
(self.ba_files, "-b"),
100
(self.key_files, "-k"),):
102
file_set = eval(option)
105
for (target, files) in file_set:
106
build_target = os.path.join("build", target)
107
if not os.path.exists(build_target):
108
os.makedirs(build_target)
111
if file.endswith(".in"):
112
file_merged = os.path.basename(file[:-3])
114
file_merged = os.path.basename(file)
115
file_merged = os.path.join(build_target, file_merged)
116
cmd = ["intltool-merge", switch, self.po_dir, file,
119
files_merged.append(file_merged)
120
data_files.append((target, files_merged))