Jump to content

Google Translate (Languages Configurable)


Recommended Posts

I can't understand what's going on. I used this workflow some time ago with the paid API and decided to stop until the multiple langue support was released. Now the workflow no longer works. :(

 

Try adding a new API key to the Google project and then plugging that one in.

Link to comment

Try adding a new API key to the Google project and then plugging that one in.

 

 

Still not working.

 

By the way, why the first result has no flag or language? Look:

xPzgQ3m.png

P.S.: Notice, as I already pointed out in this thread, that the code for Brazilian Portuguese is wrong (pt-BZ instead pt-BR).

Edited by xilopaint
Link to comment

Still not working.

 

By the way, why the first result has no flag or language? Look:

xPzgQ3m.png

P.S.: Notice, as I already pointed in this thread, that the code for Brazilian Portuguese is wrong (pt-BZ instead pt-BR).

 

Try deleting the config file. It should be somewhere like ~/Library/Application Support/Alfred 2/Workflow Data/com.spr.translate.api/config.ini.

 

Then re-enter the api key and try again. More than likely there is a null value for the first item. I'll change the code for BR soon.

Link to comment

Try deleting the config file. It should be somewhere like ~/Library/Application Support/Alfred 2/Workflow Data/com.spr.translate.api/config.ini.

 

Then re-enter the api key and try again. More than likely there is a null value for the first item. I'll change the code for BR soon.

 

 

Nothing has changed and the null value persists. :(

Link to comment

Another thought for possible failure. Google provides three months free (basically), but if you downloaded the previous version and created the project on Google then, you didn't need to add a credit card to your account. If you haven't added one by now to let it bill you, then it might be rejecting the queries based on that.

Link to comment
  • 1 month later...

Is it possible to add Pinyin to the results? The functionality doesn't seem to be published on Google's API documentation, however the Google API seems to support it (at least the previous version before they locked down the API) as seen in this package:

 

https://pypi.python.org/pypi/goslate#romanlization

 

I looked through the source for the  but couldn't even find where this package made an API call...

Link to comment

Is it possible to add Pinyin to the results? The functionality doesn't seem to be published on Google's API documentation, however the Google API seems to support it (at least the previous version before they locked down the API) as seen in this package:

 

https://pypi.python.org/pypi/goslate#romanlization

 

I looked through the source for the  but couldn't even find where this package made an API call...

 

It'll probably take me a while to get to this. If it were in the documentation, then it would be much easier to do, but otherwise I have to find the time to reverse engineer the API calls (which might change if they're not official).

Link to comment

Is it possible to add Pinyin to the results? The functionality doesn't seem to be published on Google's API documentation, however the Google API seems to support it (at least the previous version before they locked down the API) as seen in this package:

 

https://pypi.python.org/pypi/goslate#romanlization

 

I looked through the source for the  but couldn't even find where this package made an API call...

 

 

It adds &dt=rm to the URL.

Link to comment
  • 3 months later...

;;;;;

; `config.ini` generated by Alphred v0.9.7

; at 2016-Feb-19 16:48:32

;;;;;

 

api_key = "xxxxxxxxxxxxxxx"

languages = ",pt-BR,en,es"

 

 

I think the null value is due to the first comma in ",pt-BR,en,es". Try to remove it, i.e. replace with "pt-BR,en,es".

Link to comment
  • 2 years later...

help me

 

Starting debug for 'Translate'

 

[2019-02-08 22:37:55][STDERR: input.scriptfilter] [22:37:54][filter.php:103][ERROR] Request completely failed, and no cached data exists. cURL debug information follows:

[22:37:54][filter.php:103][ERROR] cURL error number: 22

[22:37:54][filter.php:103][ERROR] cURL error message: `The requested URL returned error: 503 Service Unavailable`.

[22:37:55][filter.php:103][ERROR] Request completely failed, and no cached data exists. cURL debug information follows:

[22:37:55][filter.php:103][ERROR] cURL error number: 22

[22:37:55][filter.php:103][ERROR] cURL error message: `The requested URL returned error: 503 Service Unavailable`.

[2019-02-08 22:37:55][ERROR: input.scriptfilter] JSON error: JSON text did not start with array or object and option to allow fragments not set. in JSON:

Warning: Invalid argument supplied for foreach() in /Users/moritayu/Library/Application Support/Alfred 3/Alfred.alfredpreferences/workflows/user.workflow.000099A5-D31E-4F18-8757-38D71113EBF3/functions.php on line 22

 

Warning: Invalid argument supplied for foreach() in /Users/moritayu/Library/Application Support/Alfred 3/Alfred.alfredpreferences/workflows/user.workflow.000099A5-D31E-4F18-8757-38D71113EBF3/functions.php on line 22

<?xml version="1.0" encoding="UTF-8"?>

<items>

<item arg="{&quot;action&quot;:&quot;translate&quot;,&quot;translation&quot;:&quot;&quot;,&quot;original&quot;:&quot;word&quot;,&quot;code&quot;:&quot;ja&quot;,&quot;listen&quot;:&quot;&quot;}" valid="yes">

  <title></title>

  <subtitle>Japanese: word</subtitle>

  <icon>icons/ja.png</icon>

  <subtitle mod="cmd">Open in Web Browser</subtitle>

  <subtitle mod="alt">Listen to Translation</subtitle>

</item>

<item arg="{&quot;action&quot;:&quot;translate&quot;,&quot;translation&quot;:&quot;&quot;,&quot;original&quot;:&quot;word&quot;,&quot;code&quot;:&quot;en&quot;,&quot;listen&quot;:&quot;&quot;}" valid="yes">

  <title></title>

  <subtitle>English: word</subtitle>

  <icon>icons/en.png</icon>

  <subtitle mod="cmd">Open in Web Browser</subtitle>

  <subtitle mod="alt">Listen to Translation</subtitle>

</item>

</items>

Link to comment
  • 6 months later...
On 2/8/2019 at 2:39 PM, yuyuyu said:

help me

 

Starting debug for 'Translate'

 

[2019-02-08 22:37:55][STDERR: input.scriptfilter] [22:37:54][filter.php:103][ERROR] Request completely failed, and no cached data exists. cURL debug information follows:

[22:37:54][filter.php:103][ERROR] cURL error number: 22

[22:37:54][filter.php:103][ERROR] cURL error message: `The requested URL returned error: 503 Service Unavailable`.

[22:37:55][filter.php:103][ERROR] Request completely failed, and no cached data exists. cURL debug information follows:

[22:37:55][filter.php:103][ERROR] cURL error number: 22

[22:37:55][filter.php:103][ERROR] cURL error message: `The requested URL returned error: 503 Service Unavailable`.

[2019-02-08 22:37:55][ERROR: input.scriptfilter] JSON error: JSON text did not start with array or object and option to allow fragments not set. in JSON:

Warning: Invalid argument supplied for foreach() in /Users/moritayu/Library/Application Support/Alfred 3/Alfred.alfredpreferences/workflows/user.workflow.000099A5-D31E-4F18-8757-38D71113EBF3/functions.php on line 22

 

Warning: Invalid argument supplied for foreach() in /Users/moritayu/Library/Application Support/Alfred 3/Alfred.alfredpreferences/workflows/user.workflow.000099A5-D31E-4F18-8757-38D71113EBF3/functions.php on line 22

<?xml version="1.0" encoding="UTF-8"?>

<items>

<item arg="{&quot;action&quot;:&quot;translate&quot;,&quot;translation&quot;:&quot;&quot;,&quot;original&quot;:&quot;word&quot;,&quot;code&quot;:&quot;ja&quot;,&quot;listen&quot;:&quot;&quot;}" valid="yes">

  <title></title>

  <subtitle>Japanese: word</subtitle>

  <icon>icons/ja.png</icon>

  <subtitle mod="cmd">Open in Web Browser</subtitle>

  <subtitle mod="alt">Listen to Translation</subtitle>

</item>

<item arg="{&quot;action&quot;:&quot;translate&quot;,&quot;translation&quot;:&quot;&quot;,&quot;original&quot;:&quot;word&quot;,&quot;code&quot;:&quot;en&quot;,&quot;listen&quot;:&quot;&quot;}" valid="yes">

  <title></title>

  <subtitle>English: word</subtitle>

  <icon>icons/en.png</icon>

  <subtitle mod="cmd">Open in Web Browser</subtitle>

  <subtitle mod="alt">Listen to Translation</subtitle>

</item>

</items>

 

Exactly the same for me.

 

Thanks for an excellent Alfred workflow

Link to comment
  • 2 years later...

I've been using this workflow using a Google API for years now with no problems.  It's like magic to everyone around me trying to figure out how I do this.

 

With the recent Monterey MacOS upgrade, this workflow does not work.  Normally, I trigger Alfred, then start to type my trigger "tl", and I could just start to the the text I want translated.  However, I see the logo for the workflow for a moment before it goes into Alfred's search mode.  I don't think I did anything to the workflow before the Monterey update.

 

Not sure what's going on.  Here is the bug report:

 

Screen Shot 2021-10-31 at 4.15.10 PM.png

Edited by milopus
Link to comment
13 hours ago, milopus said:

Not sure what's going on.

 

The cause is the removal of PHP in Monterey. I don’t have an API key to test (and I’m still on Big Sur) but this should work to fix it:

  1. Install Homebrew.
  2. Install PHP (brew install php).
  3. Add to the top of the Script Filter and both Run Scripts:

export PATH="/opt/homebrew/bin:/usr/local/bin:${PATH}"

 

Link to comment
3 hours ago, vitor said:

The cause is the removal of PHP in Monterey. I don’t have an API key to test (and I’m still on Big Sur) but this should work to fix it:

  1. Install Homebrew.
  2. Install PHP (brew install php).
  3. Add to the top of the Script Filter and both Run Scripts:

 

export PATH="/opt/homebrew/bin:/usr/local/bin:${PATH}"

 

 

Thanks, I installed Homebrew and PHP as well as adding that text at the top of the Script filter.

 

However, it still does not work, but I see this in the debugger.  Thanks in advance.

 

Quote

[9:08:19.035 AM] Translate API[Script Filter] Queuing argument ''

[9:08:19.104 AM] Translate API[Script Filter] Script with argv '(null)' finished

[9:08:19.106 AM] STDERR: Translate API[Script Filter] PHP Warning:  Undefined array key "" in /Users/myHDD/~~~~~~~~~/Alfred.alfredpreferences/workflows/user.workflow.0D0939D0-C140-4F96-8094-0F56E470FD56/filter.php on line 37

[9:08:19.107 AM] Translate API[Script Filter] Warning: Undefined array key "" in /Users/myHDD/~~~~~~~~~/Alfred.alfredpreferences/workflows/user.workflow.0D0939D0-C140-4F96-8094-0F56E470FD56/filter.php on line 37

<?xml version="1.0" encoding="UTF-8"?>

<items>

<item valid="no">

  <title>Type to translate...</title>

</item>

<item autocomplete="› set language ›" valid="no">

  <title>Set Translation Languages</title>

  <subtitle>Currently translating to ``</subtitle>

</item>

<item arg="{&quot;action&quot;:&quot;set-api-key&quot;}" valid="yes">

  <title>Set Google Translate API Key</title>

  <subtitle>API Key is currently set to &quot;MyGoogleAPI_is_confirmed_and_here&quot;</subtitle>

</item>

</items>

[9:08:19.109 AM] ERROR: Translate API[Script Filter] JSON error: JSON text did not start with array or object and option to allow fragments not set. around line 1, column 0. in JSON:

Warning: Undefined array key "" in /Users/myHDD/~~~~~~~~~/Alfred.alfredpreferences/workflows/user.workflow.0D0939D0-C140-4F96-8094-0F56E470FD56/filter.php on line 37

<?xml version="1.0" encoding="UTF-8"?>

<items>

<item valid="no">

  <title>Type to translate...</title>

</item>

<item autocomplete="› set language ›" valid="no">

  <title>Set Translation Languages</title>

  <subtitle>Currently translating to ``</subtitle>

</item>

<item arg="{&quot;action&quot;:&quot;set-api-key&quot;}" valid="yes">

  <title>Set Google Translate API Key</title>

  <subtitle>API Key is currently set to &quot;MyGoogleAPI_is_confirmed_and_here&quot;</subtitle>

</item>

</items>

 

Link to comment
  • 2 months later...
On 11/1/2021 at 3:15 AM, milopus said:

hanks, I installed Homebrew and PHP as well as adding that text at the top of the Script filter.

 

However, it still does not work, but I see this in the debugger.  Thanks in advance.

 

This workflow has been so useful, it's a pity it does not work on Monterey, hopefully it can be fixed. I also installed php using homebrew in Monterey, seems to be running php correctly but seems there is code in the workflow being deprecated in newer versions of php. I paste the debugger information below when translating the string "Alfred is great". I'm on macOS 12.1 using Alfred version 4.6.1 and php 8.1.1. Errors about auto_detect_line_endings and JSON. Unfortunately I do not know anything about php so do not understand how to fix. As you can see from the debug info below the string is actually translated, so possibly just a few changes are needed to make the workflow working again. Anyone with needed skills that can assist?

 

[10:46:58.566] STDERR: Translate API[Script Filter] PHP Deprecated:  auto_detect_line_endings is deprecated in phar:///Users/***/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.80D64116-6465-4CFF-B003-3F558C5495AB/Alphred.phar/Main.php on line 29
[10:46:58.567] ERROR: Translate API[Script Filter] JSON error: JSON text did not start with array or object and option to allow fragments not set. around line 1, column 0. in JSON:
Deprecated: auto_detect_line_endings is deprecated in phar:///Users/***/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.80D64116-6465-4CFF-B003-3F558C5495AB/Alphred.phar/Main.php on line 29
<?xml version="1.0" encoding="UTF-8"?>
<items>
 <item valid="no">
  <title>Type to translate...</title>
 </item>
 <item autocomplete="› set language ›" valid="no">
  <title>Set Translation Languages</title>
  <subtitle>Currently translating to `English, Swedish`</subtitle>
 </item>
 <item arg="{&quot;action&quot;:&quot;set-api-key&quot;}" valid="yes">
  <title>Set Google Translate API Key</title>
  <subtitle>API Key is currently set to &quot;*****&quot;</subtitle>
 </item>
</items>
[10:47:01.331] STDERR: Translate API[Script Filter] PHP Deprecated:  auto_detect_line_endings is deprecated in phar:///Users/***/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.80D64116-6465-4CFF-B003-3F558C5495AB/Alphred.phar/Main.php on line 29
[10:47:01.332] ERROR: Translate API[Script Filter] JSON error: JSON text did not start with array or object and option to allow fragments not set. around line 1, column 0. in JSON:
Deprecated: auto_detect_line_endings is deprecated in phar:///Users/***/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.80D64116-6465-4CFF-B003-3F558C5495AB/Alphred.phar/Main.php on line 29
<?xml version="1.0" encoding="UTF-8"?>
<items>
 <item arg="{&quot;action&quot;:&quot;translate&quot;,&quot;translation&quot;:&quot;Alfred is great&quot;,&quot;original&quot;:&quot;Alfred is great&quot;,&quot;code&quot;:&quot;en&quot;}" valid="yes">
  <title>Alfred is great</title>
  <subtitle>English: Alfred is great</subtitle>
  <icon>icons/en.png</icon>
  <subtitle mod="cmd">Open in Web Browser</subtitle>
 </item>
 <item arg="{&quot;action&quot;:&quot;translate&quot;,&quot;translation&quot;:&quot;Alfred \u00e4r j\u00e4ttebra&quot;,&quot;original&quot;:&quot;Alfred is great&quot;,&quot;code&quot;:&quot;sv&quot;}" valid="yes">
  <title>Alfred är jättebra</title>
  <subtitle>Swedish: Alfred is great</subtitle>
  <icon>icons/sv.png</icon>
  <subtitle mod="cmd">Open in Web Browser</subtitle>
 </item>
</items>

 

Edited by cands
Link to comment
On 1/16/2022 at 11:23 AM, deanishe said:

 

Thanks for the tip, that might work, but seems the file to edit is in a special php .phar package named "Alphred.phar". Could not find a simple way to edit, had very little time to look into this now though and I have no experience with php. Maybe the fix is simple with just a little bit experience, if I get more time later I will take a closer look.

Link to comment
  • 3 months later...

Hi!

I just managed to add the API by adding

Quote

PATH="/opt/homebrew/bin:/usr/local/bin:${PATH}"

 

to the script. It still does not work and nothing happens. Same thing happens if I use

 

/opt/homebrew/opt/php@7.4/bin/php filter.php "{query}"

 

The problem seems to revolve around line 37 in filter.php but I don't know what's wrong.

 

I am using a Macbook Pro 16" with Apples M1 Pro chip.

 

Any recommendations on how I can solve this? Thanks a lot in advance.

 

Quote

[01:07:42.640] Translate API[Script Filter] Queuing argument ''
[01:07:42.787] Translate API[Script Filter] Script with argv '(null)' finished
[01:07:42.789] STDERR: Translate API[Script Filter] PHP Notice:  Undefined index:  in /Users/doogie/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.91003814-D445-4A42-8425-0CBD61A92904/filter.php on line 37
[01:07:42.790] Translate API[Script Filter] Notice: Undefined index:  in /Users/doogie/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.91003814-D445-4A42-8425-0CBD61A92904/filter.php on line 37
<?xml version="1.0" encoding="UTF-8"?>
<items>
 <item valid="no">
  <title>Type to translate...</title>
 </item>
 <item autocomplete="› set language ›" valid="no">
  <title>Set Translation Languages</title>
  <subtitle>Currently translating to ``</subtitle>
 </item>
 <item arg="{&quot;action&quot;:&quot;set-api-key&quot;}" valid="yes">
  <title>Set Google Translate API Key</title>
  <subtitle>API Key is currently set to &quot;XXX&quot;</subtitle>
 </item>
</items>
[01:07:42.791] ERROR: Translate API[Script Filter] JSON error: JSON text did not start with array or object and option to allow fragments not set. around line 1, column 0. in JSON:
Notice: Undefined index:  in /Users/doogie/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.91003814-D445-4A42-8425-0CBD61A92904/filter.php on line 37
<?xml version="1.0" encoding="UTF-8"?>
<items>
 <item valid="no">
  <title>Type to translate...</title>
 </item>
 <item autocomplete="› set language ›" valid="no">
  <title>Set Translation Languages</title>
  <subtitle>Currently translating to ``</subtitle>
 </item>
 <item arg="{&quot;action&quot;:&quot;set-api-key&quot;}" valid="yes">
  <title>Set Google Translate API Key</title>
  <subtitle>API Key is currently set to &quot;XXX&quot;</subtitle>
 </item>
</items>

 

Edited by Brekker
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...