#NEWLINE# def process( self , command , potfile , domain , keep_pot = False ) : #NEWLINE# #INDENT# '\n        Extract translatable literals from self.file for :param domain:\n        creating or updating the :param potfile: POT file.\n\n        Uses the xgettext GNU gettext utility.\n        ' #NEWLINE# from django.utils.translation import templatize #NEWLINE# if ( command . verbosity > 1 ) : #NEWLINE# #INDENT# command . stdout . write ( ( 'processing file %s in %s\n' % ( self . file , self . dirpath ) ) ) #NEWLINE# #UNINDENT# ( _ , file_ext ) = os . path . splitext ( self . file ) #NEWLINE# if ( ( domain == 'djangojs' ) and ( file_ext in command . extensions ) ) : #NEWLINE# #INDENT# is_templatized = True #NEWLINE# orig_file = os . path . join ( self . dirpath , self . file ) #NEWLINE# with open ( orig_file ) as fp : #NEWLINE# #INDENT# src_data = fp . read ( ) #NEWLINE# #UNINDENT# src_data = prepare_js_for_gettext ( src_data ) #NEWLINE# thefile = ( '%s.c' % self . file ) #NEWLINE# work_file = os . path . join ( self . dirpath , thefile ) #NEWLINE# with open ( work_file , 'w' ) as fp : #NEWLINE# #INDENT# fp . write ( src_data ) #NEWLINE# #UNINDENT# args = [ 'xgettext' , '-d' , domain , '--language=C' , '--keyword=gettext_noop' , '--keyword=gettext_lazy' , '--keyword=ngettext_lazy:1,2' , '--keyword=pgettext:1c,2' , '--keyword=npgettext:1c,2,3' , '--from-code=UTF-8' , '--add-comments=Translators' , '--output=-' ] #NEWLINE# if command . wrap : #NEWLINE# #INDENT# args . append ( command . wrap ) #NEWLINE# #UNINDENT# if command . location : #NEWLINE# #INDENT# args . append ( command . location ) #NEWLINE# #UNINDENT# args . append ( work_file ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( domain == 'django' ) and ( ( file_ext == '.py' ) or ( file_ext in command . extensions ) ) ) : #NEWLINE# #INDENT# thefile = self . file #NEWLINE# orig_file = os . path . join ( self . dirpath , self . file ) #NEWLINE# is_templatized = ( file_ext in command . extensions ) #NEWLINE# if is_templatized : #NEWLINE# #INDENT# with open ( orig_file , 'rU' ) as fp : #NEWLINE# #INDENT# src_data = fp . read ( ) #NEWLINE# #UNINDENT# thefile = ( '%s.py' % self . file ) #NEWLINE# content = templatize ( src_data , orig_file [ 2 : ] ) #NEWLINE# with open ( os . path . join ( self . dirpath , thefile ) , 'w' ) as fp : #NEWLINE# #INDENT# fp . write ( is_templatized ) #NEWLINE# #UNINDENT# #UNINDENT# work_file = os . path . join ( self . dirpath , thefile ) #NEWLINE# args = [ 'xgettext' , '-d' , domain , '--language=Python' , '--keyword=gettext_noop' , '--keyword=gettext_lazy' , '--keyword=ngettext_lazy:1,2' , '--keyword=ugettext_noop' , '--keyword=ugettext_lazy' , '--keyword=ungettext_lazy:1,2' , '--keyword=pgettext:1c,2' , '--keyword=npgettext:1c,2,3' , '--keyword=pgettext_lazy:1c,2' , '--keyword=npgettext_lazy:1c,2,3' , '--from-code=UTF-8' , '--add-comments=Translators' , '--output=-' ] #NEWLINE# if command . wrap : #NEWLINE# #INDENT# args . append ( command . wrap ) #NEWLINE# #UNINDENT# if command . location : #NEWLINE# #INDENT# args . append ( command . location ) #NEWLINE# #UNINDENT# args . append ( work_file ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# #UNINDENT# ( msgs , errors , status ) = popen_wrapper ( args ) #NEWLINE# if errors : #NEWLINE# #INDENT# if ( status != STATUS_OK ) : #NEWLINE# #INDENT# if is_templatized : #NEWLINE# #INDENT# os . unlink ( work_file ) #NEWLINE# #UNINDENT# if ( ( not keep_pot ) and os . path . exists ( potfile ) ) : #NEWLINE# #INDENT# os . unlink ( potfile ) #NEWLINE# #UNINDENT# raise CommandError ( ( 'errors happened while running xgettext on %s\n%s' % ( self . file , errors ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( command . verbosity > 0 ) : #NEWLINE# #INDENT# command . stdout . write ( errors ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if msgs : #NEWLINE# #INDENT# if is_templatized : #NEWLINE# #INDENT# if ( os . name == 'nt' ) : #NEWLINE# #INDENT# old = ( '#: ' + work_file ) #NEWLINE# new = ( '#: ' + orig_file ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# old = ( '#: ' + work_file [ 2 : ] ) #NEWLINE# new = ( '#: ' + orig_file [ 2 : ] ) #NEWLINE# #UNINDENT# msgs = msgs . replace ( old , new ) #NEWLINE# #UNINDENT# write_pot_file ( potfile , msgs ) #NEWLINE# #UNINDENT# if is_templatized : #NEWLINE# #INDENT# os . unlink ( work_file )