@@ -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
341365class Bower (Command ):
342366 description = "fetch static client-side components with bower"
@@ -467,7 +491,7 @@ def run(self):
467491
468492
469493class 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