mirror of
https://github.com/jupyter/notebook.git
synced 2024-11-27 03:20:27 +08:00
Build js translation at build time.
Make sure they are included in sdist/wheel.
This commit is contained in:
parent
bb07253ff4
commit
d239839e07
@ -29,7 +29,7 @@ before_install:
|
|||||||
- node --version
|
- node --version
|
||||||
- npm --version
|
- npm --version
|
||||||
- npm upgrade -g npm
|
- npm upgrade -g npm
|
||||||
- npm install
|
- npm install -g po2json@0.4.5
|
||||||
- |
|
- |
|
||||||
if [[ $GROUP == js* ]]; then
|
if [[ $GROUP == js* ]]; then
|
||||||
npm install -g casperjs@1.1.3 phantomjs-prebuilt@2.1.7
|
npm install -g casperjs@1.1.3 phantomjs-prebuilt@2.1.7
|
||||||
|
@ -16,7 +16,8 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"bower": "*",
|
"bower": "*",
|
||||||
"less": "~2",
|
"less": "~2",
|
||||||
"requirejs": "^2.1.17"
|
"requirejs": "^2.1.17",
|
||||||
|
"po2json": "^0.4.5"
|
||||||
},
|
},
|
||||||
"dependencies": {}
|
"dependencies": {}
|
||||||
}
|
}
|
||||||
|
2
setup.py
2
setup.py
@ -40,6 +40,7 @@ from setupbase import (
|
|||||||
check_package_data_first,
|
check_package_data_first,
|
||||||
CompileCSS,
|
CompileCSS,
|
||||||
CompileJS,
|
CompileJS,
|
||||||
|
CompileBackendTranslation,
|
||||||
Bower,
|
Bower,
|
||||||
JavascriptVersion,
|
JavascriptVersion,
|
||||||
css_js_prerelease,
|
css_js_prerelease,
|
||||||
@ -131,6 +132,7 @@ setup_args['cmdclass'] = {
|
|||||||
'sdist' : css_js_prerelease(sdist, strict=True),
|
'sdist' : css_js_prerelease(sdist, strict=True),
|
||||||
'develop': css_js_prerelease(develop),
|
'develop': css_js_prerelease(develop),
|
||||||
'css' : CompileCSS,
|
'css' : CompileCSS,
|
||||||
|
'backendtranslations': CompileBackendTranslation,
|
||||||
'js' : CompileJS,
|
'js' : CompileJS,
|
||||||
'jsdeps' : Bower,
|
'jsdeps' : Bower,
|
||||||
'jsversion' : JavascriptVersion,
|
'jsversion' : JavascriptVersion,
|
||||||
|
37
setupbase.py
37
setupbase.py
@ -337,6 +337,30 @@ def run(cmd, *args, **kwargs):
|
|||||||
kwargs['shell'] = (sys.platform == 'win32')
|
kwargs['shell'] = (sys.platform == 'win32')
|
||||||
return check_call(cmd, *args, **kwargs)
|
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.split('/')[-1]
|
||||||
|
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):
|
class Bower(Command):
|
||||||
description = "fetch static client-side components with bower"
|
description = "fetch static client-side components with bower"
|
||||||
@ -467,7 +491,7 @@ class CompileCSS(Command):
|
|||||||
|
|
||||||
|
|
||||||
class CompileJS(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
|
Calls require via build-main.js
|
||||||
"""
|
"""
|
||||||
@ -526,12 +550,22 @@ class CompileJS(Command):
|
|||||||
log.info("Rebuilding %s" % target)
|
log.info("Rebuilding %s" % target)
|
||||||
run(['node', 'tools/build-main.js', name])
|
run(['node', 'tools/build-main.js', name])
|
||||||
|
|
||||||
|
def build_jstranslation(self, trd):
|
||||||
|
lang = trd.split('/')[2]
|
||||||
|
run(['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):
|
def run(self):
|
||||||
self.run_command('jsdeps')
|
self.run_command('jsdeps')
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
env['PATH'] = npm_path
|
env['PATH'] = npm_path
|
||||||
pool = ThreadPool()
|
pool = ThreadPool()
|
||||||
pool.map(self.build_main, self.apps)
|
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 in case this created new files
|
||||||
update_package_data(self.distribution)
|
update_package_data(self.distribution)
|
||||||
|
|
||||||
@ -586,6 +620,7 @@ def css_js_prerelease(command, strict=False):
|
|||||||
try:
|
try:
|
||||||
self.distribution.run_command('js')
|
self.distribution.run_command('js')
|
||||||
self.distribution.run_command('css')
|
self.distribution.run_command('css')
|
||||||
|
self.distribution.run_command('backendtranslations')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# refresh missing
|
# refresh missing
|
||||||
missing = [ t for t in targets if not os.path.exists(t) ]
|
missing = [ t for t in targets if not os.path.exists(t) ]
|
||||||
|
Loading…
Reference in New Issue
Block a user