summaryrefslogtreecommitdiffstats
path: root/web/lang
diff options
context:
space:
mode:
authorLoui Chang <louipc.ist@gmail.com>2009-01-19 16:34:11 -0500
committerLoui Chang <louipc.ist@gmail.com>2009-01-19 16:34:11 -0500
commitc602e245bb19317314793114dec49c5f4994e265 (patch)
treef44399778731f1e67e2abc4f16da8bdf1b354227 /web/lang
parent87828ae08b4e37189bd3e78a35df24975f00c633 (diff)
downloadaurweb-c602e245bb19317314793114dec49c5f4994e265.tar.xz
Add new genpopo and translation_tool that work with new system.
Signed-off-by: Loui Chang <louipc.ist@gmail.com>
Diffstat (limited to 'web/lang')
-rwxr-xr-xweb/lang/genpopo170
-rwxr-xr-xweb/lang/translation_tool217
2 files changed, 387 insertions, 0 deletions
diff --git a/web/lang/genpopo b/web/lang/genpopo
new file mode 100755
index 0000000..66bf9a1
--- /dev/null
+++ b/web/lang/genpopo
@@ -0,0 +1,170 @@
+#! /usr/bin/python -O
+# -*- coding: iso-8859-1 -*-
+
+# This script iterates through the script directories
+# looking for php scripts that contain __() functions.
+# It creates/appends to the corresponding
+# "xxx.po" file in the 'lang' subdirectory and places the
+# i18n strings into the file in the proper format.
+#
+# usage: genpopo [-v] [-f]
+# -v: verbose, print duplicate terms that could be moved to common_po
+# -f: force, overwrite existing translated files, otherwise append
+#
+
+import re
+import os
+import sys
+
+INC_HEADER = """\
+<?php
+# INSTRUCTIONS TO TRANSLATORS
+#
+# This file contains the i18n translations for a subset of the
+# Arch Linux User Community Repository (AUR). This is a PHP
+# script, and as such, you MUST pay great attention to the syntax.
+# If your text contains any double-quotes ("), you MUST escape
+# them with a backslash (\).
+#
+
+global $_t;
+"""
+
+language = 'en'
+lang = {}
+
+print_dupes = '-v' in sys.argv
+force = '-f' in sys.argv
+
+up = re.compile('_\(\s*"(([^"]|(?<=\\\\)["])+)"')
+
+scriptdirs = ['html', 'lib', 'template']
+pofile = '%s.po' % language
+
+current_dir = os.getcwd()
+
+# Iterate through various places where the php files might be.
+#
+for dir in scriptdirs:
+ dir = "../%s" % dir
+
+ if os.path.exists(dir):
+ # Find all the PHP files in the current directory.
+ #
+ files = [x for x in os.listdir(dir)
+ if (x[-4:] == '.inc' and x[-7:] != '.po')
+ or x[-6:] == '.class'
+ or x[-4:] == '.php'
+ or x[-6:] == '.phtml'
+ ]
+ os.chdir(dir)
+
+ for file in files:
+ f = open(file,'r')
+ lines = f.readlines()
+ f.close()
+
+ # Parse the file
+ print "Parsing %s..." % file
+ for line in lines:
+ match = up.search(line)
+ while match:
+ term = match.group(1).replace('\\"','"')
+ if print_dupes:
+ if term in lang.keys():
+ print 'Multiple use of "%s"' % term
+
+ lang[term] = 1
+ line = line[match.end(1):]
+ match = up.search(line)
+
+ os.chdir(current_dir)
+
+# Generate the .po file if it doesn't already exist.
+# If it does exist, only append new stuff to the end.
+# If the 'force' option is passed, just overwrite.
+
+if force:
+ # Just overwrite any existing files
+ print "Generating %s..." % pofile
+
+ f = open(pofile,'w')
+ f.write(INC_HEADER)
+
+ for term in lang.keys():
+ f.write("\n")
+ f.write('$_t["%s"]\n = "%s";\n' % (term, term))
+
+ f.write("\n");
+ f.close()
+else:
+ # Need to leave existing file intact. Only append on new terms.
+ mapre = re.compile('^\$_t\["(.*)"\].*$')
+ got_match = False
+
+ print "Updating %s..." % pofile
+
+ try:
+ f = open(pofile, 'r')
+ new_file = 0
+ except:
+ new_file = 1
+
+ if not new_file:
+ contents = f.readlines()
+ f.close()
+
+ # Strip beginning/ending empty lines
+ while contents[0] == '':
+ del contents[0]
+ while contents[-1] in ['', "\n", "?>", "?>\n", "\n?>"]:
+ del contents[-1]
+
+ f = open(pofile,'w')
+ f.write("".join(contents))
+ f.write("\n");
+ f.close()
+ else:
+ f = open(pofile,'w')
+ f.write(INC_HEADER)
+ f.write('\n')
+ f.close()
+
+ # Read file contents so we can hash what already exists
+ try:
+ f = open(pofile, 'r')
+ new_file = 0
+ except:
+ new_file = 1
+
+ existing_terms = []
+ if not new_file:
+ contents = f.readlines()
+ f.close()
+
+ # Strip beginning/ending empty lines
+ while contents[0] == '':
+ del contents[0]
+ while contents[-1] in ['', "\n", "?>", "?>\n", "\n?>"]:
+ del contents[-1]
+
+ # Collect existing terms
+ for line in contents:
+ match = mapre.search(line)
+ if match:
+ existing_terms.append(match.group(1))
+
+ # Append any new terms to EOF
+ f = open(pofile, 'w')
+ if not new_file:
+ f.write("".join(contents))
+ else:
+ f.write(INC_HEADER)
+
+ for term in lang.keys():
+ if term not in existing_terms:
+ f.write("\n");
+ f.write('$_t["%s"]\n = "%s";\n' % (term, term))
+ f.write("\n");
+ f.close()
+
diff --git a/web/lang/translation_tool b/web/lang/translation_tool
new file mode 100755
index 0000000..241f1ee
--- /dev/null
+++ b/web/lang/translation_tool
@@ -0,0 +1,217 @@
+#! /usr/bin/python -O
+# -*- coding: iso-8859-1 -*-
+
+# This script iterates through the html, lib, and template directories
+# looking for php scripts that contain __() functions.
+# It creates/appends to the corresponding 'xxx.po' file in the
+# 'lang' subdirectory and places the i18n strings into the file
+# in the proper format.
+#
+# usage: translation_tool [-v] [-f]
+# -v: Verbose, print duplicate terms that could be moved to common_po
+# -f: Force, overwrite existing translated files, otherwise append
+#
+
+import getopt
+import os
+import re
+import sys
+
+scriptdirs = ['html', 'lib', 'template']
+
+try:
+ opts, args =getopt.getopt(sys.argv[1:], 'vf')
+except getopt.GetoptError, e:
+ print 'error: %s' % str(e)
+ raise SystemExit
+
+translator_name = raw_input("What is your full name? ")
+translator_email = raw_input("What is your email address? ")
+trans_native = raw_input("What is the native name of the language? ")
+trans_eng = raw_input("What is the English name of the language? ")
+trans_abbrv = raw_input("What is the ISO 639-1 Alpha-2 abbreviation for the language? ")
+
+if len(trans_abbrv) != 2:
+ print "Must use 2 character abbreviation"
+ raise SystemExit
+
+INC_HEADER = """\
+<?php
+# INSTRUCTIONS TO TRANSLATORS
+#
+# This file contains the i18n translations for a subset of the
+# Arch Linux User Community Repository (AUR). This is a PHP
+# script, and as such, you MUST pay great attention to the syntax.
+# If your text contains any double-quotes ("), you MUST escape
+# them with a backslash (\).
+#
+# %s (%s) translation
+# Translator: %s <%s>
+
+global $_t;
+
+
+""" % (trans_eng, trans_native, translator_name, translator_email)
+
+
+print_dupes = '-v' in sys.argv
+force = '-f' in sys.argv
+
+up = re.compile('_\(\s*"(([^"]|(?<=\\\\)["])+)"')
+
+lang = {}
+
+current_dir = os.getcwd()
+
+pofile = '%s.po' % trans_abbrv
+
+# Iterate through various places where the php files might be.
+#
+for dir in scriptdirs:
+ dir = '../%s' % dir
+
+ if os.path.exists(dir):
+ # Find all the PHP files in the current directory.
+ files = [x for x in os.listdir(dir)
+ if (x[-4:] == '.inc' and x[-7:] != '.po')
+ or x[-6:] == '.class'
+ or x[-4:] == '.php'
+ or x[-6:] == '.phtml'
+ ]
+ os.chdir(dir)
+
+ for file in files:
+ f = open(file,'r')
+ lines = f.readlines()
+ f.close()
+
+ # Parse files.
+ print "Parsing %s..." % file
+ for line in lines:
+ match = up.search(line)
+ while match:
+ term = match.group(1).replace('\\"','"')
+ if print_dupes:
+ if term in lang.keys():
+ print 'Multiple use of "%s"' % term
+
+ lang[term] = 1
+ line = line[match.end(1):]
+ match = up.search(line)
+
+ os.chdir(current_dir)
+
+# Now generate the .po file if it doesn't already exist.
+# If it does exist, only append new stuff to the end.
+# If the 'force' option is passed, just overwrite.
+
+print """
+You will now be prompted for all needed translations.
+Please translate the requested lines, hitting [enter]
+goes to the next one. You may stop at any time using
+ctrl+c, and pick up where you left off by running
+translation_tool again.
+
+If there are escapes in the original English, you may
+need to include them in your translation. The
+following is a list of escapes and what they do:
+%h - HTML code inserted at run-time
+%s - Nontranslated string inserted at run-time (such as username)
+\\" - A double quote (")
+
+When you have finished your translation, make a tarball
+of the .po file and send it to aur-dev@archlinux.org
+for inclusion in the AUR.
+
+By submitting a translation, you are implying that you
+are also willing to maintain it. When there are
+new strings to be translated, you will be contacted.
+****************************************************
+"""
+
+os.chdir(current_dir)
+if force:
+ # Just overwrite any existing files.
+ # NOT RECOMMENDED! OVERWRITES ALL OTHER LANGUAGE SUPPORT
+ #
+ print "Generating %s..." % pofile
+
+ f = open(pofile,'w')
+ f.write(INC_HEADER)
+
+ for term in lang:
+ f.write("\n")
+ trans = raw_input("\n%s\n= " % term)
+ f.write('$_t["%s"] = "%s";\n' % (term, trans))
+ f.write("\n");
+ f.close()
+else:
+ # Leave existing file intact. Only append on new terms.
+ mapre = re.compile('^\$_t\["(.*)"\].*$')
+
+ got_match = False
+ print "Updating %s..." % pofile
+ try:
+ f = open(pofile, 'r')
+ new_file = 0
+ except:
+ new_file = 1
+ if not new_file:
+ contents = f.readlines()
+ f.close()
+
+ # Strip beginning/ending empty lines
+ while contents[0] == '':
+ del contents[0]
+ while contents[-1] in ['', "\n", "?>", "?>\n", "\n?>"]:
+ del contents[-1]
+
+ f = open(pofile,'w')
+ f.write("".join(contents))
+ f.write("\n");
+ f.close()
+ else:
+ f = open(pofile,'w')
+ f.write(INC_HEADER)
+ f.write('\n')
+ f.close()
+
+ # Read in file contents so we can hash what already exists
+ try:
+ f = open(pofile, 'r')
+ new_file = 0
+ except:
+ new_file = 1
+
+ existing_terms = []
+ if not new_file:
+ contents = f.readlines()
+ f.close()
+
+ # Strip beginning/ending empty lines
+ while contents[0] == '':
+ del contents[0]
+ while contents[-1] in ['', "\n", "?>", "?>\n", "\n?>"]:
+ del contents[-1]
+
+ # Collect existing terms
+ for line in contents:
+ match = mapre.search(line)
+ if match:
+ existing_terms.append(match.group(1))
+
+ # Append any new terms to EOF
+ f = open(pofile, 'w')
+ if not new_file:
+ f.write("".join(contents))
+ else:
+ f.write(INC_HEADER)
+
+ for term in lang.keys():
+ if term not in existing_terms:
+ f.write("\n");
+ trans = raw_input("\n%s\n= " % term)
+ f.write('$_t["%s"] = "%s";\n' % (term, trans))
+ f.write("\n");
+ f.close()
+