Skip to content

Commit f383aa5

Browse files
committed
fix(google-translate): api key as query param, fix docsLink, rename tool file
1 parent f813362 commit f383aa5

File tree

5 files changed

+21
-10
lines changed

5 files changed

+21
-10
lines changed

apps/docs/content/docs/en/tools/google_translate.mdx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,24 @@ Translate and detect languages using the Google Cloud Translation API. Supports
2020

2121
### `google_translate_text`
2222

23+
Translate text between languages using the Google Cloud Translation API. Supports auto-detection of the source language.
24+
2325
#### Input
2426

2527
| Parameter | Type | Required | Description |
2628
| --------- | ---- | -------- | ----------- |
29+
| `apiKey` | string | Yes | Google Cloud API key with Cloud Translation API enabled |
30+
| `text` | string | Yes | The text to translate |
31+
| `target` | string | Yes | Target language code \(e.g., "es", "fr", "de", "ja"\) |
32+
| `source` | string | No | Source language code. If omitted, the API will auto-detect the source language. |
33+
| `format` | string | No | Format of the text: "text" for plain text, "html" for HTML content |
2734

2835
#### Output
2936

3037
| Parameter | Type | Description |
3138
| --------- | ---- | ----------- |
32-
| `translatedText` | string | Translated text |
33-
| `detectedSourceLanguage` | string | Detected source language code |
34-
| `language` | string | Detected language code |
35-
| `confidence` | number | Detection confidence score |
39+
| `translatedText` | string | The translated text |
40+
| `detectedSourceLanguage` | string | The detected source language code \(if source was not specified\) |
3641

3742
### `google_translate_detect`
3843

apps/sim/blocks/blocks/google_translate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const GoogleTranslateBlock: BlockConfig = {
77
description: 'Translate text using Google Cloud Translation',
88
longDescription:
99
'Translate and detect languages using the Google Cloud Translation API. Supports auto-detection of the source language.',
10-
docsLink: 'https://docs.sim.ai/tools/google-translate',
10+
docsLink: 'https://docs.sim.ai/tools/google_translate',
1111
category: 'tools',
1212
bgColor: '#E0E0E0',
1313
icon: GoogleTranslateIcon,

apps/sim/tools/google_translate/detect.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@ export const googleTranslateDetectTool: ToolConfig<
2929
},
3030

3131
request: {
32-
url: 'https://translation.googleapis.com/language/translate/v2/detect',
32+
url: (params) => {
33+
const url = new URL('https://translation.googleapis.com/language/translate/v2/detect')
34+
url.searchParams.set('key', params.apiKey)
35+
return url.toString()
36+
},
3337
method: 'POST',
3438
headers: () => ({
3539
'Content-Type': 'application/json',
3640
}),
3741
body: (params) => ({
3842
q: params.text,
39-
key: params.apiKey,
4043
}),
4144
},
4245

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import { googleTranslateDetectTool } from './detect'
2-
import { googleTranslateTool } from './translate'
2+
import { googleTranslateTool } from './text'
33

44
export { googleTranslateDetectTool, googleTranslateTool }

apps/sim/tools/google_translate/translate.ts renamed to apps/sim/tools/google_translate/text.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ export const googleTranslateTool: ToolConfig<GoogleTranslateParams, GoogleTransl
4343
},
4444

4545
request: {
46-
url: 'https://translation.googleapis.com/language/translate/v2',
46+
url: (params) => {
47+
const url = new URL('https://translation.googleapis.com/language/translate/v2')
48+
url.searchParams.set('key', params.apiKey)
49+
return url.toString()
50+
},
4751
method: 'POST',
4852
headers: () => ({
4953
'Content-Type': 'application/json',
@@ -52,7 +56,6 @@ export const googleTranslateTool: ToolConfig<GoogleTranslateParams, GoogleTransl
5256
const body: Record<string, unknown> = {
5357
q: params.text,
5458
target: params.target,
55-
key: params.apiKey,
5659
}
5760
if (params.source) body.source = params.source
5861
if (params.format) body.format = params.format

0 commit comments

Comments
 (0)