Commit 0e744b39 by Piotr Mitros Committed by GitHub

Merge pull request #46 from ziafazal/ziafazal/custom-build-steps

This PR compiles translations during the XBlock install process. A future PR will remove them during uninstall :)
parents 8d10afe2 32e16a03
"""Setup for recommender XBlock."""
import os
import subprocess
from setuptools.command.install import install as _install
from setuptools import setup
class XBlockInstall(_install):
"""Custom XBlock install command."""
def run(self):
_install.run(self)
self.compile_translations()
def compile_translations(self):
"""
Compiles textual translations files(.po) to binary(.mo) files.
"""
self.announce('Compiling translations')
try:
for dirname, _, files in os.walk(os.path.join('recommender', 'translations')):
for fname in files:
if os.path.splitext(fname)[1] == '.po':
po_path = os.path.join(dirname, fname)
mo_path = os.path.splitext(po_path)[0] + '.mo'
self.announce('Compiling translation at %s' % po_path)
subprocess.check_call(['msgfmt', po_path, '-o', mo_path], cwd=self.install_lib)
except Exception as ex:
self.announce('Translations compilation failed: %s', ex.message)
def package_data(pkg, root_list):
"""Generic function to find package_data for `pkg` under `root`."""
data = []
......@@ -28,4 +54,7 @@ setup(
]
},
package_data=package_data("recommender", ["static", "translations"]),
cmdclass={
'install': XBlockInstall,
},
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment