psistorm

Translation with Leo Dictionary (German <> English/French/Spanish)

67 posts in this topic

Hey!
 
I've created this first workflow to try out the new possibilities of Alfreds workflow. It provides two different search methods:

  • de - Translating a german word to english and vice versa.
  • df - Translating a german word to french and vice versa.
  • ds - Translating a german word to spanish and vice versa.

When hitting 'Enter' the translated word is copied to the clipboard. When hitting 'Shift + Enter' the selected word translation is opened with Leo. With Version 1.2 newly introduced a somewhat "automatic" detection of the language of the entered word.
 
Thanks, at this point, to David Ferguson, whose workflow.php I used to pass the results to Alfred.
 
Here is the workflow:
https://github.com/psistorm/alfredapp
 
screenshot_de.png
 
V1.1:
- Added hotkeys transferring selected text (please choose your own hotkey)
V 1.2:
- Only one keyword per language needed now. The language of the entered word is automatically detected.
- Opening Leo with the selected word when hitting 'Shift + Enter'.
- Fixed problem with german umlauts.
V 1.2.1:
- Fixed problem with opening the URL in some cases.
- Fixed problem with some words.

V 1.3:

- Added support for translation of german to polish and vice versa (Sebastian Kusnier)

V 1.3.1:

- Quick fix for changes in Leo site to make the workflow work again (Oderwat)

V 1.4:

- Added timeout for php request to avoid high process load when loosing internet connection.

- Open Leo with the originally entered word when hitting 'Ctrl+Enter'.

 

Added workflow to Packal.

 

 

Best regards,
 
psistorm

Edited by psistorm
nikipore, Teodin, blkrk4000 and 8 others like this

Share this post


Link to post

Perfect, thanks. I was glad that LEO restructured their site so I was now able to use a simple "custom search". But this workflow is way better. Thanks for creating it.

Share this post


Link to post

sweet. dankeschön!  ;)

but any idea if it is possible just to type a word and it recognize automatically german or english like the leo site does? without de or en?

Edited by DJay

Share this post


Link to post

sweet. dankeschön!  ;)

but any idea if it is possible just to type a word and it recognize automatically german or english like the leo site does? without de or en?

I thin this would interfere with Alfred's regular search.

Share this post


Link to post

Hey there,

 

I'm happy you like it. I had a look at how Leo "recognizes" what language it is. Apparently, I think, it doesn't recognize this. Try out "Parameter". Leo marks the german and the english words bold as well. But normally you know which language the word is ;)

Unfortunately Alfred workflows do not support some sort of modifier key, otherwise I could have used Enter for copying the first language and Shift+Enter for copying the second language, or something like this.

Or why would you like to have just one word? I thought two keywords are good to be able to copy the translated word, depending on the language. But I'll try to think about other solutions.

 

I could do a dict.cc Plugin but they don't show all results on the same page, so this makes it harder. And if there should be all results shown also slower, or the search would only show the results of the first page.

 

Is there a general interest in other languages?

Share this post


Link to post

Actually Alfred v2 now does support modifier keys: just drag in two result actions and by clicking on the connecting line you can choose a modifier key that will toggle that specific path. 

 

So you could do:

          (enter)

Leo ------------- EN search

       |   (option)

        ------------ DE search

Share this post


Link to post

Hi Adrianthomas,

 

That's nice. But I think what doesn't work is to have the keyword "leo" and get a result feedback from their page depending on the key. This is what should work without pressing enter, displaying the suggestions.

Edited by psistorm

Share this post


Link to post

Yes I noticed that too, but I'm not sure why. I've tried all possible encodings and the one I'm using should definitely works. I'll do some debugging on the weekend. For now I haven't got any time at the moment.

 

As a workaround you could use the ae, oe, ue writing. That works.

Share this post


Link to post

The encoding is UTF-8 in a funny variant which Mac OS X uses and which encodes, e.g., ü as ¨ + u. I solved this problem by first decoding to UTF-8, followed by a unicode normalizing operation (NFC, cf. http://unicode.org/reports/tr15/), which in Python reads:
 

def decode(s):
    return unicodedata.normalize('NFC', s.decode('utf-8'))

You'll have to dig out for yourself how this works in PHP. Never looked into this language because it hurts my eye with its perlish appearance, but this might be a place to begin searching ... http://php.net/manual/de/class.normalizer.php

Share this post


Link to post

Thank you for this hint. For anyone having the same issues with PHP in the future, use:

$string = iconv('UTF-8-Mac', 'UTF-8', $string);

 

As there seems to be a Mac-"Special" UTF-8 version (NFD) and iconv helps to convert this into "real" UTF-8 (NFC).

 

I've uploaded a new version of the workflow to github. And also reworked the workflow to the suggestions of DJay. There is now only one keyword per language. "de" for german-english, "df" for german-french and "ds" for german-spanish". The workflow "automatically" detects the language the keyword aims to be translated to by choosing the bold highlighted keywords of Leo as the native language of the input keyword.

 

There could be some overlap, but I think this will work in the most cases.

DJay likes this

Share this post


Link to post

wow.. this is great psistorm. 

translation/auto detect works like charm. 

the only thing I noticed is that  shift+enter not show the right thing on the leo page. but thats no problem for now.

thanks for your work and sharing. 

Share this post


Link to post

Yes I recognized it right after committing the changes...It worked before fixing the Umlaut problem. Probably something broke then...I'll have a look at this but probably rather tomorrow. 

Share this post


Link to post

I uploaded a fix for opening the leo page with the selected keyword, for each particular language. Locally everything works now, hopefully for you too :)

 

Now and then Alfred does not show any results. I found out this is due to the fact, that Leo blocks an IP for a small amount of time if there are too many requests but this should be not exceeding 10 to 30 seconds. So you'll have to wait if you fire too many requests within a short time. I'm not really happy about this but as it happens rarely and I can not change anything about this, we'll have to live with it.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now