@@ -337,6 +337,30 @@ def run(cmd, *args, **kwargs):
337
337
kwargs ['shell' ] = (sys .platform == 'win32' )
338
338
return check_call (cmd , * args , ** kwargs )
339
339
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
+ ])
340
364
341
365
class Bower (Command ):
342
366
description = "fetch static client-side components with bower"
@@ -467,7 +491,7 @@ def run(self):
467
491
468
492
469
493
class CompileJS (Command ):
470
- """Rebuild Notebook Javascript main.min.js files
494
+ """Rebuild Notebook Javascript main.min.js files and translation files.
471
495
472
496
Calls require via build-main.js
473
497
"""
@@ -526,12 +550,22 @@ def build_main(self, name):
526
550
log .info ("Rebuilding %s" % target )
527
551
run (['node' , 'tools/build-main.js' , name ])
528
552
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
+
529
562
def run (self ):
530
563
self .run_command ('jsdeps' )
531
564
env = os .environ .copy ()
532
565
env ['PATH' ] = npm_path
533
566
pool = ThreadPool ()
534
567
pool .map (self .build_main , self .apps )
568
+ pool .map (self .build_jstranslation , glob ('notebook/i18n/??_??' ))
535
569
# update package data in case this created new files
536
570
update_package_data (self .distribution )
537
571
@@ -586,6 +620,7 @@ def run(self):
586
620
try :
587
621
self .distribution .run_command ('js' )
588
622
self .distribution .run_command ('css' )
623
+ self .distribution .run_command ('backendtranslations' )
589
624
except Exception as e :
590
625
# refresh missing
591
626
missing = [ t for t in targets if not os .path .exists (t ) ]
0 commit comments