view MoinMoin/i18n/build_meta_py @ 0:77665d8e2254

tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0 (automatically generated log message) imported from: moin--main--1.5--base-0
author Thomas Waldmann <tw-public@gmx.de>
date Thu, 22 Sep 2005 15:09:50 +0000
parents
children 77499985c79f
line wrap: on
line source
#!/usr/bin/env python

import sys
sys.path.insert(0, '../..')
from MoinMoin.util import pysupport

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

outfile.write('''# -*- coding: utf-8 -*-
""" This file contains meta information about available languages, so MoinMoin
    does not need to load all language files to collect those informations.
    
    *** Automatically generated, do not edit - edit *.po instead! ***
"""
# lang: (longname, longname-in-english, encoding, direction, maintainer)
languages = {
''')

# 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('_', '-')

    # decode the language (as it is in file encoding still)
    language = meta['language'].decode(meta['encoding'])
    elanguage = meta['elanguage'].decode(meta['encoding'])
    
    meta.update(locals())

    outf = u"""'%(lang)s': (u'%(language)s', u'%(elanguage)s', '%(encoding)s', %(dir)d, '%(maintainer)s',),\n""" % meta
    outw = u"""|| %(lang)s || %(language)s || TODO || %(maintainer)s ||\n""" % meta
    
    outfile.write(outf.encode('utf-8'))
    outwiki.write(outw.encode('utf-8'))
    del meta

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