From c602e245bb19317314793114dec49c5f4994e265 Mon Sep 17 00:00:00 2001 From: Loui Chang Date: Mon, 19 Jan 2009 16:34:11 -0500 Subject: Add new genpopo and translation_tool that work with new system. Signed-off-by: Loui Chang --- web/utils/genpopo | 296 ++++++++++++++++++++---------------------------------- 1 file changed, 110 insertions(+), 186 deletions(-) (limited to 'web/utils/genpopo') diff --git a/web/utils/genpopo b/web/utils/genpopo index a2a3ac4..66bf9a1 100755 --- a/web/utils/genpopo +++ b/web/utils/genpopo @@ -1,10 +1,10 @@ #! /usr/bin/python -O # -*- coding: iso-8859-1 -*- -# this script iterates through the 'html' and 'lib' directories -# looking for php scripts that contain a include_once("xxx_po.inc") -# line and __() functions. It creates/appends to the corresponding -# "xxx_po.inc" file in the 'lang' subdirectory and places the +# 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] @@ -12,77 +12,51 @@ # -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: - # need to leave existing file intact, and only append on terms that are new - # - incre = re.compile('^include_once\("en\/(.*)"\);') - mapre = re.compile('^\$_t\["en"\]\["(.*)"\].*$') - for po in lang.keys(): - got_match = False - print "Updating %s..." % po - try: - f = open(po, 'r') - new_file = 0 - except: - new_file = 1 - - if not new_file: - contents = f.readlines() - f.close() - # strip off beginning/ending empty lines - # - while contents[0] == '': - del contents[0] - while contents[-1] in ['', "\n", "?>", "?>\n", "\n?>"]: - del contents[-1] - - for line in contents: - match = incre.search(line) - if match: - got_match = True - if not got_match: - f = open(po,'w') - f.write("".join(contents)) - f.write('\ninclude_once(\"en/%s\");\n' % po) - f.write("\n"); - f.close() - else: - f = open(po,'w') - f.write(INC_HEADER) - f.write('\ninclude_once(\"en/%s\");\n' % po) - f.write('\n') - f.close() - - # first read in file contents so we can hash what already exists - # - try: - f = open('en/'+po, 'r') - new_file = 0 - except: - new_file = 1 - - existing_terms = [] - if not new_file: - contents = f.readlines() - f.close() + else: + f = open(pofile,'w') + f.write(INC_HEADER) + f.write('\n') + f.close() - # strip off beginning/ending empty lines - # - while contents[0] == '': - del contents[0] - while contents[-1] in ['', "\n", "?>", "?>\n", "\n?>"]: - del contents[-1] - - # next, collect existing terms - # - for line in contents: - match = mapre.search(line) - if match: - existing_terms.append(match.group(1)) - - # now append any new terms to EOF - # - f = open('en/'+po, 'w') - if not new_file: - f.write("".join(contents)) - else: - f.write(INC_HEADER) - - for term in lang[po].keys(): - if term not in existing_terms: - f.write("\n"); - f.write('$_t["en"]["%s"] = "%s";\n' % (term, term)) - f.write("\n"); + # 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() -# Print out warnings for unused and little-used common entries. -# -for key in common.keys(): - if common[key] == 1: - print "Warning: common entry '%s' is only used once." % key -for key in common.keys(): - if common[key] == 0: - print "Warning: unused common entry '%s'." % key - -# vim: ts=2 sw=2 noet ft=python + # 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() + -- cgit v1.2.3-70-g09d2