From: <cl...@us...> - 2003-05-06 02:48:16
|
Update of /cvsroot/todo-manager/todo-manager/i18n In directory sc8-pr-cvs1:/tmp/cvs-serv6260 Added Files: updatepo.py Log Message: This new script will update translations with new strings found in the module.pot file. I put this together rather quickly without any reference material so it could potentially screw a few things up. I know that it currently preserve translations marked as fuzzy. This should be resolved in a few days. For info on how it works, run python updatepo.py --help --- NEW FILE: updatepo.py --- #!/usr/bin/env python # # updatepo.py # Update translations based on the newest POT file # # Author: Brian Bernas import os, sys #Global variables sel_module = [] sel_trans = [] help_text = """updatepo.py: Update po files with new translation strings Usage: python updatepo.py [module names] [translation names] module names:\t\tThe names of every module that translations should be \t\t\tupdated for translation names:\tNames of the translation files that should be updated ex:\t\tTo update a translation for the core: \t\t\tpython updatepo.py core LL.po -h, --help:\tDisplay this text and exit """ def update_translation(po, potdata): print "Updating translation file: %s" %po pofile = open(po, 'r') podata = pofile.read() pofile.close() text = '' # Copy the initial header i = podata.find('msgid') text = text + podata[:i] # Copy the msgid's. This is where it can get scary i = potdata.find('msgid') msgid = None while i < len(potdata): if msgid: x = podata.find(msgid) if x != -1: xi = x+len(msgid) z = podata.find('\n#:', xi) text = text + podata[xi: z] else: text = text + "msgstr \"\"\n" msgid = None else: start = potdata.find('msgid', i) if start == -1: break end = potdata.find('msgstr', start) msgid = potdata[start: end] text = text + potdata[i:end] i = potdata.find("\n#:", end) # Set the POT creation date fstr = "\"POT-Creation-Date:" start = potdata.find(fstr) if start != -1: end = potdata.find("\n\"", start) date = potdata[start:end] start = text.find(fstr) if start != -1: end = text.find("\n\"", start) olddate = text[start:end] text = text.replace(olddate, date, 1) tmpfile = open(po, 'w') tmpfile.write(text) tmpfile.close() def update_module(module): po_path = os.path.join('po', module) trans = os.listdir(po_path) pot_file = os.path.join(po_path, "%s.pot" %module) if not os.path.isfile(pot_file): print "%s.pot doesn't exist. Moving on..." %module return potfile = open(pot_file, 'r') potdata = potfile.read() potfile.close() for t in trans: if os.path.splitext(t)[1] == '.po': file = os.path.join(po_path, t) if sel_trans and (not t in sel_trans): continue update_translation(file, potdata) def parse_args(args): global sel_module global sel_trans print args for a in args: if a == '-h' or a == '--help': print help_text return 1 elif a[-3:] == '.po': sel_trans.append(a) else: sel_module.append(a) return 0 def main(): # Parse the command arguments if parse_args(sys.argv[1:]): return # Enter the main directory os.chdir(os.pardir) # All of the files and directories in the 'po' directory list = os.listdir('po') for l in list: if (os.path.isdir(os.path.join('po', '%s') %l)) and (l != "CVS"): if sel_module and (not l in sel_module): continue print "Updating translation '%s'." %l update_module(l) print # Execute the main function main() |