Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 884ee23

Browse files
committed
Add setup.py 'refresh_translations' command.
1 parent 7036ae2 commit 884ee23

2 files changed

Lines changed: 43 additions & 10 deletions

File tree

INSTALL

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,10 @@ An RPM can be built and placed in the local rpmroot with:
1111
python setup.py rpm
1212

1313
Note this RPM has been catered to Fedora/Red Hat distros.
14+
15+
For translators, running:
16+
17+
python setup.py refresh_translations
18+
19+
Will regenerate po/virtinst.pot and merge existing translations with the
20+
new template file.

setup.py

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,32 @@ def run(self):
120120
self.run_command('sdist')
121121
os.system('rpmbuild -ta dist/virtinst-%s.tar.gz' % VERSION)
122122

123+
class refresh_translations(Command):
124+
125+
user_options = []
126+
127+
description = "Regenerate POT file and merge with current translations."
128+
129+
def initialize_options(self):
130+
pass
131+
132+
def finalize_options(self):
133+
pass
134+
135+
def run(self):
136+
137+
# Generate POT file
138+
files = [ "virtinst/*.py", "virtconv/*.py", "virtconv/parsers/*.py",
139+
"virt-*" ]
140+
pot_cmd = "xgettext --language=Python -o po/virtinst.pot"
141+
for f in files:
142+
pot_cmd += " %s " % f
143+
os.system(pot_cmd)
144+
145+
# Merge new template with existing translations.
146+
for po in glob(pjoin(os.getcwd(), 'po', '*.po')):
147+
os.system("msgmerge -U %s po/virtinst.pot" % po)
148+
123149
class sdist(_sdist):
124150
""" custom sdist command, to prep virtinst.spec file for inclusion """
125151

@@ -134,19 +160,18 @@ class build(_build):
134160

135161
def run(self):
136162
global builddir
137-
dirlist = os.listdir("po")
138163

139164
if not os.path.exists("build/po"):
140165
os.makedirs("build/po")
141166

142-
for filename in dirlist:
143-
if filename.endswith(".po"):
144-
lang = filename[0:len(filename)-3]
145-
if not os.path.exists("build/po/%s" % lang):
146-
os.makedirs("build/po/%s" % lang)
147-
newname = "build/po/%s/virtinst.mo" % lang
148-
print "Building %s from %s" % (newname, filename)
149-
os.system("msgfmt po/%s -o %s" % (filename, newname))
167+
for filename in glob(pjoin(os.getcwd(), 'po', '*.po')):
168+
lang = filename[0:len(filename)-3]
169+
if not os.path.exists("build/po/%s" % lang):
170+
os.makedirs("build/po/%s" % lang)
171+
newname = "build/po/%s/virtinst.mo" % lang
172+
173+
print "Building %s from %s" % (newname, filename)
174+
os.system("msgfmt po/%s -o %s" % (filename, newname))
150175

151176
_build.run(self)
152177
builddir = self.build_lib
@@ -209,5 +234,6 @@ def run(self):
209234
'sdist': sdist, 'build': build,
210235
'install_data' : install_data,
211236
'install_lib' : install_lib,
212-
'install' : install}
237+
'install' : install,
238+
'refresh_translations' : refresh_translations}
213239
)

0 commit comments

Comments
 (0)