#! /usr/bin/python2 -O # -*- coding: iso-8859-1 -*- # This script iterates through the script directories # looking for php scripts that contain __() functions. # It creates/appends to the corresponding # "xxx.po" file in the 'lang' subdirectory and places the # i18n strings into the file in the proper format. # # usage: genpopo [-v] [-f] # -v: verbose, print duplicate terms that could be moved to common_po # -f: force, overwrite existing translated files, otherwise append # import re import os import sys INC_HEADER = """\ ", "?>\n", "\n?>"]: del contents[-1] f = open(pofile,'w') f.write("".join(contents)) f.write("\n"); f.close() else: f = open(pofile,'w') f.write(INC_HEADER) f.write('\n') f.close() # Read file contents so we can hash what already exists try: f = open(pofile, 'r') new_file = 0 except: new_file = 1 existing_terms = [] if not new_file: contents = f.readlines() f.close() # Strip beginning/ending empty lines while contents[0] == '': del contents[0] while contents[-1] in ['', "\n", "?>", "?>\n", "\n?>"]: del contents[-1] # Collect existing terms for line in contents: match = mapre.search(line) if match: existing_terms.append(match.group(1)) # Append any new terms to EOF f = open(pofile, 'w') if not new_file: f.write("".join(contents)) else: f.write(INC_HEADER) for term in lang.keys(): if term not in existing_terms: f.write("\n"); f.write('$_t["%s"]\n = "%s";\n' % (term, term)) f.write("\n"); f.close()