D-Bus examples

From Apertium
Revision as of 17:56, 18 December 2007 by Francis Tyers (talk | contribs) (New page: ==Python== <pre> #!/usr/bin/python # coding=utf-8 # -*- encoding: utf-8 -*- import dbus; sys.stdin = codecs.getwriter('utf-8')(sys.stdin); sys.stdout = codecs.getwriter('utf-8')(sys.std...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Python

#!/usr/bin/python
# coding=utf-8
# -*- encoding: utf-8 -*-

import dbus;

sys.stdin = codecs.getwriter('utf-8')(sys.stdin);
sys.stdout = codecs.getwriter('utf-8')(sys.stdout);

pair_name = 'en-af';
dbus_pair_name = "/" + "_".join(pair_name.split("-"));

bus = dbus.SessionBus();

translator = dbus.Interface(bus.get_object("org.apertium.mode", dbus_pair_name), "org.apertium.Mode")

input = sys.stdin.read();

print translator.translate({"mark_unknown": "true"}, input)