diff options
Diffstat (limited to 'web/utils/genpopo')
-rwxr-xr-x | web/utils/genpopo | 72 |
1 files changed, 62 insertions, 10 deletions
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("<?\n") f.write("""# INSTRUCTIONS TO TRANSLATORS: - # blah blah blah.... +# blah blah blah.... """) for term in lang[po].keys(): @@ -137,10 +135,64 @@ if force: 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("<?\n") + if not new_file: + f.write("".join(contents)) + + 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('# $_t["es"]["%s"] = "--> 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. # |