Skip to content

Commit

Permalink
Fixed broken setup.py for data files and translations
Browse files Browse the repository at this point in the history
  • Loading branch information
muflone committed Oct 18, 2020
1 parent fd24188 commit 64b4c15
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ def run(self):
cmd_translations = Command_Translations(self.distribution)
cmd_translations.initialize_options()
cmd_translations.finalize_options()
cmd_translations.data_files = self.data_files
cmd_translations.run()
return
self.install_translations()
install_data.run(self)

def install_icons(self):
"""Add icons to the data files"""
info('Installing icons...')
DIR_ICONS = 'icons'
for icon_format in os.listdir(DIR_ICONS):
Expand All @@ -71,25 +71,6 @@ def install_icons(self):
os.path.join('share', 'icons', 'hicolor', icon_format, 'apps'),
glob.glob(os.path.join(icon_dir, '*'))))

def install_translations(self):
info('Installing translations...')
for po in glob.glob(os.path.join('po', '*.po')):
lang = os.path.basename(po[:-3])
mo = os.path.join('build', 'mo', lang, '%s.mo' % DOMAIN_NAME)

directory = os.path.dirname(mo)
if not os.path.exists(directory):
info('creating %s' % directory)
os.makedirs(directory)

cmd = 'msgfmt -o %s %s' % (mo, po)
info('compiling %s -> %s' % (po, mo))
if os.system(cmd) != 0:
raise SystemExit('Error while running msgfmt')

dest = os.path.join('share', 'locale', lang, 'LC_MESSAGES')
self.data_files.append((dest, [mo]))


class Command_Translation(Command):
description = "compile a translation"
Expand All @@ -108,6 +89,7 @@ def finalize_options(self):
assert (self.output), 'Missing output file'

def run(self):
"""Compile a single translation using self.input and self.output"""
lang = os.path.basename(self.input[:-3])
dir_lang = os.path.dirname(self.output)
if not os.path.exists(dir_lang):
Expand All @@ -133,6 +115,7 @@ def finalize_options(self):
self.dir_mo = os.path.join(self.dir_base, 'locale')

def run(self):
"""Compile every translation and add it to the data files"""
for file_po in glob.glob(os.path.join(self.dir_po, '*.po')):
file_mo = os.path.join(self.dir_mo,
os.path.basename(file_po[:-3]),
Expand All @@ -143,6 +126,8 @@ def run(self):
cmd_translation.input = file_po
cmd_translation.output = file_mo
cmd_translation.finalize_options()
# Add the translation files to the data files
cmd_translation.data_files = self.data_files
cmd_translation.run()


Expand Down

0 comments on commit 64b4c15

Please sign in to comment.