diff options
-rw-r--r-- | web/html/index.php | 8 | ||||
-rw-r--r-- | web/lang/common_po.inc | 5 | ||||
-rw-r--r-- | web/lang/index_po.inc | 25 | ||||
-rwxr-xr-x | web/utils/genpopo | 72 |
4 files changed, 99 insertions, 11 deletions
diff --git a/web/html/index.php b/web/html/index.php index ec2808a..58bba8d 100644 --- a/web/html/index.php +++ b/web/html/index.php @@ -1,3 +1,9 @@ <? -print "Hello, world!<br/>\n"; +include_once("index_po.inc"); + +print _("Hello, world!")."<br/>\n"; +print _("Hello, again!")."<br/>\n"; +print _("Julie was here!")."<br/>\n"; +print _("Abernathy was here!")."<br/>\n"; + ?> diff --git a/web/lang/common_po.inc b/web/lang/common_po.inc new file mode 100644 index 0000000..c314876 --- /dev/null +++ b/web/lang/common_po.inc @@ -0,0 +1,5 @@ +<? +# INSTRUCTIONS TO TRANSLATORS: +# blah blah blah.... + +?>
\ 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 0000000..22b1456 --- /dev/null +++ b/web/lang/index_po.inc @@ -0,0 +1,25 @@ +<? +# INSTRUCTIONS TO TRANSLATORS: +# blah blah blah.... + +$_t["en"]["Julie was here!"] = "Julie was here!"; +# $_t["es"]["Julie was here!"] = "--> 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 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. # |