#!/usr/bin/python """ Reads a language file from stdin, and formats the entries as an array of java strings to stdout. Allows inclusion of a language file's content from java. input: 1 {one} 3 {multi "line"} output: , "one" , "" , "multi\n\"line\"" """ #import sys import re from os import path import mebuild import glob reBackref = re.compile('%(\d\d?)') def split(bigstr): lines = [] oldid = -1 for match in re.finditer(r"(?:^|\n)(\d\d?)\W+\{([^}]*)\}", bigstr): id = int(match.group(1)) txt = match.group(2).replace('\n', r'\n').replace('"', r'\"') assert oldid < id for i in range(oldid+1, id): print 'missing key ', i lines.append('') oldid = id lines.append(reBackref.sub(lambda m: lines[int(m.group(1))], txt) ) return lines def fileStrings(lang): fi = open("lang/"+lang) bigstr = fi.read() fi.close() return split(bigstr) enStrings = fileStrings('en') table=[] tmpl = """ class L { final static String[] s = { %(strings)s }; } """ for lang in glob.glob('lang/??'): lang = lang.rpartition('/')[2] print lang try: strings = fileStrings(lang) strings += enStrings[len(strings)+1:] code = ',\n'.join(['"%s"'%x for x in strings]) mebuild.writeFile(path.join('javalang', lang), tmpl%dict(strings=code)) table.append((lang, strings[0], strings[1], strings[2])) except IOError: pass print '%s, %s, %s, %s'%(strings[0], strings[1], strings[2], strings[3]) table.sort() fscreen = open('table-screen.html', 'w') fhandheld = open('table-handheld.html', 'w') fauthors = open('table-authors.html', 'w') for line in table: lang = line[0] name = 'menstral-' + lang fscreen.write(""" %(lang)s %(langen)s jar jad """ % dict(name = name, lang = line[2], langen = line[3])) fhandheld.write("
  • %(lang)s - %(langen)s
  • \n" % dict(name = name, lang = line[2], langen = line[3])) fauthors.write("%(lang)s%(iso)s%(author)s\n" % dict(iso=line[0], author= line[1], lang=line[2])) fscreen.close() fhandheld.close() fauthors.close()