ErfahrungenCOM Posted May 9, 2014 Share Posted May 9, 2014 Thanks Florian for the Workflow. Thank you kopischke for the bug fixes. You guys are awesome! Link to comment
maxbmx Posted June 26, 2014 Share Posted June 26, 2014 This is what I was looking for. I can stop disturb David Ferguson to make such one. Maciej, Did you resolve problem with polish chars (exemple: Łąka) Link to comment
mcskrzypczak Posted July 11, 2014 Share Posted July 11, 2014 Maciej, Did you resolve problem with polish chars (exemple: Łąka) Well, it just works for me. Link to comment
bonka Posted March 17, 2015 Share Posted March 17, 2015 (edited) Although i this workflow, I wonder if it is possible to translate bigger chunks of text? It seems like the first period sign "." terminates the translation. I do a lot of research in academic papers for my master thesis, and use Alfred to do a quick translation of chunks of text (typically a paragraph or three) that I use as citations in my paper. I have successfully made it work by removing the punctuation manually before pasting it into this wf, but that removes the beauty of it. Suggestions? Edit: I fidgeted around with periods a little. Not only are periods escaping the query, but the result from a "I say hello." returns (the translated equivalent of) "I say hello ." - mind the gap between hello and the period. Would love it if someone smarter than me would have a look at this! Edited March 17, 2015 by bonka Link to comment
deanishe Posted March 17, 2015 Share Posted March 17, 2015 What actually happens is that Google returns each sentence as a separate result, but the workflow throws away all but the first. To get multi-sentence results, open the workflow in Finder and edit the translate script in it to read as follows. This will show all the sentences in a translation. Because Alfred can't show much text in its results, I've added copy text and large type. Hit CMD+C on a result to copy the translation to the clipboard and CMD+L to show the full translation in Alfred's large type window. # Set locale and normalize unicode composition for international support. export LC_CTYPE="UTF-8" query="$(echo "${@:3}" | iconv -s -f UTF-8-Mac -t UTF-8)" # Retrieve and parse Google Translate answer. response="$(curl -G --data-urlencode "text=$query" --data 'client=p' --data 'sl=auto' --data "tl=$1" --silent --user-agent 'Mozilla/5.0' 'http://translate.google.com/translate_a/t' | python -c 'import sys, json; print("".join([d.get("trans", "<UNTRANSLATED>") for d in json.loads(sys.stdin.read())["sentences"]]).encode("utf-8"))')" [[ -z "$response" ]] && translation="No translation found" || translation="$response" # Write feedback. echo '<?xml version="1.0" encoding="UTF-8"?><items> <item uid="translation"> <title><![CDATA['"$translation"']]></title> <arg><![CDATA['"$translation"']]></arg> <text type="copy"><![CDATA['"$translation"']]></text> <text type="largetype"><![CDATA['"$translation"']]></text> <icon>icon.png</icon> <subtitle>”'"$query"'” in '$2'.</subtitle> </item> </items>' bonka 1 Link to comment
rice.shawn Posted March 17, 2015 Share Posted March 17, 2015 What actually happens is that Google returns each sentence as a separate result, but the workflow throws away all but the first. You know, I noticed this when I was writing my version of this workflow, but I lost track / got distracted and forgot to continue looking into it. I should go fix mine. Link to comment
deanishe Posted March 17, 2015 Share Posted March 17, 2015 The important bit is setting the client URL parameter to something other than t. That way you get valid, comprehensible JSON instead of some weird crap. Link to comment
rice.shawn Posted March 17, 2015 Share Posted March 17, 2015 The important bit is setting the client URL parameter to something other than t. That way you get valid, comprehensible JSON instead of some weird crap. I was just working on this, and, well, I took the other route to make the json valid. Basically, it seems that for a null value, Google just sends back nothing, so I added a while loop to look for two commas in a row and replace them with `,null,`. But your solution seems much, much better. Link to comment
deanishe Posted March 17, 2015 Share Posted March 17, 2015 (edited) Yeah, I spent some time staring at the weird output and wasn't going to bother trying to figure it out. Thankfully, a Stack Overflow thread turned up the above nugget. Edited March 17, 2015 by deanishe Link to comment
rice.shawn Posted March 17, 2015 Share Posted March 17, 2015 Well, I just fixed mine. Thanks for the leads. Link to comment
bonka Posted March 26, 2015 Share Posted March 26, 2015 Multiple sentences - check. Correct period behaviour - check. Thanks a lot, deanishe! Link to comment
bonka Posted April 8, 2015 Share Posted April 8, 2015 Did the workflow just break? Response from any request is: "No translation found" Link to comment
Teodin Posted April 8, 2015 Share Posted April 8, 2015 The creator of another translate workflow just added this to his readme: It seems like Google closed the open API endpoints for it's translation services. Therefore this Workflow does not work anymore. It's sad, but there not much I can do.https://github.com/thomashempel/AlfredGoogleTranslateWorkflow If this is true, it would be very, very sad… this is one of my most used workflows. Link to comment
malinich Posted April 8, 2015 Share Posted April 8, 2015 I found the same "No translation found" this morning, Too bad. It was a useful workflow Link to comment
bonka Posted April 8, 2015 Share Posted April 8, 2015 (edited) Oh my god. That is so lame. Lets start a Facebook page. Edit: Is this API pricing page on Google Cloud Services new? Edited April 8, 2015 by bonka Link to comment
rice.shawn Posted April 8, 2015 Share Posted April 8, 2015 Oh my god. That is so lame. Lets start a Facebook page. Edit: Is this API pricing page on Google Cloud Services new? I don't think it is new. The endpoint that this (and my) workflow used was unofficial, and the paid translation API has been around for quite a while. So, these just used a sort of backdoor that Google had left open. Now, the URL leads to a redirect captcha challenge that redirects nowhere. It's a pity that they closed the endpoint, but we can't be too mad because it was never official to begin with. bonka 1 Link to comment
bonka Posted April 8, 2015 Share Posted April 8, 2015 I see :/ Nevertheless, I reserve the right to be mad because it was such a great service. (╯°□°)╯︵ ┻━┻ Link to comment
Florian Posted April 9, 2015 Author Share Posted April 9, 2015 For single word translation, wordreference was always better anyway: http://www.wordreference.com/docs/api.aspx Anyone feels like making a workflow for it? For sentences and all, it'd be really cool to find an alternative too, this was way useful! Any ideas guys? Link to comment
vanderholm Posted April 9, 2015 Share Posted April 9, 2015 catastrophic! I was relying very much on these workflows. What to do? Link to comment
rice.shawn Posted April 9, 2015 Share Posted April 9, 2015 It looks like Translate Shell (which used the same path) found a new way to use it. It should easily be adaptable. So this means that they didn't close it; they just changed it.... bonka 1 Link to comment
rice.shawn Posted April 9, 2015 Share Posted April 9, 2015 (edited) Okay. It can work. I just updated mine. The endpoint has changed slightly, so the URL needs to be corrected. Also, the trick to get good JSON that Dean pointed out a few posts back no longer works, so you have to scrub the data. Next, the keys seem to have changed in that they're all just numeric arrays. Here's what I did (it is truly an inelegant hack, but I just wanted to get it working again), so you can crib from it to get this one working again. foreach ( $languages as $code => $name ) : $query = "http://translate.google.com/translate_a/single?client=json&ie=UTF-8&oe=UTF-8"; $query .= "&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at"; $query .= "&q=" . urlencode( $text ); $query .= "&hl=en&sl=auto&"; $query .= "tl=" . $code; $trans = file_get_contents( $query ); while ( false !== strpos( $trans, '[,' ) ) : $trans = str_replace( '[,', '[null,', $trans ); endwhile; while ( false !== strpos( $trans, ',,' ) ) : $trans = str_replace( ',,', ',null,', $trans ); endwhile; $trans = json_decode( $trans, true ); $string = ''; foreach ( $trans[0] as $t ) : $string .= trim( $t[0] ) . ' '; endforeach; $w->result( '', $string, $string, "$name: $text", "icons/$code.png", 'yes', '' ); endforeach; (Note: mine lets you use multiple languages at once, so that's why there is the big foreach loop. I haven't updated this to use Alphred yet, so it still uses David's Workflows library) The while loops scrub the response into something that json_decode can read. Edited April 9, 2015 by Shawn Rice vanderholm 1 Link to comment
vanderholm Posted April 10, 2015 Share Posted April 10, 2015 wonderful! can anyone update the workflow (well out of my range as a 'programmer') or give a hint as to where to change the existing one (in the translate file or in the script filter)? NB: thomashempel also got his working again: https://github.com/thomashempel/AlfredGoogleTranslateWorkflow/blob/master/README.md Link to comment
ErfahrungenCOM Posted April 10, 2015 Share Posted April 10, 2015 I would also be interested in an updated workflow. Thanks guys! Link to comment
vanderholm Posted April 10, 2015 Share Posted April 10, 2015 from what I gather the state of this workflow is this workflow, not counting the most recent fix: https://github.com/kopischke/alfred-workflows/raw/master/Google%20Translate.alfredworkflow with this substitution in the 'translate' file: http://www.alfredforum.com/topic/120-google-translate-workflow/?p=35081 what's next? (I use a modified version of the workflow for single language translations (da>en) with a hotkey and instant paste, perhaps I should just hack mr. Rice' in the same way workflow and let this one deprecate) Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now