psistorm

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

67 posts in this topic

If you go to http://leo.dict.org and click a language, there is an URL like http://dict.leo.org/itde/index_de.html for Italian-German or http://dict.leo.org/ptde/index_de.html for Portuguese-German. The important part is between dict.leo.org and index_xx.html.

 

You would have to add a new scriptfilter with a keyword for that language. Then paste the code like

 

require('leo.php');

$in = "{query}";
$leo = new Leo("{LANGUAGECODE}");
echo $leo->getTranslations($in);

 

{LANGUAGECODE} is the part you'll have to fill in, for italien this would be itde for portuguese it would be ptde

I think you can guess the further scheme for other languages like Russian or Polish. Just have a look at the URL and take that languagecode out of it. Then link the new scriptfilter with the two RunScript Boxes assigning Shift-Modifierkey to the upper box like I did. That's all.

 

If you tell me which language you're interested in, I can add it for all others and upload it on github again. I just picked out the ones I thought were most common. 

 

But: This only works for Leo, if you want any other site, there would be the need to rewrite the site parsing. I'll think I'll start probably with dict.cc next week or on the weekend.

Edited by psistorm

Share this post


Link to post

I was about to write a workflow just for that, but found out this one already exists.

 

However, I get the following error in Konsole.App:

 

 

03.04.13 09:44:56,406 Alfred 2[98678]: [ERROR] Script XML Parse Error occured Error Domain=NSXMLParserErrorDomain Code=4 "The operation couldn’t be completed. (NSXMLParserErrorDomain error 4.)"
 
And no result appears.
 
Any ideas?

Share this post


Link to post

Right, sorry for being too brief:

 

I set the workflow to be triggered by cmd+alt+ctrl+D.

 

I trigger the shortcut and enter

  de test

 

The information that the workflow is retrieving data from the server is displayed and a few seconds of network traffic is observable. The status doesn't change and no network traffic happens. The previously posted error is displayed in the Konsole log for Alfred 2.

 

I added a little debug to the scripts, the URL requested is:

http://dict.leo.org/ende/?lang=en&searchLoc=0&search=de+test

 

The behaviour is the same, even when I ommit the leading "de". The retrieved HTML then does contain translations, but nothing gets displayed. The constructed XML looks like this: 

  http://pastebin.com/3hd0VBvK

Share this post


Link to post

Ok, first, you're not supposed to still enter the keyword like 'de' when you assigned a shortcut. Just use the word you're searching for. As you told, this does not solve the problem. Thus, the constructed XML looks just like it should. Does this problem happen every time? Even when using no shortcut just the keyword 'de'?

Sometimes there seems to be some sort of hickup in Alfred. Could you try to remove the last character of your input, wait for one second and type it again like "test" -> "tes" -> wait -> "test". Does the result show something?

 

The shown error in the console.app suggests the workflow returned an empty XML (http://stackoverflow.com/questions/7304850/parser-error-error-domain-nsxmlparsererrordomain-code-4-the-operation-couldnt), but you showed it isn't empty...

Edited by psistorm

Share this post


Link to post

FYI: As Dict.cc often has much better results than LEO, I would greatly appreciate a dict.cc workflow :-)

Share this post


Link to post

Ok, first, you're not supposed to still enter the keyword like 'de' when you assigned a shortcut. Just use the word you're searching for. As you told, this does not solve the problem. Thus, the constructed XML looks just like it should. Does this problem happen every time? Even when using no shortcut just the keyword 'de'?

Sometimes there seems to be some sort of hickup in Alfred. Could you try to remove the last character of your input, wait for one second and type it again like "test" -> "tes" -> wait -> "test". Does the result show something?

 

The shown error in the console.app suggests the workflow returned an empty XML (http://stackoverflow.com/questions/7304850/parser-error-error-domain-nsxmlparsererrordomain-code-4-the-operation-couldnt), but you showed it isn't empty...

 

I tried the delay and revert approach you described, but that didn't help. I have no idea, why the apparent correct XML appears to not make it back to Alfred. And why does it work for everybody else?

Share this post


Link to post

Thanks a million, had used a simple dict.cc custom web search, but this is way better! I guess the speed is the main thing that's annoying, but there's only so much you can do ;-)

Share this post


Link to post

 tried the delay and revert approach you described, but that didn't help. I have no idea, why the apparent correct XML appears to not make it back to Alfred. And why does it work for everybody else?

 

Yes that's a pretty good question :) Perhaps you can open a ticket in the alfred bugs section with the same detailed description you provided for me. I guess Andrew is potentially better able to see if the error is within the workflow output or somewhere else.

 

 

 

Thanks a million, had used a simple dict.cc custom web search, but this is way better! I guess the speed is the main thing that's annoying, but there's only so much you can do ;-)

 

Well the speed depends on different factors from your internet connection speed to the workflow algorithm itself. How "fast" or "slow" is the workflow responding? Of course it will never be that fast like Alfreds program search. But I'll have a look if I can do optimisations if it's really so slow. It doesn't feel that slow here at my computer ;)

Share this post


Link to post

Mhm, I had used the workflow while my connection was kinda busy, now I tried it again with everything else shut off, and it's about 2 seconds, give or take some.

I guess it just feels a bit weird because the feedback sometimes kicks in right when I'm done typing, but for the first half of the word. ‘de window’ as input for example has about a second of ‘Watt’ in the feedback before the real translation comes in.

 

Again, great work, I'm not complaining, rather analyzing :)

Share this post


Link to post

I tried the delay and revert approach you described, but that didn't help. I have no idea, why the apparent correct XML appears to not make it back to Alfred. And why does it work for everybody else?

 

You are not alone, I have exactly the same problem.

Same error message in Konsole.app, nothing gets displayed  :(

 

I am new to Alfred and workflows so I don't know what to do to give more informations.

 

Mario

Share this post


Link to post

Thank you so much for this workflow, it really speeds up the process of looking up a word!

 

I have just one question: I've added Chinese support according to your tutorial a few posts earlier and I'd like to add an icon in the same style as those for English, French, and so on... Could tell me, where you got those?

 

Thank you so much!

Yannick

Share this post


Link to post

Hi, after the last Alfred Update and/or Mac OSX 10.8.4 Update the Leo workflow show no results anymore.

Share this post


Link to post

Hey, the same for me. Since the last Alfred update the workflow won't show any results.

Share this post


Link to post

With the new Alfred Update to 2.0.5 11th Jun 2013, now the great Translation with Leo Dictionary works again.  ;)

Share this post


Link to post

I really like your workflow (especially because it's the only "German <> English - dictionary" workflow I know of). Personally, I prefer dict.cc to look up words. I'm not an expert at all, but I was just wondering if it's difficult to create a workflow that works in the same manner as yours - but instead of using LEO, using dict.cc?

 

Thanks!

Edited by brutze

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