@@ -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 [- 5 :]
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 """
@@ -515,23 +539,35 @@ def should_run(self, name, target):
515539 print (source , target )
516540 return True
517541 return False
518-
542+
519543 def build_main (self , name ):
520544 """Build main.min.js"""
521545 target = pjoin (static , name , 'js' , 'main.min.js' )
522-
546+
523547 if not self .should_run (name , target ):
524548 log .info ("%s up to date" % target )
525549 return
526550 log .info ("Rebuilding %s" % target )
527551 run (['node' , 'tools/build-main.js' , name ])
528552
553+ def build_jstranslation (self , trd ):
554+ lang = trd [- 5 :]
555+ run ([
556+ pjoin ('node_modules' , '.bin' , 'po2json' ),
557+ '-p' , '-F' ,
558+ '-f' , 'jed1.x' ,
559+ '-d' , 'nbjs' ,
560+ pjoin ('notebook' , 'i18n' , lang , 'LC_MESSAGES' , 'nbjs.po' ),
561+ pjoin ('notebook' , 'i18n' , lang , 'LC_MESSAGES' , 'nbjs.json' ),
562+ ])
563+
529564 def run (self ):
530565 self .run_command ('jsdeps' )
531566 env = os .environ .copy ()
532567 env ['PATH' ] = npm_path
533568 pool = ThreadPool ()
534569 pool .map (self .build_main , self .apps )
570+ pool .map (self .build_jstranslation , glob ('notebook/i18n/??_??' ))
535571 # update package data in case this created new files
536572 update_package_data (self .distribution )
537573
@@ -586,6 +622,7 @@ def run(self):
586622 try :
587623 self .distribution .run_command ('js' )
588624 self .distribution .run_command ('css' )
625+ self .distribution .run_command ('backendtranslations' )
589626 except Exception as e :
590627 # refresh missing
591628 missing = [ t for t in targets if not os .path .exists (t ) ]
0 commit comments