@@ -337,6 +337,21 @@ 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+ def run (self ):
344+ paths = glob ('notebook/i18n/??_??' )
345+ for p in paths :
346+ LANG = p .split ('/' )[- 1 ]
347+ for component in ['notebook' , 'nbui' ]:
348+ run (['pybabel' , 'compile' ,
349+ '-D' , component ,
350+ '-f' ,
351+ '-l' , LANG ,
352+ '-i' , pjoin ('notebook' , 'i18n' , LANG , 'LC_MESSAGES' , 'notebook.po' ),
353+ '-o' , pjoin ('notebook' , 'i18n' , LANG , 'LC_MESSAGES' , 'notebook.mo' )
354+ ])
340355
341356class Bower (Command ):
342357 description = "fetch static client-side components with bower"
@@ -467,7 +482,7 @@ def run(self):
467482
468483
469484class CompileJS (Command ):
470- """Rebuild Notebook Javascript main.min.js files
485+ """Rebuild Notebook Javascript main.min.js files and translation files.
471486
472487 Calls require via build-main.js
473488 """
@@ -526,12 +541,16 @@ def build_main(self, name):
526541 log .info ("Rebuilding %s" % target )
527542 run (['node' , 'tools/build-main.js' , name ])
528543
544+ def build_jstranslation (self , trd ):
545+ run (['po2json' , '-p' , '-F' , '-f' , 'jed1.x' , '-d' , 'nbjs' , trd + '/LC_MESSAGES/nbjs.po' , trd + '/LC_MESSAGES/nbjs.json' ])
546+
529547 def run (self ):
530548 self .run_command ('jsdeps' )
531549 env = os .environ .copy ()
532550 env ['PATH' ] = npm_path
533551 pool = ThreadPool ()
534552 pool .map (self .build_main , self .apps )
553+ pool .map (self .build_jstranslation , glob ('notebook/i18n/??_??' ))
535554 # update package data in case this created new files
536555 update_package_data (self .distribution )
537556
@@ -586,6 +605,7 @@ def run(self):
586605 try :
587606 self .distribution .run_command ('js' )
588607 self .distribution .run_command ('css' )
608+ self .distribution .run_command ('backendtranslations' )
589609 except Exception as e :
590610 # refresh missing
591611 missing = [ t for t in targets if not os .path .exists (t ) ]
0 commit comments