I know this question begins to be a bit old, but in case anyone's still looking for an answer: it's possible to add a function to setup.py
that will compile po files and return the data_files
list. I didn't choose to include them in package_data
because data_files
's description looked more appropriate:
configuration files, message catalogs, data files, anything which doesn’t fit in the previous categories.
Of course you can only append this list to the one you're already using, but assuming you only have these mo files to add in data_files, you can write:
setup(
.
.
.
data_files=create_mo_files(),
.
.
.
)
For your information, here's the function create_mo_files()
I use. I don't pretend it's the best implementation possible. I put it here because it looks useful and is easy to adapt. Note that it's a bit more extra-complicated than what you need because it doesn't assume there's only one po file to compile per directory, it deals with several instead; note also that it assumes that all po files are located in something like locale/language/LC_MESSAGES/*.po
, you'll have to change it to fit your needs:
def create_mo_files():
data_files = []
localedir = 'relative/path/to/locale'
po_dirs = [localedir + '/' + l + '/LC_MESSAGES/'
for l in next(os.walk(localedir))[1]]
for d in po_dirs:
mo_files = []
po_files = [f
for f in next(os.walk(d))[2]
if os.path.splitext(f)[1] == '.po']
for po_file in po_files:
filename, extension = os.path.splitext(po_file)
mo_file = filename + '.mo'
msgfmt_cmd = 'msgfmt {} -o {}'.format(d + po_file, d + mo_file)
subprocess.call(msgfmt_cmd, shell=True)
mo_files.append(d + mo_file)
data_files.append((d, mo_files))
return data_files
(you'll have to import os
and subprocess
to use it)