Skip to content

Commit d239839

Browse files
committed
Build js translation at build time.
Make sure they are included in sdist/wheel.
1 parent bb07253 commit d239839

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ before_install:
2929
- node --version
3030
- npm --version
3131
- npm upgrade -g npm
32-
- npm install
32+
- npm install -g [email protected]
3333
- |
3434
if [[ $GROUP == js* ]]; then
3535

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"devDependencies": {
1717
"bower": "*",
1818
"less": "~2",
19-
"requirejs": "^2.1.17"
19+
"requirejs": "^2.1.17",
20+
"po2json": "^0.4.5"
2021
},
2122
"dependencies": {}
2223
}

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
check_package_data_first,
4141
CompileCSS,
4242
CompileJS,
43+
CompileBackendTranslation,
4344
Bower,
4445
JavascriptVersion,
4546
css_js_prerelease,
@@ -131,6 +132,7 @@ def run(self):
131132
'sdist' : css_js_prerelease(sdist, strict=True),
132133
'develop': css_js_prerelease(develop),
133134
'css' : CompileCSS,
135+
'backendtranslations': CompileBackendTranslation,
134136
'js' : CompileJS,
135137
'jsdeps' : Bower,
136138
'jsversion' : JavascriptVersion,

setupbase.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,30 @@ def run(cmd, *args, **kwargs):
337337
kwargs['shell'] = (sys.platform == 'win32')
338338
return check_call(cmd, *args, **kwargs)
339339

340+
class CompileBackendTranslation(Command):
341+
description = "compile the .po files into .mo files, that contain the translations."
342+
343+
user_options = []
344+
345+
def initialize_options(self):
346+
pass
347+
348+
def finalize_options(self):
349+
pass
350+
351+
352+
def run(self):
353+
paths = glob('notebook/i18n/??_??')
354+
for p in paths:
355+
LANG = p.split('/')[-1]
356+
for component in ['notebook', 'nbui']:
357+
run(['pybabel', 'compile',
358+
'-D', component,
359+
'-f',
360+
'-l', LANG,
361+
'-i', pjoin('notebook', 'i18n', LANG, 'LC_MESSAGES', component+'.po'),
362+
'-o', pjoin('notebook', 'i18n', LANG, 'LC_MESSAGES', component+'.mo')
363+
])
340364

341365
class Bower(Command):
342366
description = "fetch static client-side components with bower"
@@ -467,7 +491,7 @@ def run(self):
467491

468492

469493
class CompileJS(Command):
470-
"""Rebuild Notebook Javascript main.min.js files
494+
"""Rebuild Notebook Javascript main.min.js files and translation files.
471495
472496
Calls require via build-main.js
473497
"""
@@ -526,12 +550,22 @@ def build_main(self, name):
526550
log.info("Rebuilding %s" % target)
527551
run(['node', 'tools/build-main.js', name])
528552

553+
def build_jstranslation(self, trd):
554+
lang = trd.split('/')[2]
555+
run(['po2json', '-p', '-F',
556+
'-f', 'jed1.x',
557+
'-d', 'nbjs',
558+
pjoin('notebook', 'i18n', lang ,'LC_MESSAGES', 'nbjs.po'),
559+
pjoin('notebook', 'i18n', lang, 'LC_MESSAGES', 'nbjs.json')
560+
])
561+
529562
def run(self):
530563
self.run_command('jsdeps')
531564
env = os.environ.copy()
532565
env['PATH'] = npm_path
533566
pool = ThreadPool()
534567
pool.map(self.build_main, self.apps)
568+
pool.map(self.build_jstranslation, glob('notebook/i18n/??_??'))
535569
# update package data in case this created new files
536570
update_package_data(self.distribution)
537571

@@ -586,6 +620,7 @@ def run(self):
586620
try:
587621
self.distribution.run_command('js')
588622
self.distribution.run_command('css')
623+
self.distribution.run_command('backendtranslations')
589624
except Exception as e:
590625
# refresh missing
591626
missing = [ t for t in targets if not os.path.exists(t) ]

0 commit comments

Comments
 (0)