Difference between revisions of "Apertium-tolk"

From Apertium
Jump to navigation Jump to search
 
(39 intermediate revisions by 12 users not shown)
Line 1: Line 1:
  +
{{Github-unmigrated-tool}}
 
{{TOCD}}
 
{{TOCD}}
'''apertium-tolk'''<ref>No, this isn't a spelling mistake</ref> is a program which translates ''as you type''.
+
'''apertium-tolk'''<ref>No, this isn't a spalling mistake</ref> is a program which translates ''as you type''.
   
 
== What you need ==
 
== What you need ==
[[Image:Screenshot_apertium-tolk.png|thumb|300px|right|Macedonian to Serbo-Croatian.]]
+
[[Image:Pantallazo-apertium-tolk.png|thumb|300px|right|Version 0.2, pair: French to Spanish.]]
 
* The [[D-Bus_service_for_Apertium|Apertium D-Bus Service]]
 
* The [[D-Bus_service_for_Apertium|Apertium D-Bus Service]]
 
* A working Apertium 3.0 installation (note: this must be installed)
 
* A working Apertium 3.0 installation (note: this must be installed)
  +
* Python >= 2.4
  +
* A reasonably fast computer (a 1.2Ghz Pentium, with 256Mb RAM is fast enough if completely unloaded.)
   
  +
If installing from SVN, you also need these prerequisites:
== Getting apertium-view ==
 
  +
* gettext
  +
* intltool
  +
* libglib2.0-dev
  +
* python-gi
  +
(On Debian/Ubuntu <code>sudo apt-get install gettext intltool libglib2.0-dev python-gi</code>)
  +
  +
== Installing ==
   
 
;Debian
 
;Debian
  +
  +
If you're running Debian unstable (sid), just:
  +
  +
<pre>
  +
sudo apt-get install apertium-tolk
  +
</pre>
   
 
There are debian packages available [http://xixona.dlsi.ua.es/~fran/debian/apertium-tolk here]. Note: any language pair you want to use will need to be installed from a Debian package as well.
 
There are debian packages available [http://xixona.dlsi.ua.es/~fran/debian/apertium-tolk here]. Note: any language pair you want to use will need to be installed from a Debian package as well.
Line 15: Line 31:
 
;SVN
 
;SVN
   
  +
'''Note:''' After Apertium's migration to GitHub, this tool is '''read-only''' on the SourceForge repository and does not exist on GitHub. If you are interested in migrating this tool to GitHub, see [[Migrating tools to GitHub]].
Check out the <code>apertium-tools/simple-viewer</code> from the subversion repository.
 
   
  +
Check out the <code>apertium-tolk</code> from the subversion repository.
==Feature requests==
 
   
  +
<pre>
* Focus on text entry box, not on exit button
 
  +
svn co https://svn.code.sf.net/p/apertium/svn/trunk/apertium-tolk
* Tooltip to say "type text in this box to translate".
 
  +
./autogen.sh
** Alternatively, just put text in the box that disappears when you click.
 
  +
make
  +
./apertium-tolk
  +
# Optionally install it so you can run it from anywhere:
  +
sudo make install
  +
apertium-tolk
  +
</pre>
  +
  +
[[Image:Screenshot_apertium-tolk.png|thumb|300px|right|Version 0.1, pair: Macedonian to Serbo-Croatian.]]
   
 
==Troubleshooting==
 
==Troubleshooting==
Line 31: Line 55:
 
$ sudo /etc/init.d/dbus restart
 
$ sudo /etc/init.d/dbus restart
 
</pre>
 
</pre>
  +
  +
If that does not work, try logging out and in again.
   
 
;Method does not exist
 
;Method does not exist
Line 46: Line 72:
 
Unable to guess signature from an empty dict
 
Unable to guess signature from an empty dict
 
</pre>
 
</pre>
  +
  +
===Install dbus-x11===
  +
  +
If you get a message that <code>dbus-launch</code> is missing, like this:
  +
  +
<pre>
  +
File "/var/lib/python-support/python2.4/dbus/bus.py", line 125, in __new__
  +
bus = cls._new_for_bus(address_or_type, mainloop=mainloop)
  +
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.Spawn.ExecFailed: Failed to execute dbus-launch
  +
to autolaunch D-Bus session
  +
</pre>
  +
  +
Then in Debian/Ubuntu you need to install the <code>dbus-x11</code> package.
  +
  +
===No module named tolk===
  +
If you get a message like this:
  +
<pre>
  +
$ apertium-tolk
  +
** Message: pygobject_register_sinkfunc is deprecated (GtkWindow)
  +
** Message: pygobject_register_sinkfunc is deprecated (GtkInvisible)
  +
** Message: pygobject_register_sinkfunc is deprecated (GtkObject)
  +
Traceback (most recent call last):
  +
File "/usr/local/bin/apertium-tolk", line 19, in <module>
  +
import tolk
  +
ImportError: No module named tolk
  +
</pre>
  +
  +
you can probably fix it by setting the PYTHONPATH variable. On my system, Python by default notices modules installed into /usr, but not into /usr/local, so I had to start apertium-tolk like this:
  +
  +
PYTHONPATH=/usr/local/lib/python2.6/site-packages:${PYTHONPATH} apertium-tolk
  +
  +
For most recently version of apertium-tolk using python3:
  +
  +
PYTHONPATH=/usr/local/lib/python3/dist-packages:${PYTHONPATH} apertium-tolk
  +
  +
If you installed into some other prefix, swap <code>/usr/local</code> for your prefix.
  +
  +
You might also want to edit the "Exec" line of <code>/usr/local/share/applications/apertium-tolk.desktop</code> to say this.
   
 
===Python encodings===
 
===Python encodings===
   
If you get the following error, it means that for some reason UTF-8 is not the default encoding on your system:
+
If you get the following error, it means that there is a bug in apertium-tolk:
   
 
<pre>
 
<pre>
Line 56: Line 120:
 
</pre>
 
</pre>
   
You can fix this by making a <code>sitecustomize.py</code> file in either <code>/usr/lib/python2.4/site-packages/</code> or <code>/usr/lib/python2.4/site-packages/</code> (whichever corresponds to your version of Python) with the following contents:
+
You can hack this by making a <code>sitecustomize.py</code> file in either <code>/usr/lib/python2.5/site-packages/</code> or <code>/usr/lib/python2.4/site-packages/</code> (whichever corresponds to your version of Python) with the following contents:
   
 
<pre>
 
<pre>
Line 65: Line 129:
 
sys.setdefaultencoding('utf-8');
 
sys.setdefaultencoding('utf-8');
 
</pre>
 
</pre>
  +
  +
'''Note:''' Python 2.6 users can set sitecustomize.py locally per user under <code>~/.local/</code> ([http://docs.python.org/whatsnew/2.6.html#pep-370-per-user-site-packages-directory See details in doc.python.org]).
  +
  +
  +
(apertium-tolk should be fixed so that it decodes and encodes utf-8 correctly, see http://wiki.apertium.org/wiki/Unicode_in_Python_2.)
  +
  +
===Machine grinds to a halt===
  +
  +
This is probably because either you're running apertium-tolk on an old machine, or the machine is heavily loaded, if you look in your process list (<code>$ ps axu</code>) you will probably see many instances of Apertium running.
  +
  +
You can kill them using:
  +
  +
<pre>
  +
$ ps ax | grep apertium\/ | cut -f2 -d' ' | xargs kill
  +
</pre>
  +
  +
Unfortunately the only ways to stop this are either, decrease load on your current machine, buy a new machine or fix the code. Its a known issue, and we're working on it, but we could always do with some help :)
  +
  +
===crash on update_translation_object===
  +
Traceback (most recent call last):
  +
File "/usr/local/bin/apertium-tolk", line 159, in on_comboPair_changed
  +
self.update_translation_object(pair_name)
  +
File "/usr/local/bin/apertium-tolk", line 155, in update_translation_object
  +
self.translator = dbus.Interface(self.bus.get_object("org.apertium.mode", dbus_pair_name), "org.apertium.Mode")
  +
File "/usr/lib/python2.6/site-packages/dbus/bus.py", line 244, in get_object
  +
follow_name_owner_changes=follow_name_owner_changes)
  +
File "/usr/lib/python2.6/site-packages/dbus/proxies.py", line 241, in __init__
  +
self._named_service = conn.activate_name_owner(bus_name)
  +
File "/usr/lib/python2.6/site-packages/dbus/bus.py", line 183, in activate_name_owner
  +
self.start_service_by_name(bus_name)
  +
File "/usr/lib/python2.6/site-packages/dbus/bus.py", line 281, in start_service_by_name
  +
'su', (bus_name, flags)))
  +
File "/usr/lib/python2.6/site-packages/dbus/connection.py", line 630, in call_blocking
  +
message, timeout)
  +
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.Spawn.ChildExited: Process /usr/local/share/apertium/dbus-1/mode.py exited with status 1
  +
  +
One possible reason for this is if you are (1) running an outdated version of apertium-dbus and (2) trying to run apertium-tolk (or some other dbus-program) first as one user, then as another user. A quick fix is to do
  +
  +
sudo chmod a+w /tmp/mode.log
  +
  +
==Feature requests==
  +
  +
* Focus on text entry box, not on exit button
  +
* Tooltip to say "type text in this box to translate".
  +
** Alternatively, just put text in the box that disappears when you click.
   
 
==Related software==
 
==Related software==
   
[[Apertium-view]] is a similar, but more complicated GUI tool which shows you every stage of the Apertium pipeline.
+
* [[Apertium-view]] is a similar, but more complicated GUI tool which shows you every stage of the Apertium pipeline.
  +
* [[Apertium-viewer]] is an improved version of Apertium-view, which does not require dbus and which is written in Java
   
 
==Notes==
 
==Notes==

Latest revision as of 02:16, 9 March 2018

Note: After Apertium's migration to GitHub, this tool is read-only on the SourceForge repository and does not exist on GitHub. If you are interested in migrating this tool to GitHub, see Migrating tools to GitHub.

apertium-tolk[1] is a program which translates as you type.

What you need[edit]

Version 0.2, pair: French to Spanish.
  • The Apertium D-Bus Service
  • A working Apertium 3.0 installation (note: this must be installed)
  • Python >= 2.4
  • A reasonably fast computer (a 1.2Ghz Pentium, with 256Mb RAM is fast enough if completely unloaded.)

If installing from SVN, you also need these prerequisites:

  • gettext
  • intltool
  • libglib2.0-dev
  • python-gi

(On Debian/Ubuntu sudo apt-get install gettext intltool libglib2.0-dev python-gi)

Installing[edit]

Debian

If you're running Debian unstable (sid), just:

sudo apt-get install apertium-tolk

There are debian packages available here. Note: any language pair you want to use will need to be installed from a Debian package as well.

SVN

Note: After Apertium's migration to GitHub, this tool is read-only on the SourceForge repository and does not exist on GitHub. If you are interested in migrating this tool to GitHub, see Migrating tools to GitHub.

Check out the apertium-tolk from the subversion repository.

svn co https://svn.code.sf.net/p/apertium/svn/trunk/apertium-tolk
./autogen.sh
make
./apertium-tolk
# Optionally install it so you can run it from anywhere:
sudo make install
apertium-tolk
Version 0.1, pair: Macedonian to Serbo-Croatian.

Troubleshooting[edit]

Restart D-Bus[edit]

The solution to both of the problems below is typically to restart D-Bus. You can do this on Debian and Ubuntu by issuing the following command:

$ sudo /etc/init.d/dbus restart

If that does not work, try logging out and in again.

Method does not exist
org.freedesktop.DBus.Error.UnknownMethod: Method "translate" with signature "a{ss}s" on interface 
"org.apertium.Mode" doesn't exist
Unable to guess signature
  ERROR:dbus.connection:Unable to set arguments ({}, 'A') according to signature None: 
  exceptions.ValueError: Unable to guess signature from an empty dict
  Unable to guess signature from an empty dict

Install dbus-x11[edit]

If you get a message that dbus-launch is missing, like this:

  File "/var/lib/python-support/python2.4/dbus/bus.py", line 125, in __new__
    bus = cls._new_for_bus(address_or_type, mainloop=mainloop)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.Spawn.ExecFailed: Failed to execute dbus-launch 
to autolaunch D-Bus session

Then in Debian/Ubuntu you need to install the dbus-x11 package.

No module named tolk[edit]

If you get a message like this:

$ apertium-tolk
** Message: pygobject_register_sinkfunc is deprecated (GtkWindow)
** Message: pygobject_register_sinkfunc is deprecated (GtkInvisible)
** Message: pygobject_register_sinkfunc is deprecated (GtkObject)
Traceback (most recent call last):
  File "/usr/local/bin/apertium-tolk", line 19, in <module>
    import tolk
ImportError: No module named tolk

you can probably fix it by setting the PYTHONPATH variable. On my system, Python by default notices modules installed into /usr, but not into /usr/local, so I had to start apertium-tolk like this:

PYTHONPATH=/usr/local/lib/python2.6/site-packages:${PYTHONPATH} apertium-tolk

For most recently version of apertium-tolk using python3:

PYTHONPATH=/usr/local/lib/python3/dist-packages:${PYTHONPATH} apertium-tolk

If you installed into some other prefix, swap /usr/local for your prefix.

You might also want to edit the "Exec" line of /usr/local/share/applications/apertium-tolk.desktop to say this.

Python encodings[edit]

If you get the following error, it means that there is a bug in apertium-tolk:

UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in
position 1: ordinal not in range(128)

You can hack this by making a sitecustomize.py file in either /usr/lib/python2.5/site-packages/ or /usr/lib/python2.4/site-packages/ (whichever corresponds to your version of Python) with the following contents:

# sitecustomize.py
# this file can be anywhere in your Python path,
# but it usually goes in ${pythondir}/lib/site-packages/
import sys;
sys.setdefaultencoding('utf-8');

Note: Python 2.6 users can set sitecustomize.py locally per user under ~/.local/ (See details in doc.python.org).


(apertium-tolk should be fixed so that it decodes and encodes utf-8 correctly, see http://wiki.apertium.org/wiki/Unicode_in_Python_2.)

Machine grinds to a halt[edit]

This is probably because either you're running apertium-tolk on an old machine, or the machine is heavily loaded, if you look in your process list ($ ps axu) you will probably see many instances of Apertium running.

You can kill them using:

$ ps ax | grep apertium\/  | cut -f2 -d' ' | xargs kill

Unfortunately the only ways to stop this are either, decrease load on your current machine, buy a new machine or fix the code. Its a known issue, and we're working on it, but we could always do with some help :)

crash on update_translation_object[edit]

Traceback (most recent call last):
 File "/usr/local/bin/apertium-tolk", line 159, in on_comboPair_changed
   self.update_translation_object(pair_name)
 File "/usr/local/bin/apertium-tolk", line 155, in update_translation_object
   self.translator = dbus.Interface(self.bus.get_object("org.apertium.mode", dbus_pair_name), "org.apertium.Mode")
 File "/usr/lib/python2.6/site-packages/dbus/bus.py", line 244, in get_object
   follow_name_owner_changes=follow_name_owner_changes)
 File "/usr/lib/python2.6/site-packages/dbus/proxies.py", line 241, in __init__
   self._named_service = conn.activate_name_owner(bus_name)
 File "/usr/lib/python2.6/site-packages/dbus/bus.py", line 183, in activate_name_owner
   self.start_service_by_name(bus_name)
 File "/usr/lib/python2.6/site-packages/dbus/bus.py", line 281, in start_service_by_name
   'su', (bus_name, flags)))
 File "/usr/lib/python2.6/site-packages/dbus/connection.py", line 630, in call_blocking
   message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.Spawn.ChildExited: Process /usr/local/share/apertium/dbus-1/mode.py exited with status 1

One possible reason for this is if you are (1) running an outdated version of apertium-dbus and (2) trying to run apertium-tolk (or some other dbus-program) first as one user, then as another user. A quick fix is to do

sudo chmod a+w /tmp/mode.log

Feature requests[edit]

  • Focus on text entry box, not on exit button
  • Tooltip to say "type text in this box to translate".
    • Alternatively, just put text in the box that disappears when you click.

Related software[edit]

  • Apertium-view is a similar, but more complicated GUI tool which shows you every stage of the Apertium pipeline.
  • Apertium-viewer is an improved version of Apertium-view, which does not require dbus and which is written in Java

Notes[edit]

  1. No, this isn't a spalling mistake