#NEWLINE# def do_update_translations( target = ( 't' , '' ) , lang = ( 'l' , '' ) , statistics = ( 's' , False ) , i18n_dir = ( 'i' , '' ) , all = ( 'a' , False ) ) : #NEWLINE# #INDENT# '\n  Update existing translations with updated pot files.\n  ' #NEWLINE# if ( ( not target ) and ( not all ) ) : #NEWLINE# #INDENT# print_status ( 'Please specify target.' ) #NEWLINE# sys . exit ( 1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( target == 'kay' ) : #NEWLINE# #INDENT# print_status ( 'Updating core strings' ) #NEWLINE# root = path . join ( kay . KAY_DIR , 'i18n' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if all : #NEWLINE# #INDENT# targets = get_user_apps ( ) #NEWLINE# for target in targets : #NEWLINE# #INDENT# do_update_translations ( target = target , lang = lang , statistics = statistics , i18n_dir = None , all = False ) #NEWLINE# #UNINDENT# do_update_translations ( target = kay . PROJECT_DIR , lang = lang , statistics = statistics , i18n_dir = None , all = False ) #NEWLINE# sys . exit ( 0 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if i18n_dir : #NEWLINE# #INDENT# root = i18n_dir #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# root = path . join ( target , 'i18n' ) #NEWLINE# #UNINDENT# if ( not path . isdir ( root ) ) : #NEWLINE# #INDENT# print_status ( 'source folder missing' ) #NEWLINE# sys . exit ( 1 ) #NEWLINE# #UNINDENT# print_status ( ( 'Updating %s' % root ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for domain in domains : #NEWLINE# #INDENT# if lang : #NEWLINE# #INDENT# filepath = path . join ( root , lang , 'LC_MESSAGES' , ( domain + '.po' ) ) #NEWLINE# if ( not path . exists ( filepath ) ) : #NEWLINE# #INDENT# print_status ( ( '%s not found, skipped.' % filepath ) ) #NEWLINE# continue #NEWLINE# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# f = file ( path . join ( root , ( po_files + '.pot' ) ) ) #NEWLINE# #UNINDENT# except IOError : #NEWLINE# #INDENT# print_status ( ( 'Can not open file: %s, skipped.' % path . join ( root , ( domain + '.pot' ) ) ) ) #NEWLINE# continue #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# template = read_po ( f ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# f . close ( ) #NEWLINE# #UNINDENT# po_files = [ ] #NEWLINE# for lang_dir in listdir ( root ) : #NEWLINE# #INDENT# filename = path . join ( root , lang_dir , 'LC_MESSAGES' , ( domain + '.po' ) ) #NEWLINE# if ( lang and ( filename != path . join ( root , lang , 'LC_MESSAGES' , ( domain + '.po' ) ) ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if path . exists ( filename ) : #NEWLINE# #INDENT# print_status ( ( 'Updating %s' % filename ) , nl = False ) #NEWLINE# locale = Locale . parse ( lang_dir ) #NEWLINE# f = file ( filename ) #NEWLINE# try : #NEWLINE# #INDENT# catalog = read_po ( f , locale = locale , domain = domain ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# f . close ( ) #NEWLINE# #UNINDENT# catalog . update ( template ) #NEWLINE# f = file ( filename , 'w' ) #NEWLINE# try : #NEWLINE# #INDENT# write_po ( f , catalog , ignore_obsolete = True , include_previous = False , width = 79 ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# if statistics : #NEWLINE# #INDENT# translated = fuzzy = percentage = 0 #NEWLINE# for message in list ( catalog ) [ 1 : ] : #NEWLINE# #INDENT# if message . string : #NEWLINE# #INDENT# translated += 1 #NEWLINE# #UNINDENT# if ( 'fuzzy' in message . flags ) : #NEWLINE# #INDENT# fuzzy += 1 #NEWLINE# #UNINDENT# #UNINDENT# if len ( catalog ) : #NEWLINE# #INDENT# percentage = ( ( translated * 100 ) // len ( catalog ) ) #NEWLINE# print_status ( ( '-> %d of %d messages (%d%%) translated' % ( translated , len ( catalog ) , percentage ) ) , nl = False ) #NEWLINE# if fuzzy : #NEWLINE# #INDENT# if ( fuzzy == 1 ) : #NEWLINE# #INDENT# print_status ( ( '%d of which is fuzzy' % fuzzy ) , nl = False ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# print_status ( ( '%d of which are fuzzy' % fuzzy ) , nl = False ) #NEWLINE# #UNINDENT# #UNINDENT# print_status ( ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# print_status ( ) #NEWLINE# #UNINDENT# f . close ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# print_status ( 'All done.' )