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/html/index.php | 8 +++++- web/lang/common_po.inc | 5 ++++ web/lang/index_po.inc | 25 ++++++++++++++++++ web/utils/genpopo | 72 +++++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 99 insertions(+), 11 deletions(-) create mode 100644 web/lang/common_po.inc create mode 100644 web/lang/index_po.inc (limited to 'web') diff --git a/web/html/index.php b/web/html/index.php index ec2808a2..58bba8db 100644 --- a/web/html/index.php +++ b/web/html/index.php @@ -1,3 +1,9 @@ \n"; +include_once("index_po.inc"); + +print _("Hello, world!")."
\n"; +print _("Hello, again!")."
\n"; +print _("Julie was here!")."
\n"; +print _("Abernathy was here!")."
\n"; + ?> diff --git a/web/lang/common_po.inc b/web/lang/common_po.inc new file mode 100644 index 00000000..c3148760 --- /dev/null +++ b/web/lang/common_po.inc @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/web/lang/index_po.inc b/web/lang/index_po.inc new file mode 100644 index 00000000..22b14566 --- /dev/null +++ b/web/lang/index_po.inc @@ -0,0 +1,25 @@ + Spanish translation here. <--"; +# $_t["fr"]["Julie was here!"] = "--> French translation here. <--"; +# $_t["de"]["Julie was here!"] = "--> German translation here. <--"; + +$_t["en"]["Hello, again!"] = "Hello, again!"; +# $_t["es"]["Hello, again!"] = "--> Spanish translation here. <--"; +# $_t["fr"]["Hello, again!"] = "--> French translation here. <--"; +# $_t["de"]["Hello, again!"] = "--> German translation here. <--"; + +$_t["en"]["Hello, world!"] = "Hello, world!"; +# $_t["es"]["Hello, world!"] = "--> Spanish translation here. <--"; +# $_t["fr"]["Hello, world!"] = "--> French translation here. <--"; +# $_t["de"]["Hello, world!"] = "--> German translation here. <--"; + +$_t["en"]["Abernathy was here!"] = "Abernathy was here!"; +# $_t["es"]["Abernathy was here!"] = "--> Spanish translation here. <--"; +# $_t["fr"]["Abernathy was here!"] = "--> French translation here. <--"; +# $_t["de"]["Abernathy was here!"] = "--> German translation here. <--"; + +?> \ No newline at end of file diff --git a/web/utils/genpopo b/web/utils/genpopo index 72ec8e56..ea6569a2 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-24-g4f1b