From 79f64a059254bbbae93cf7c2f9dfa512aa5f9f7e Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 18 Jun 2004 00:25:15 +0000 Subject: genpopo seems to do its job now --- web/utils/genpopo | 72 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 62 insertions(+), 10 deletions(-) (limited to 'web/utils') diff --git a/web/utils/genpopo b/web/utils/genpopo index 72ec8e5..ea6569a 100755 --- a/web/utils/genpopo +++ b/web/utils/genpopo @@ -19,11 +19,11 @@ force = '-f' in sys.argv import re, os up = re.compile('_\(\s*"(([^"]|(?<=\\\\)["])+)"') -lang = { 'common_po.po': {} } +lang = { 'common_po.inc': {} } current_dir = os.getcwd() -# Find the common_po.po file. +# Find the common_po.inc file. # common = {} for dir in ['../lang', 'lang']: @@ -36,7 +36,7 @@ for dir in ['../lang', 'lang']: for line in lines: if line[0] != '#': common[line[:-1]] = 0 - lang['common_po.po'][line[:-1]] = 1 + lang['common_po.inc'][line[:-1]] = 1 os.chdir(current_dir) break os.chdir(current_dir) @@ -80,7 +80,7 @@ for dir in ['../html', '../lib', 'html', 'lib']: for line in lines: match = re.search("include(_once|)\s*\(\s*[\"']([A-Za-z_]+_po.inc)[\"']\s*\);",line) if match and match.group(2) != "common_po.inc": - po = match.group(2).replace(".inc",".po") + po = match.group(2) if not lang.has_key(po): lang[po] = {} parse_file = 1 @@ -111,9 +111,7 @@ for dir in ['../html', '../lib', 'html', 'lib']: # if they do exist, only append new stuff to the end. If the 'force' # option is passed, just overwrite the entire thing. # -mapre = re.compile('^\$_t\["en\]["(.*)"].*$') os.chdir(lang_dir) - if force: # just going to overwrite any existing files # @@ -123,7 +121,7 @@ if force: f = open(po,'w') f.write(""); f.close() else: - # TODO left off here... need to leave existing file intact, and only - # append on terms that are new + # need to leave existing file intact, and only append on terms that are new # - pass + mapre = re.compile('^\$_t\["en"\]\["(.*)"\].*$') + for po in lang.keys(): + print "Updating %s..." % po + # first read in file contents so we can hash what already exists + # + try: + f = open(po, 'r') + new_file = 0 + except: + new_file = 1 + + existing_terms = [] + if not new_file: + contents = f.readlines() + f.close() + + # remove PHP tags + # + stripped_contents = [] + for line in contents: + if line.strip() not in [""]: + stripped_contents.append(line) + contents = stripped_contents + + # strip off beginning/ending empty lines + # + while contents[0] == '': + del contents[0] + while contents[-1] == '': + del contents[-1] + if contents[-1] == "\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(po, 'w') + f.write(" Spanish translation here. <--";\n' % term) + f.write('# $_t["fr"]["%s"] = "--> French translation here. <--";\n' % term) + f.write('# $_t["de"]["%s"] = "--> German translation here. <--";\n' % term) + f.write("\n?>"); + f.close() # Print out warnings for unused and little-used common entries. # -- cgit v1.2.3-70-g09d2