#!/usr/bin/env python

import sys
sys.path.append('../..')
from MoinMoin.util import pysupport

outfile = file("meta.py", "w")
outwiki = file("meta.wiki", "w")

# TODO: Save this file using utf-8 encdoing, then the language names
# could be in the language itself - Hebrew will show in Hebrew in the
# languages menu in the user preferences
outfile.write("""# -*- coding: iso-8859-1 -*-
# automatically generated, do not edit - edit *.po instead!
# lang: (longname, encoding, direction, maintainer)
languages = {
'en': ('English', 'iso-8859-1', 0, '"Juergen Hermann" <jh@web.de>',),
""")

# Create python dictionary of known languages
for lang in sys.argv[1:]:
    print "Processing %s ..." % lang
    try:
        meta = pysupport.importName(lang, "meta")
    except:
        print "Exception caught while importing %s!" % lang
        continue

    # Encode direction to binary, this will be decoded later by
    # i18n.getDirection.
    # TODO: refactor this to save the direction as simple string
    if meta['direction'] == 'ltr':
        dir = 0
    else:
        dir = 1

    # Translate file name to iso language name. iso names are xx[-xx],
    # but since each langauge is a python module, we use xx[_xx]
    lang = lang.replace('_', '-')
    
    meta.update(locals())

    # TODO maybe we should at least recode "language" ...
    outfile.write("""'%(lang)s': ('%(language)s', '%(encoding)s', %(dir)d, '%(maintainer)s',),\n""" % meta)
    outwiki.write("""|| %(lang)s || %(language)s || TODO || %(maintainer)s ||\n""" % meta)
    del meta

outfile.write("""}
# EOF
""")


