Jump to content

Google Translate (Languages Configurable)


Recommended Posts

 

Could you add zh-TW into this workflow?

zh-CN and zh-TW are two different versions of Chinese.

zh-CN is used in China mainland while zh-TW is the official language of Taiwan, HongKong and Macau.

According to Google's documents, they should be called  'Chinese (Simplified) ' and 'Chinese (Traditional)' respectively .

 

'zh-CN' => 'Chinese (Simplified)',

'zh-TW' => 'Chinese (Traditional)',
 
The icon of zh-TW 'tw.png' is also included in the icon pack you using.
 
Thank you.

 

 

Added it in and tested it out. It's available in v1.22 on Packal now.

Link to comment
  • 1 month later...

The image you posted was the "Please Wait" subtext, which means the script was running but hadn't output anything yet. The API is a bit slow, and if your internet connection is a bit slow, and if you turned on a lot of languages, then it will take a while longer to process everything. So, you probably just need to wait a bit longer.

Link to comment
  • 1 month later...

Thank you very much for this! I love that I'm able to look up translations and see multiple languages in-line.

 

I've ben looking through the workflow's folder, trying to find a way to easily edit the order in which the languages are listed, but I haven't been successful so far (primarily due to my lack of knowledge on the subject).

Is there a file where I can edit this, and am I just looking in the wrong place? I know I could go and enable and disable the languages, until I get the order I want, but that seems tedious.

 

qBqyvqN.png

Edited by jackalriot
Link to comment

The file is at "~/Library/Application Support/Alfred 2/Workflow Data/com.spr.translate/config.json"

 

Make sure that you don't open it with TextEditor, and, if you do, then make sure that you turn it onto plain text mode.

 

The JSON will be broken by Smart Quotes, etc.

Link to comment
  • 4 weeks later...

If you just reinstalled Yosemite, then it might be an error with PHP itself. In the most recent Yosemite build, Apple broke PHP (seriously Apple?).

 

So, first thing to try: open a terminal and type `php -v`. If it gives you an error saying that some 'dylib' cannot be found, then it's the PHP problem. I can't remember the name of the one off the top of my head, but it wanted a copy of it with a number, but symlinking the version without the number to the one that PHP wants fixes it.

 

Past that, I need a bit more info. Can you open the Alfred debugger and run the workflow and let me know if it throws any errors there?

Link to comment

I wish I could help, but maybe I will complicate it even more.

It is not working for me either, but no sign of a php error:

 

{~/} what now... php -v
PHP 5.5.20 (cli) (built: Feb 25 2015 23:30:53)
Copyright © 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright © 1998-2014 Zend Technologies
Link to comment

It still is working for me, which means the API endpoint is still functioning.

 

Can you open the Alfred Debugger, run the workflow, and let me know what it says?

 

(Open Alfred Preferences, click Workflows, Select the Translate workflow, click the little bug icon in the upper-right hand corner, then run the workflow).

Link to comment

It still is working for me, which means the API endpoint is still functioning.

 

Can you open the Alfred Debugger, run the workflow, and let me know what it says?

 

(Open Alfred Preferences, click Workflows, Select the Translate workflow, click the little bug icon in the upper-right hand corner, then run the workflow).

 

Sure:

Starting debug for 'Translate'

[ERROR: alfred.workflow.input.scriptfilter] XML Parse Error 'The operation couldn’t be completed. (NSXMLParserErrorDomain error 4.)'. Row 1, Col 1: 'Document is empty' in XML:
Warning: file_get_contents(http://translate.google.com/translate_a/single?client=json&ie=UTF-8&oe=UTF-8&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&q=hello+there&hl=en&sl=auto&tl=no): failed to open stream: HTTP request failed! HTTP/1.0 503 Service Unavailable
 in /Users/racoonlab/GoogleDrive/__MyDocs__/__mac-settings__/Alfredapp/Alfred.alfredpreferences/workflows/user.workflow.1DB299CA-6A28-4E73-B861-F7119BF3EB7B/filter.php on line 58

Warning: Invalid argument supplied for foreach() in /Users/racoonlab/GoogleDrive/__MyDocs__/__mac-settings__/Alfredapp/Alfred.alfredpreferences/workflows/user.workflow.1DB299CA-6A28-4E73-B861-F7119BF3EB7B/filter.php on line 67

Warning: file_get_contents(http://translate.google.com/translate_a/single?client=json&ie=UTF-8&oe=UTF-8&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&q=hello+there&hl=en&sl=auto&tl=it): failed to open stream: HTTP request failed! HTTP/1.0 503 Service Unavailable
 in /Users/racoonlab/GoogleDrive/__MyDocs__/__mac-settings__/Alfredapp/Alfred.alfredpreferences/workflows/user.workflow.1DB299CA-6A28-4E73-B861-F7119BF3EB7B/filter.php on line 58

Warning: Invalid argument supplied for foreach() in /Users/racoonlab/GoogleDrive/__MyDocs__/__mac-settings__/Alfredapp/Alfred.alfredpreferences/workflows/user.workflow.1DB299CA-6A28-4E73-B861-F7119BF3EB7B/filter.php on line 67

Warning: file_get_contents(http://translate.google.com/translate_a/single?client=json&ie=UTF-8&oe=UTF-8&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&q=hello+there&hl=en&sl=auto&tl=en): failed to open stream: HTTP request failed! HTTP/1.0 503 Service Unavailable
 in /Users/racoonlab/GoogleDrive/__MyDocs__/__mac-settings__/Alfredapp/Alfred.alfredpreferences/workflows/user.workflow.1DB299CA-6A28-4E73-B861-F7119BF3EB7B/filter.php on line 58

Warning: Invalid argument supplied for foreach() in /Users/racoonlab/GoogleDrive/__MyDocs__/__mac-settings__/Alfredapp/Alfred.alfredpreferences/workflows/user.workflow.1DB299CA-6A28-4E73-B861-F7119BF3EB7B/filter.php on line 67
<?xml version="1.0"?>
<items><item arg="" valid="yes"><arg></arg><title></title><subtitle>Norwegian: hello there</subtitle><icon>icons/no.png</icon></item><item arg="" valid="yes"><arg></arg><title></title><subtitle>Italian: hello there</subtitle><icon>icons/it.png</icon></item><item arg="" valid="yes"><arg></arg><title></title><subtitle>English: hello there</subtitle><icon>icons/en.png</icon></item></items> 

If it helps...

http://stackoverflow.com/questions/7304850/parser-error-error-domain-nsxmlparsererrordomain-code-4-the-operation-couldn-t

Link to comment

That output helps a bit. Google is sending you a 503 HTTP status error (service unavailable). But, it kind of is still available. So, the first URL that it queries doesn't work, for instance, if you use `curl` directly from the command line. It also doesn't work if you just paste it into address bar in Chrome.

 

Here's something else to try. Open a terminal and copy/paste the following line:

php -r 'print_r(file_get_contents("http://translate.google.com/translate_a/single?client=json&ie=UTF-8&oe=UTF-8&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&q=hello+there&hl=en&sl=auto&tl=no"));'

It should say something like:

[[["hei der","hello there",,,0]],,"en",,,[["hello there",1,[["hei der",1000,true,false],["hello there",0,true,false],["hei på",0,true,false],["hei på deg",0,true,false],["hei",0,true,false]],[[0,11]],"hello there",0,2]],0.036865726,,[["en"],,[0.036865726]],,,,,,[["Hello there!","there","hello"]]]

Let me know if it says something else.

Link to comment

It still is working for me, which means the API endpoint is still functioning.

 

Can you open the Alfred Debugger, run the workflow, and let me know what it says?

 

(Open Alfred Preferences, click Workflows, Select the Translate workflow, click the little bug icon in the upper-right hand corner, then run the workflow).

it it helps, thes is my debug output:

http://pastebin.com/QdEzMMF5

 

That output helps a bit. Google is sending you a 503 HTTP status error (service unavailable). But, it kind of is still available. So, the first URL that it queries doesn't work, for instance, if you use `curl` directly from the command line. It also doesn't work if you just paste it into address bar in Chrome.

 

Here's something else to try. Open a terminal and copy/paste the following line:

php -r 'print_r(file_get_contents("http://translate.google.com/translate_a/single?client=json&ie=UTF-8&oe=UTF-8&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&q=hello+there&hl=en&sl=auto&tl=no"));'
It should say something like:

[[["hei der","hello there",,,0]],,"en",,,[["hello there",1,[["hei der",1000,true,false],["hello there",0,true,false],["hei på",0,true,false],["hei på deg",0,true,false],["hei",0,true,false]],[[0,11]],"hello there",0,2]],0.036865726,,[["en"],,[0.036865726]],,,,,,[["Hello there!","there","hello"]]]
Let me know if it says something else.

 

 

 

What I get:

Warning: file_get_contents(http://translate.google.com/translate_a/single?client=json&ie=UTF-8&oe=UTF-8&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&q=hello+there&hl=en&sl=auto&tl=no): failed to open stream: HTTP request failed! HTTP/1.0 503 Service Unavailable
 in Command line code on line 1
Edited by mrgreen
Link to comment

Can you also try to do the test that I mentioned in my last post and let me know if that works?

 

 

it it helps, thes is my debug output:
http://pastebin.com/QdEzMMF5

 
 
Warning: file_get_contents(http://translate.google.com/translate_a/single?client=json&ie=UTF-8&oe=UTF-8&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&q=hello+there&hl=en&sl=auto&tl=no): failed to open stream: HTTP request failed! HTTP/1.0 503 Service Unavailable
 in Command line code on line 1

Link to comment

Okay, that is strange. There's something weird going on somewhere between Google and PHP.

 

Let's see if Ruby throws the same error. Can you try this one-liner in the terminal?

ruby -r open-uri -e 'puts open("http://translate.google.com/translate_a/single?client=json&ie=UTF-8&oe=UTF-8&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&q=hello+there&hl=en&sl=auto&tl=no") { |io| io.read }'
Link to comment

Here both:

{~/} what now... php -r 'print_r(file_get_contents("http://translate.google.com/translate_a/single?client=json&ie=UTF-8&oe=UTF-8&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&q=hello+there&hl=en&sl=auto&tl=no"));'

Warning: file_get_contents(http://translate.google.com/translate_a/single?client=json&ie=UTF-8&oe=UTF-8&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&q=hello+there&hl=en&sl=auto&tl=no): failed to open stream: HTTP request failed! HTTP/1.0 503 Service Unavailable
 in Command line code on line 1


{~/} what now... ruby -r open-uri -e 'puts open("http://translate.google.com/translate_a/single?client=json&ie=UTF-8&oe=UTF-8&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&q=hello+there&hl=en&sl=auto&tl=no") { |io| io.read }'
[[["hei der","hello there",,,0]],,"en",,,[["hello there",1,[["hei der",1000,true,false],["hello there",0,true,false],["hei på",0,true,false],["hei på deg",0,true,false],["hei",0,true,false]],[[0,11]],"hello there",0,2]],0.036865726,,[["en"],,[0.036865726]],,,,,,[["Hello there!","there","hello"]]]
{~/} what now...
Link to comment

Okay... so, the problem is that Google is rejecting however PHP 5.5.20 constructs the request and sends a 503 status error. I think it's working for me because I'm using 5.5.24 (this is at least a difference). Let me write up another script in a minute to test another approach to constructing the request with PHP to see if that will work with PHP 5.5.20.

Link to comment

Actually, let's see if the Alphred get methods work better (they seem to be fine on my computer). So, help me out with a simple test.

 

Download Alphred (https://github.com/shawnrice/alphred/raw/master/build/Alphred.phar) and place it in the workflow directory. (Easiest way to find that it so ctrl+click the workflow in Alfred preferences and select "Reveal in Finder").

 

Then, open `filter.php`, and add in these two lines near the top:

require_once( 'Alphred.phar' );
$a = new Alphred;

Then replace the line:

$trans = file_get_contents( $query );

with

$trans = $a->get( $query, 86400, true );

Then try the workflow again to see if that works.

Link to comment

 

Okay, that is strange. There's something weird going on somewhere between Google and PHP.

 

Let's see if Ruby throws the same error. Can you try this one-liner in the terminal?

ruby -r open-uri -e 'puts open("http://translate.google.com/translate_a/single?client=json&ie=UTF-8&oe=UTF-8&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&q=hello+there&hl=en&sl=auto&tl=no") { |io| io.read }'

here is my output:

http://pastebin.com/WDJeqhhW

 

 

 

Actually, let's see if the Alphred get methods work better (they seem to be fine on my computer). So, help me out with a simple test.

 

Download Alphred (https://github.com/shawnrice/alphred/raw/master/build/Alphred.phar) and place it in the workflow directory. (Easiest way to find that it so ctrl+click the workflow in Alfred preferences and select "Reveal in Finder").

 

Then, open `filter.php`, and add in these two lines near the top:

require_once( 'Alphred.phar' );
$a = new Alphred;

Then replace the line:

$trans = file_get_contents( $query );

with

$trans = $a->get( $query, 86400, true );

Then try the workflow again to see if that works.

 

Does not work, here is debug:

http://pastebin.com/AkAekamR

Link to comment

Does not work, here is debug:

http://pastebin.com/AkAekamR

 

Dammit. So I have to conclude that the bug exists in the way that Google is denying the request object as built by PHP 5.2.20, for reasons that are far beyond me. I'll go ahead and note that the workflow relies on an unofficial API, so there is really no documentation on it whatsoever, and it's basically a backdoor for the service. It would make much more sense to me if the API endpoint threw the same error consistently rather than just the 503 when requested by PHP 5.2.20.

 

So, two options currently exist to fix it (because the code is, technically fine).

 

1. Upgrade OS X. I'm currently on 10.10.5, which packages PHP 5.2.24. But, as I brought up earlier, Apple borked the PHP build.*

2. Wait for me to rewrite this thing in Ruby, which will probably take a bit because my plate is a bit full currently.

 

So weird. Sorry there isn't better news.

 

 

 

* The way to fix it is to run the following command from the terminal:

sudo ln -s /usr/lib/libnetsnmp.30.dylib /usr/lib/libnetsnmp.25.dylib

There might be unforeseen problems with this solution, but I haven't run into any of them yet.

Link to comment

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
×
×
  • Create New...