Difference between revisions of "X-Chat plugin"

From Apertium
Jump to navigation Jump to search
m (Reverted edits by 78.166.102.152 (Talk) to last revision by Francis Tyers)
Line 70: Line 70:


[[Category:Tools]]
[[Category:Tools]]
[http://www.istanbulescortbayanlar.com escort bayan]
[http://www.escortbayanlarresimli.com escort bayan]
[http://www.nabervideo.com porno izle]

Revision as of 20:07, 22 November 2010

Save this to a Python file and load it with XChat.

Pre-requisites

SVN version

This module is being further developed in our SVN repository. It can be found under apertium-tools/xchat-modules.

Script

__module_name__ = "translate"
__module_version__ = "0.1"
__module_description__ = "Uses Apertium to translate users' text"
__module_author__ = "Wynand Winterbach <wynand.winterbach@gmail.com"

import xchat
import dbus

active_pairs = set()

translator = dbus.Interface(dbus.SessionBus().get_object("org.apertium.mode", "/"), "org.apertium.Translate")
info  = dbus.Interface(dbus.SessionBus().get_object("org.apertium.info", "/"), "org.apertium.Info")
modes = info.modes()

def translate(word, word_eol, userdata):
    for pair in active_pairs:
        print "[%s]: %s" %(pair, translator.translate(pair, {}, word[1]))

    return xchat.EAT_NONE

def add_pair(word, word_eol, userdata):
    if len(word) != 2:
        print "usage: /add_pair <language_pair"
        return xchat.EAT_NONE

    _, pair = word

    if pair not in modes:
        print "invalid language pair"
        return xchat.EAT_NONE

    print "Adding %s" % pair
    active_pairs.add(pair)
    return xchat.EAT_NONE

def remove_pair(word, word_eol, userdata):
    print "Removing %s" % word[1]
    active_pairs.remove(word[1])


xchat.hook_print("Channel Message", translate) 
xchat.hook_command("add_pair", add_pair, help="/add_pair <pair> will start using the language pair to translate IRC text")
xchat.hook_command("remove_pair", remove_pair, help="/remove_pair <pair> will stop using the language pair to translate IRC text")

print "Plugin translate loaded!"

If you want Apertium to start translating a language pair (let's say fr-es), then type

/add_pair fr-es

You can stop translation of this pair by typing

/remove_pair fr-es