view jabberbot/ @ 3183:952f8f1268c5

- Remove dummy formatter which did a lot of stuff to output text, instead simply serialize dom to text when endDocument is called. - Output valid doctype - Temporarily disable Include macro support which required the dummy formatter. - Update copyright
author Mikko Virkkil? <>
date Tue, 04 Mar 2008 23:12:23 +0100
parents af857f8c2e44
children 6f06c7d051a4
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
    MoinMoin - jabber bot i18n routines

    @copyright: 2007 by Karol Nowak <>
    @license: GNU GPL, see COPYING for details.
import logging, xmlrpclib
from jabberbot.config import BotConfig


def get_text(original, lang="en"):
    """ Return a translation of text in the user's language.

        @type original: unicode
    if original == u"":
        return u""

    if not TRANSLATIONS:

        return TRANSLATIONS[lang][original]
    except KeyError:
        return original

def init_i18n(config):
    """Prepare i18n

    @type config: jabberbot.config.BotConfig

    TRANSLATIONS = request_translations(config) or {'en': {}}

def request_translations(config):
    """Download translations from wiki using xml rpc

    @type config: jabberbot.config.BotConfig


    wiki = xmlrpclib.Server(config.wiki_url + "?action=xmlrpc2")
    log = logging.getLogger("log")
    log.debug("Initialising i18n...")

        translations =  wiki.getBotTranslations()
        return translations
    except xmlrpclib.Fault, fault:
        log.error("XML RPC fault occured while getting translations: %s" % (str(fault), ))
    except xmlrpclib.Error, error:
        log.error("XML RPC error occured while getting translations: %s" % (str(error), ))
    except Exception, exc:
        log.error("Unexpected exception occured while getting translations: %s" % (str(exc), ))

    log.error("Translations could not be downloaded, is wiki is accesible?")
    return None