Monday, April 25, 2011

A tiny client for

I've been using translation service for several years now for Russian<->English translation, and was quite happy about it. In my opinion, it's one of the best online translation services and provides better quality translations (esp. for phrases) than e.g. Google Translate. The only thing I've been missing is an API so I, as a console geek, could have a cli tool to craft translations. Not so long they've added complete-as-you-type feature. So... firebug, 10 minutes and script is ready:

I wouldn't typically post a blog entry about 50-lines Python script, but I've figured out that it became my one of most used CLI tool (not counting basic ones, obviously, like cd or ls).

To try it just do:

# easy_install yaslov

and start using it! Like:

$ yaslov gnome.

Thanks to Yandex for a wonderful services and especially for the exposed suggestion script.

PS If you liked that, you might also want to check my similar script for urbandictionary: py-urbandict.


  1. Great tool, but not Unix friendly. Consider the following example:

    % yaslov bewilder
    bewilder - смущать, ставить в тупик, сбивать с толку, приводить в замешательство
    bewilderment - смущение, замешательство, недоумение, неясность, путаница

    If I want to pipe 1st meaning of the word (i.e. 1st line of output), than I will get the following error:

    % yaslov bewilder | head -n 1
    Traceback (most recent call last):
    File "/usr/local/bin/yaslov", line 5, in
    pkg_resources.run_script('yaslov==0.1', 'yaslov')
    File "/usr/lib/python2.6/dist-packages/", line 467, in run_script
    self.require(requires)[0].run_script(script_name, ns)
    File "/usr/lib/python2.6/dist-packages/", line 1200, in run_script
    execfile(script_filename, namespace, namespace)
    File "/usr/local/lib/python2.6/dist-packages/yaslov-0.1-py2.6.egg/EGG-INFO/scripts/yaslov", line 32, in
    print translation
    UnicodeEncodeError: 'ascii' codec can't encode characters in position 11-17: ordinal not in range(128)

    However, if I'll replace "print translation" with "print translation.encode(ENCODING)" where ENCODING should be system specific encoding ("UTF-8" in my case, got via ENCODING = locale.getpreferredencoding(do_setlocale=True)) than everything works well

  2. Kirill, thanks for the fix, I have included it and released a new version of yaslov which is available here:

  3. I wanted to implement this by myself but couldn't find API url.

    Thank you!

  4. This comment has been removed by a blog administrator.