diff options
Diffstat (limited to 'web/utils/genpopo')
-rwxr-xr-x | web/utils/genpopo | 55 |
1 files changed, 46 insertions, 9 deletions
diff --git a/web/utils/genpopo b/web/utils/genpopo index 6e59b1e..652f9fc 100755 --- a/web/utils/genpopo +++ b/web/utils/genpopo @@ -128,6 +128,9 @@ for dir in ['../html', '../lib', 'html', 'lib']: # option is passed, just overwrite the entire thing. # os.chdir(lang_dir) +if not os.path.exists('en'): + os.mkdir('en') + if force: # just going to overwrite any existing files # @@ -136,13 +139,15 @@ if force: f = open(po,'w') f.write(INC_HEADER) - + f.write('\ninclude_once(\"en/%s\");\n' % po) + f.write('\n?>') + f.close() + + f = open("en/"+po,'w') + f.write(INC_HEADER) for term in lang[po].keys(): f.write("\n") f.write('$_t["en"]["%s"] = "%s";\n' % (term, term)) - f.write('# $_t["es"]["%s"] = "--> Traducción española aquí. <--";\n' % term) - f.write('# $_t["fr"]["%s"] = "--> Traduction française ici. <--";\n' % term) - f.write('# $_t["de"]["%s"] = "--> Deutsche Übersetzung hier. <--";\n' % term) f.write("\n"); f.write("?>"); @@ -150,13 +155,48 @@ if force: 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(po, 'r') + f = open('en/'+po, 'r') new_file = 0 except: new_file = 1 @@ -182,7 +222,7 @@ else: # now append any new terms to EOF # - f = open(po, 'w') + f = open('en/'+po, 'w') if not new_file: f.write("".join(contents)) else: @@ -192,9 +232,6 @@ else: if term not in existing_terms: f.write("\n"); f.write('$_t["en"]["%s"] = "%s";\n' % (term, term)) - f.write('# $_t["es"]["%s"] = "--> Traducción española aquí. <--";\n' % term) - f.write('# $_t["fr"]["%s"] = "--> Traduction française ici. <--";\n' % term) - f.write('# $_t["de"]["%s"] = "--> Deutsche Übersetzung hier. <--";\n' % term) f.write("\n?>"); f.close() |