mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
genpopo seems to do its job now
This commit is contained in:
parent
4628afd422
commit
79f64a0592
4 changed files with 99 additions and 11 deletions
|
@ -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";
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
5
web/lang/common_po.inc
Normal file
5
web/lang/common_po.inc
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<?
|
||||||
|
# INSTRUCTIONS TO TRANSLATORS:
|
||||||
|
# blah blah blah....
|
||||||
|
|
||||||
|
?>
|
25
web/lang/index_po.inc
Normal file
25
web/lang/index_po.inc
Normal file
|
@ -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. <--";
|
||||||
|
|
||||||
|
?>
|
|
@ -19,11 +19,11 @@ force = '-f' in sys.argv
|
||||||
import re, os
|
import re, os
|
||||||
up = re.compile('_\(\s*"(([^"]|(?<=\\\\)["])+)"')
|
up = re.compile('_\(\s*"(([^"]|(?<=\\\\)["])+)"')
|
||||||
|
|
||||||
lang = { 'common_po.po': {} }
|
lang = { 'common_po.inc': {} }
|
||||||
|
|
||||||
current_dir = os.getcwd()
|
current_dir = os.getcwd()
|
||||||
|
|
||||||
# Find the common_po.po file.
|
# Find the common_po.inc file.
|
||||||
#
|
#
|
||||||
common = {}
|
common = {}
|
||||||
for dir in ['../lang', 'lang']:
|
for dir in ['../lang', 'lang']:
|
||||||
|
@ -36,7 +36,7 @@ for dir in ['../lang', 'lang']:
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if line[0] != '#':
|
if line[0] != '#':
|
||||||
common[line[:-1]] = 0
|
common[line[:-1]] = 0
|
||||||
lang['common_po.po'][line[:-1]] = 1
|
lang['common_po.inc'][line[:-1]] = 1
|
||||||
os.chdir(current_dir)
|
os.chdir(current_dir)
|
||||||
break
|
break
|
||||||
os.chdir(current_dir)
|
os.chdir(current_dir)
|
||||||
|
@ -80,7 +80,7 @@ for dir in ['../html', '../lib', 'html', 'lib']:
|
||||||
for line in lines:
|
for line in lines:
|
||||||
match = re.search("include(_once|)\s*\(\s*[\"']([A-Za-z_]+_po.inc)[\"']\s*\);",line)
|
match = re.search("include(_once|)\s*\(\s*[\"']([A-Za-z_]+_po.inc)[\"']\s*\);",line)
|
||||||
if match and match.group(2) != "common_po.inc":
|
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):
|
if not lang.has_key(po):
|
||||||
lang[po] = {}
|
lang[po] = {}
|
||||||
parse_file = 1
|
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'
|
# if they do exist, only append new stuff to the end. If the 'force'
|
||||||
# option is passed, just overwrite the entire thing.
|
# option is passed, just overwrite the entire thing.
|
||||||
#
|
#
|
||||||
mapre = re.compile('^\$_t\["en\]["(.*)"].*$')
|
|
||||||
os.chdir(lang_dir)
|
os.chdir(lang_dir)
|
||||||
|
|
||||||
if force:
|
if force:
|
||||||
# just going to overwrite any existing files
|
# just going to overwrite any existing files
|
||||||
#
|
#
|
||||||
|
@ -123,7 +121,7 @@ if force:
|
||||||
f = open(po,'w')
|
f = open(po,'w')
|
||||||
f.write("<?\n")
|
f.write("<?\n")
|
||||||
f.write("""# INSTRUCTIONS TO TRANSLATORS:
|
f.write("""# INSTRUCTIONS TO TRANSLATORS:
|
||||||
# blah blah blah....
|
# blah blah blah....
|
||||||
""")
|
""")
|
||||||
|
|
||||||
for term in lang[po].keys():
|
for term in lang[po].keys():
|
||||||
|
@ -137,10 +135,64 @@ if force:
|
||||||
f.write("?>");
|
f.write("?>");
|
||||||
f.close()
|
f.close()
|
||||||
else:
|
else:
|
||||||
# TODO left off here... need to leave existing file intact, and only
|
# need to leave existing file intact, and only append on terms that are new
|
||||||
# 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.
|
# Print out warnings for unused and little-used common entries.
|
||||||
#
|
#
|
||||||
|
|
Loading…
Add table
Reference in a new issue