diff --git a/appveyor.yml b/appveyor.yml index c513c6f83..3f58159ad 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -20,6 +20,7 @@ install: - cmd: conda config --add channels conda-forge #- cmd: conda update --yes --quiet conda - cmd: conda install -y pyzmq tornado jupyter_client nbformat nbconvert ipykernel pip nodejs nose + - cmd: python setup.py build - cmd: pip install .[test] test_script: diff --git a/package.json b/package.json index 1cf8a1848..062978e8a 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,8 @@ "devDependencies": { "bower": "*", "less": "~2", - "requirejs": "^2.1.17" + "requirejs": "^2.1.17", + "po2json": "^0.4.5" }, "dependencies": {} } diff --git a/setup.py b/setup.py index 6d60391db..b58e847f2 100755 --- a/setup.py +++ b/setup.py @@ -40,6 +40,7 @@ from setupbase import ( check_package_data_first, CompileCSS, CompileJS, + CompileBackendTranslation, Bower, JavascriptVersion, css_js_prerelease, @@ -131,6 +132,7 @@ setup_args['cmdclass'] = { 'sdist' : css_js_prerelease(sdist, strict=True), 'develop': css_js_prerelease(develop), 'css' : CompileCSS, + 'backendtranslations': CompileBackendTranslation, 'js' : CompileJS, 'jsdeps' : Bower, 'jsversion' : JavascriptVersion, diff --git a/setupbase.py b/setupbase.py index d362eadc0..1b1549c54 100644 --- a/setupbase.py +++ b/setupbase.py @@ -337,6 +337,30 @@ def run(cmd, *args, **kwargs): kwargs['shell'] = (sys.platform == 'win32') return check_call(cmd, *args, **kwargs) +class CompileBackendTranslation(Command): + description = "compile the .po files into .mo files, that contain the translations." + + user_options = [] + + def initialize_options(self): + pass + + def finalize_options(self): + pass + + + def run(self): + paths = glob('notebook/i18n/??_??') + for p in paths: + LANG = p[-5:] + for component in ['notebook', 'nbui']: + run(['pybabel', 'compile', + '-D', component, + '-f', + '-l', LANG, + '-i', pjoin('notebook', 'i18n', LANG, 'LC_MESSAGES', component+'.po'), + '-o', pjoin('notebook', 'i18n', LANG, 'LC_MESSAGES', component+'.mo') + ]) class Bower(Command): description = "fetch static client-side components with bower" @@ -467,7 +491,7 @@ class CompileCSS(Command): class CompileJS(Command): - """Rebuild Notebook Javascript main.min.js files + """Rebuild Notebook Javascript main.min.js files and translation files. Calls require via build-main.js """ @@ -515,23 +539,35 @@ class CompileJS(Command): print(source, target) return True return False - + def build_main(self, name): """Build main.min.js""" target = pjoin(static, name, 'js', 'main.min.js') - + if not self.should_run(name, target): log.info("%s up to date" % target) return log.info("Rebuilding %s" % target) run(['node', 'tools/build-main.js', name]) + def build_jstranslation(self, trd): + lang = trd[-5:] + run([ + pjoin('node_modules', '.bin', 'po2json'), + '-p', '-F', + '-f', 'jed1.x', + '-d', 'nbjs', + pjoin('notebook', 'i18n', lang, 'LC_MESSAGES', 'nbjs.po'), + pjoin('notebook', 'i18n', lang, 'LC_MESSAGES', 'nbjs.json'), + ]) + def run(self): self.run_command('jsdeps') env = os.environ.copy() env['PATH'] = npm_path pool = ThreadPool() pool.map(self.build_main, self.apps) + pool.map(self.build_jstranslation, glob('notebook/i18n/??_??')) # update package data in case this created new files update_package_data(self.distribution) @@ -586,6 +622,7 @@ def css_js_prerelease(command, strict=False): try: self.distribution.run_command('js') self.distribution.run_command('css') + self.distribution.run_command('backendtranslations') except Exception as e: # refresh missing missing = [ t for t in targets if not os.path.exists(t) ]