rice.shawn Posted June 24, 2014 Share Posted June 24, 2014 (edited) Note: the original version of this workflow utilized an unofficial API that Google Translate exposed. Unfortunately, the Google has shut down the API. There is an alternative workflow that uses the official (paid) Google Translate API that you can find here: http://www.packal.org/workflow/translate-api. It's actually pretty cheap. Here's a little ditty that interfaces with Google Translate. The upside of this one is that it gives you access to all of Google Translate's languages (or at least about 80 of them). You can enable/disable languages from inside the workflow. Find it on Packal. Demo: Current Languages: Afrikaans Albanian Arabic Armenian Azerbaljani Basque Belarusian Bengali Bosnian Brazilian Portuguese Bulgarian Catalan Cebuano Chinese Croatian Czech Danish Dutch English Esperanto Estonian Filipino Finnish French Galician Georgian German Greek Gujarati Hatian Creole Hausa Hebrew Hindi Hmong Hungarian Icelandic Igbo Indonesian Irish Italian Japanese Javanese Kannada Khmer Korean Lao Latin Latvian Lithuanian Macedonian Malay Maltese Maori Marathi Mongolian Nepali Norwegian Persian Polish Portuguese Punjabi Romanian Russian Serbian Slovak Slovenian Somali Spanish Swahili Swedish Tamil Telugu Thai Turkish Ukranian Urdu Vietnamese Welsh Yiddish Yoruba Zulu Edited November 8, 2015 by Shawn Rice cands, rigrassm, morocons and 5 others 8 Link to comment
DrLulz Posted June 25, 2014 Share Posted June 25, 2014 This is so great! My wife is Brazilian, and when her family comes around this will come in handy. I know quite a bit of Portuguese, but this will make it easier to learn. Thanks a bunch. Link to comment
DrLulz Posted June 25, 2014 Share Posted June 25, 2014 (edited) How can I add an option for Brazilian Portuguese? There are slight differences. The Google code for Brazil is pt-BR, whereas for Portugal it is pt-PT. do I just add another line in languageCodes.php? 'pt-BR' => 'Portuguese-BR', EDIT: That did it, now I just need a slick icon with the Brazilian flag. EDIT2: pt-BR.png Edited June 26, 2014 by DrLulz Link to comment
rice.shawn Posted June 26, 2014 Author Share Posted June 26, 2014 How can I add an option for Brazilian Portuguese? There are slight differences. The Google code for Brazil is pt-BR, whereas for Portugal it is pt-PT. do I just add another line in languageCodes.php? 'pt-BR' => 'Portuguese-BR', EDIT: That did it, now I just need a slick icon with the Brazilian flag. EDIT2: pt-BR.png Yep. That's exactly how you would do it. I made the same changes (mostly) and uploaded a new version onto Packal. Where did you find that language code? It wasn't in the list that I found, which makes me think that there may be more out there that I can add in. Link to comment
DrLulz Posted June 27, 2014 Share Posted June 27, 2014 (edited) Where did you find that language code? Google Web Interface and Search Language Codes there's one for Klingon "xx-klingon" thanks again for the workflow Edited June 27, 2014 by DrLulz Link to comment
deanishe Posted June 27, 2014 Share Posted June 27, 2014 It doesn't do Klingon??? Jeez, Shawn. Sort it out! Also, I demand Elmer Fudd support. Link to comment
rice.shawn Posted June 27, 2014 Author Share Posted June 27, 2014 I'll give you them all. Even "Bork." Now I just have to figure out how the hell I'm going to do icons for all these things. Dean, pretty soon you'll have an easy way to translate everything you write into hacker. Link to comment
deanishe Posted June 27, 2014 Share Posted June 27, 2014 This is so great! My wife is Brazilian, and when her family comes around this will come in handy. I know quite a bit of Portuguese, but this will make it easier to learn. Thanks a bunch. It's worth bearing in mind that Google Translate often produces what can be best described as complete bollocks. It's no substitute for a proper dictionary. You might put a bird feeder in your garden to encourage visits from the great tits currently nesting in the area. Google Translate will, like as not, produce some sentence about large breasts… Link to comment
rice.shawn Posted June 27, 2014 Author Share Posted June 27, 2014 Of course. But it has its place. How else am I going to fake Klingon without it? Honestly, though, I'm surprised they don't have Elvish. Link to comment
deanishe Posted June 27, 2014 Share Posted June 27, 2014 I'll give you them all. Even "Bork." Now I just have to figure out how the hell I'm going to do icons for all these things. Dean, pretty soon you'll have an easy way to translate everything you write into hacker. I don't trust Google Translate in the slightest. Translating is my day job, and I have developed a very healthy, professional distrust of Google Translate. In some situations, it does an exceptionally good job, but in others it's so wide of the mark, it's ridiculous. This particular bug has now been fixed, but it used to translate Wien (Vienna) with Dublin… Link to comment
deanishe Posted June 27, 2014 Share Posted June 27, 2014 Of course. But it has its place. How else am I going to fake Klingon without it? Honestly, though, I'm surprised they don't have Elvish. Actually, that is rather surprising. Link to comment
rice.shawn Posted June 27, 2014 Author Share Posted June 27, 2014 Sadly, it looks like those are the web interface codes and not the translation codes. Klingon, Hacker, Elmer Fudd, and a bunch of other ones there aren't actually supported via Google Translate. I'll pare down the list to what is available. Link to comment
rice.shawn Posted June 27, 2014 Author Share Posted June 27, 2014 It looks like I could do it (Klingon at least) if I supported the bing translation API, but that seems like a hassle, and it needs an API key, and it limits you to 2 million characters a month for the free tier, so I'm not into that possibility of using my API key as a universal and for the script to, possibly, stop working, and I'm not into requiring others to get an API key, all for Klingon (and maybe a few others). Oh well. Link to comment
deanishe Posted June 27, 2014 Share Posted June 27, 2014 (edited) Here's a list of the language codes supported by Google's translate API from https://www.googleapis.com/language/translate/v2/languages (I have an API key): af ar az be bg bn bs ca ceb cs cy da de el en eo es et eu fa fi fr ga gl gu ha hi hmn hr ht hu hy id ig is it iw ja jw ka km kn ko la lo lt lv mi mk mn mr ms mt ne nl no pa pl pt ro ru sk sl so sq sr sv sw ta te th tl tr uk ur vi yi yo zh zh-TW zu Edited June 27, 2014 by deanishe Link to comment
rice.shawn Posted June 27, 2014 Author Share Posted June 27, 2014 That was my original list, the one from the API docs. Brazilian Portuguese wasn't on there, but it works, so I think the API supports a few more than that. Link to comment
rice.shawn Posted June 28, 2014 Author Share Posted June 28, 2014 It looks like I was just missing: Norwegian (Nynorsk) Moldavian Montenegrin Serbo-Croatian Latin American Spanish Chinese (Traditional). I'll do an update soon and push it. Might as well have them all, right? Link to comment
exalyon Posted August 15, 2014 Share Posted August 15, 2014 Thank you for the workflow. I have some questions: 1) I would like to use the union jack instead of the usa flag for the english language. How can I do it without creating troubles? 2) Russian results are in cyrillic, is there a way to show them in our alphabet? 3) Welsh language uses union jack, I think it should use the welsh one. Link to comment
deanishe Posted August 15, 2014 Share Posted August 15, 2014 Thank you for the workflow. I have some questions: 1) I would like to use the union jack instead of the usa flag for the english language. How can I do it without creating troubles? 2) Russian results are in cyrillic, is there a way to show them in our alphabet? 3) Welsh language uses union jack, I think it should use the welsh one. A splendid idea. Open up the workflow, go into the "icons" directory and overwrite the "en.png" icon with a copy of the "cy.png" one. Dunno. Now that's just wrong . Unfortunately, there isn't a Welsh flag included in the workflow. Shawn will have to have a look in the icon set he used to see if there is one. Link to comment
rice.shawn Posted August 15, 2014 Author Share Posted August 15, 2014 1. I allow for my American biases. Dean's method works. 2. There is always a way, but there isn't one in the workflow, and I'm not going to code support for it. The workflow simply queries Google translate and grabs the results. GT returns Russian results in the appropriate charset (as it does for Arabic, Gujarati, Greek, etc...). If you want to extend the functionality, then you'll need to intercept the results before they are displayed and transliterate them. There are a lot of libraries that exist that can do this sort of thing for you, so your best bet would be to implement one of those. 3. I don't think that there was a Welsh flag in the set. This is what I used: http://www.nordicfactory.com/creative/illustrations/download-free-flag-set-in-png/comment-page-1/. While the icons are pretty (hence my desire to use them), I had to spend hours mapping the results to the icons because I needed to look up most of them. If you find one in the set, then let me know. Link to comment
deanishe Posted August 15, 2014 Share Posted August 15, 2014 There's no Welsh flag. This one is not massively different. Link to comment
exalyon Posted August 15, 2014 Share Posted August 15, 2014 I did it, thank you! I also changed the icon for latin (reminds me of denmark) with vh.png (vatican). As for russian, I read what I should do twice and disabled it. Is it possible (in a human way) to show "loading", "..." or just show the flags until results are ready? right now it seems to show the first letter if the query is short and cut in half the phrase if it is long. One more thing: any chance to have a workflow like this one but for currency conversion? I tried many (one is yours deanishe!) but I would like to type "convert 50" and see enabled currencies instead of "convert x eur to usd" and the like. Link to comment
deanishe Posted August 15, 2014 Share Posted August 15, 2014 (edited) I did it, thank you! I also changed the icon for latin (reminds me of denmark) with vh.png (vatican). As for russian, I read what I should do twice and disabled it. Is it possible (in a human way) to show "loading", "..." or just show the flags until results are ready? right now it seems to show the first letter if the query is short and cut in half the phrase if it is long. Not really, no. You could make it so the workflow doesn't try to translate unless the query is at least, say, 3 characters, but it's the nature of a workflow that gets its results directly from a webservice that there will be a noticeable delay between your entering the query and the corresponding results being shown. One more thing: any chance to have a workflow like this one but for currency conversion? I tried many (one is yours deanishe!) but I would like to type "convert 50" and see enabled currencies instead of "convert x eur to usd" and the like. There's this one. Otherwise, it wouldn't be too hard to make one. If you fancied giving it a try, you could start with my workflow and pull out the irrelevant bits. Edited August 15, 2014 by deanishe Link to comment
rice.shawn Posted August 15, 2014 Author Share Posted August 15, 2014 Not really, no. You could make it so the workflow doesn't try to translate unless the query is at least, say, 3 characters, but it's the nature of a workflow that gets its results directly from a webservice that there will be a noticeable delay between your entering the query and the corresponding results being shown. I had that minimum in there, but, apparently, I took that out for some reason. It was a good reason at the time. As Dean said, there is no way to do this (because of how Alfred executes workflows). If you do want to get just want you want, then just copy the word(s) that you want to translate and paste them as the argument. Link to comment
deanishe Posted August 15, 2014 Share Posted August 15, 2014 Because lots of languages have words with only one or two letters? Link to comment
rice.shawn Posted August 15, 2014 Author Share Posted August 15, 2014 Because lots of languages have words with only one or two letters? ... That was it. I need coffee. 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