From f813362cd34782f6a0f15ba777f95a46077af4e5 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Wed, 25 Feb 2026 12:05:56 -0800 Subject: [PATCH 1/2] feat(google-translate): add Google Translate integration --- apps/docs/components/icons.tsx | 28 ++++ apps/docs/components/ui/icon-mapping.ts | 2 + .../docs/en/tools/google_translate.mdx | 55 ++++++++ apps/docs/content/docs/en/tools/meta.json | 1 + apps/sim/blocks/blocks/google_translate.ts | 130 ++++++++++++++++++ apps/sim/blocks/registry.ts | 2 + apps/sim/components/icons.tsx | 28 ++++ apps/sim/tools/google_translate/detect.ts | 79 +++++++++++ apps/sim/tools/google_translate/index.ts | 4 + apps/sim/tools/google_translate/translate.ts | 99 +++++++++++++ apps/sim/tools/google_translate/types.ts | 28 ++++ apps/sim/tools/registry.ts | 3 + 12 files changed, 459 insertions(+) create mode 100644 apps/docs/content/docs/en/tools/google_translate.mdx create mode 100644 apps/sim/blocks/blocks/google_translate.ts create mode 100644 apps/sim/tools/google_translate/detect.ts create mode 100644 apps/sim/tools/google_translate/index.ts create mode 100644 apps/sim/tools/google_translate/translate.ts create mode 100644 apps/sim/tools/google_translate/types.ts diff --git a/apps/docs/components/icons.tsx b/apps/docs/components/icons.tsx index dcd5741f2b..91748946d4 100644 --- a/apps/docs/components/icons.tsx +++ b/apps/docs/components/icons.tsx @@ -5445,6 +5445,34 @@ export function GoogleMapsIcon(props: SVGProps) { ) } +export function GoogleTranslateIcon(props: SVGProps) { + return ( + + + + + + + + + ) +} + export function DsPyIcon(props: SVGProps) { return ( diff --git a/apps/docs/components/ui/icon-mapping.ts b/apps/docs/components/ui/icon-mapping.ts index 5121253240..ba0e2bf32f 100644 --- a/apps/docs/components/ui/icon-mapping.ts +++ b/apps/docs/components/ui/icon-mapping.ts @@ -52,6 +52,7 @@ import { GoogleMapsIcon, GoogleSheetsIcon, GoogleSlidesIcon, + GoogleTranslateIcon, GoogleVaultIcon, GrafanaIcon, GrainIcon, @@ -197,6 +198,7 @@ export const blockTypeToIconMap: Record = { google_search: GoogleIcon, google_sheets_v2: GoogleSheetsIcon, google_slides_v2: GoogleSlidesIcon, + google_translate: GoogleTranslateIcon, google_vault: GoogleVaultIcon, grafana: GrafanaIcon, grain: GrainIcon, diff --git a/apps/docs/content/docs/en/tools/google_translate.mdx b/apps/docs/content/docs/en/tools/google_translate.mdx new file mode 100644 index 0000000000..437a2d0081 --- /dev/null +++ b/apps/docs/content/docs/en/tools/google_translate.mdx @@ -0,0 +1,55 @@ +--- +title: Google Translate +description: Translate text using Google Cloud Translation +--- + +import { BlockInfoCard } from "@/components/ui/block-info-card" + + + +## Usage Instructions + +Translate and detect languages using the Google Cloud Translation API. Supports auto-detection of the source language. + + + +## Tools + +### `google_translate_text` + +#### Input + +| Parameter | Type | Required | Description | +| --------- | ---- | -------- | ----------- | + +#### Output + +| Parameter | Type | Description | +| --------- | ---- | ----------- | +| `translatedText` | string | Translated text | +| `detectedSourceLanguage` | string | Detected source language code | +| `language` | string | Detected language code | +| `confidence` | number | Detection confidence score | + +### `google_translate_detect` + +Detect the language of text using the Google Cloud Translation API. + +#### Input + +| Parameter | Type | Required | Description | +| --------- | ---- | -------- | ----------- | +| `apiKey` | string | Yes | Google Cloud API key with Cloud Translation API enabled | +| `text` | string | Yes | The text to detect the language of | + +#### Output + +| Parameter | Type | Description | +| --------- | ---- | ----------- | +| `language` | string | The detected language code \(e.g., "en", "es", "fr"\) | +| `confidence` | number | Confidence score of the detection | + + diff --git a/apps/docs/content/docs/en/tools/meta.json b/apps/docs/content/docs/en/tools/meta.json index 9fc1cc577e..cd896c4457 100644 --- a/apps/docs/content/docs/en/tools/meta.json +++ b/apps/docs/content/docs/en/tools/meta.json @@ -47,6 +47,7 @@ "google_search", "google_sheets", "google_slides", + "google_translate", "google_vault", "grafana", "grain", diff --git a/apps/sim/blocks/blocks/google_translate.ts b/apps/sim/blocks/blocks/google_translate.ts new file mode 100644 index 0000000000..ba74b4f717 --- /dev/null +++ b/apps/sim/blocks/blocks/google_translate.ts @@ -0,0 +1,130 @@ +import { GoogleTranslateIcon } from '@/components/icons' +import { AuthMode, type BlockConfig } from '@/blocks/types' + +export const GoogleTranslateBlock: BlockConfig = { + type: 'google_translate', + name: 'Google Translate', + description: 'Translate text using Google Cloud Translation', + longDescription: + 'Translate and detect languages using the Google Cloud Translation API. Supports auto-detection of the source language.', + docsLink: 'https://docs.sim.ai/tools/google-translate', + category: 'tools', + bgColor: '#E0E0E0', + icon: GoogleTranslateIcon, + authMode: AuthMode.ApiKey, + subBlocks: [ + { + id: 'operation', + title: 'Operation', + type: 'dropdown', + options: [ + { label: 'Translate Text', id: 'text' }, + { label: 'Detect Language', id: 'detect' }, + ], + value: () => 'text', + }, + { + id: 'text', + title: 'Text', + type: 'long-input', + placeholder: 'Enter text...', + required: true, + }, + { + id: 'target', + title: 'Target Language', + type: 'dropdown', + condition: { field: 'operation', value: 'text' }, + options: [ + { label: 'English', id: 'en' }, + { label: 'Spanish', id: 'es' }, + { label: 'French', id: 'fr' }, + { label: 'German', id: 'de' }, + { label: 'Italian', id: 'it' }, + { label: 'Portuguese', id: 'pt' }, + { label: 'Russian', id: 'ru' }, + { label: 'Japanese', id: 'ja' }, + { label: 'Korean', id: 'ko' }, + { label: 'Chinese (Simplified)', id: 'zh-CN' }, + { label: 'Chinese (Traditional)', id: 'zh-TW' }, + { label: 'Arabic', id: 'ar' }, + { label: 'Hindi', id: 'hi' }, + { label: 'Turkish', id: 'tr' }, + { label: 'Dutch', id: 'nl' }, + { label: 'Polish', id: 'pl' }, + { label: 'Swedish', id: 'sv' }, + { label: 'Thai', id: 'th' }, + { label: 'Vietnamese', id: 'vi' }, + { label: 'Indonesian', id: 'id' }, + { label: 'Ukrainian', id: 'uk' }, + { label: 'Czech', id: 'cs' }, + { label: 'Greek', id: 'el' }, + { label: 'Hebrew', id: 'he' }, + { label: 'Romanian', id: 'ro' }, + { label: 'Hungarian', id: 'hu' }, + { label: 'Danish', id: 'da' }, + { label: 'Finnish', id: 'fi' }, + { label: 'Norwegian', id: 'no' }, + { label: 'Bengali', id: 'bn' }, + { label: 'Malay', id: 'ms' }, + { label: 'Filipino', id: 'tl' }, + { label: 'Swahili', id: 'sw' }, + { label: 'Urdu', id: 'ur' }, + ], + value: () => 'es', + required: { field: 'operation', value: 'text' }, + }, + { + id: 'source', + title: 'Source Language', + type: 'dropdown', + condition: { field: 'operation', value: 'text' }, + options: [ + { label: 'Auto-detect', id: '' }, + { label: 'English', id: 'en' }, + { label: 'Spanish', id: 'es' }, + { label: 'French', id: 'fr' }, + { label: 'German', id: 'de' }, + { label: 'Italian', id: 'it' }, + { label: 'Portuguese', id: 'pt' }, + { label: 'Russian', id: 'ru' }, + { label: 'Japanese', id: 'ja' }, + { label: 'Korean', id: 'ko' }, + { label: 'Chinese (Simplified)', id: 'zh-CN' }, + { label: 'Chinese (Traditional)', id: 'zh-TW' }, + { label: 'Arabic', id: 'ar' }, + { label: 'Hindi', id: 'hi' }, + { label: 'Turkish', id: 'tr' }, + { label: 'Dutch', id: 'nl' }, + { label: 'Polish', id: 'pl' }, + ], + value: () => '', + }, + { + id: 'apiKey', + title: 'API Key', + type: 'short-input', + placeholder: 'Enter your Google Cloud API key', + password: true, + required: true, + }, + ], + tools: { + access: ['google_translate_text', 'google_translate_detect'], + config: { + tool: (params) => `google_translate_${params.operation}`, + }, + }, + inputs: { + text: { type: 'string', description: 'Text to translate or detect language of' }, + target: { type: 'string', description: 'Target language code' }, + source: { type: 'string', description: 'Source language code (optional, auto-detected)' }, + apiKey: { type: 'string', description: 'Google Cloud API key' }, + }, + outputs: { + translatedText: { type: 'string', description: 'Translated text' }, + detectedSourceLanguage: { type: 'string', description: 'Detected source language code' }, + language: { type: 'string', description: 'Detected language code' }, + confidence: { type: 'number', description: 'Detection confidence score' }, + }, +} diff --git a/apps/sim/blocks/registry.ts b/apps/sim/blocks/registry.ts index 03b9827a77..a6d3ef3652 100644 --- a/apps/sim/blocks/registry.ts +++ b/apps/sim/blocks/registry.ts @@ -52,6 +52,7 @@ import { GoogleGroupsBlock } from '@/blocks/blocks/google_groups' import { GoogleMapsBlock } from '@/blocks/blocks/google_maps' import { GoogleSheetsBlock, GoogleSheetsV2Block } from '@/blocks/blocks/google_sheets' import { GoogleSlidesBlock, GoogleSlidesV2Block } from '@/blocks/blocks/google_slides' +import { GoogleTranslateBlock } from '@/blocks/blocks/google_translate' import { GoogleVaultBlock } from '@/blocks/blocks/google_vault' import { GrafanaBlock } from '@/blocks/blocks/grafana' import { GrainBlock } from '@/blocks/blocks/grain' @@ -234,6 +235,7 @@ export const registry: Record = { google_forms: GoogleFormsBlock, google_groups: GoogleGroupsBlock, google_maps: GoogleMapsBlock, + google_translate: GoogleTranslateBlock, gong: GongBlock, google_search: GoogleSearchBlock, google_sheets: GoogleSheetsBlock, diff --git a/apps/sim/components/icons.tsx b/apps/sim/components/icons.tsx index dcd5741f2b..91748946d4 100644 --- a/apps/sim/components/icons.tsx +++ b/apps/sim/components/icons.tsx @@ -5445,6 +5445,34 @@ export function GoogleMapsIcon(props: SVGProps) { ) } +export function GoogleTranslateIcon(props: SVGProps) { + return ( + + + + + + + + + ) +} + export function DsPyIcon(props: SVGProps) { return ( diff --git a/apps/sim/tools/google_translate/detect.ts b/apps/sim/tools/google_translate/detect.ts new file mode 100644 index 0000000000..2b90d468d1 --- /dev/null +++ b/apps/sim/tools/google_translate/detect.ts @@ -0,0 +1,79 @@ +import type { + GoogleTranslateDetectParams, + GoogleTranslateDetectResponse, +} from '@/tools/google_translate/types' +import type { ToolConfig } from '@/tools/types' + +export const googleTranslateDetectTool: ToolConfig< + GoogleTranslateDetectParams, + GoogleTranslateDetectResponse +> = { + id: 'google_translate_detect', + name: 'Google Translate Detect Language', + description: 'Detect the language of text using the Google Cloud Translation API.', + version: '1.0.0', + + params: { + apiKey: { + type: 'string', + required: true, + visibility: 'user-only', + description: 'Google Cloud API key with Cloud Translation API enabled', + }, + text: { + type: 'string', + required: true, + visibility: 'user-or-llm', + description: 'The text to detect the language of', + }, + }, + + request: { + url: 'https://translation.googleapis.com/language/translate/v2/detect', + method: 'POST', + headers: () => ({ + 'Content-Type': 'application/json', + }), + body: (params) => ({ + q: params.text, + key: params.apiKey, + }), + }, + + transformResponse: async (response: Response) => { + const data = await response.json() + + if (data.error) { + return { + success: false, + output: { + language: '', + confidence: null, + }, + error: data.error.message ?? 'Google Translate API error', + } + } + + const detection = data.data?.detections?.[0]?.[0] + + return { + success: true, + output: { + language: detection?.language ?? '', + confidence: detection?.confidence ?? null, + }, + } + }, + + outputs: { + language: { + type: 'string', + description: 'The detected language code (e.g., "en", "es", "fr")', + }, + confidence: { + type: 'number', + description: 'Confidence score of the detection', + optional: true, + }, + }, +} diff --git a/apps/sim/tools/google_translate/index.ts b/apps/sim/tools/google_translate/index.ts new file mode 100644 index 0000000000..3d2c4450ae --- /dev/null +++ b/apps/sim/tools/google_translate/index.ts @@ -0,0 +1,4 @@ +import { googleTranslateDetectTool } from './detect' +import { googleTranslateTool } from './translate' + +export { googleTranslateDetectTool, googleTranslateTool } diff --git a/apps/sim/tools/google_translate/translate.ts b/apps/sim/tools/google_translate/translate.ts new file mode 100644 index 0000000000..6e191ca921 --- /dev/null +++ b/apps/sim/tools/google_translate/translate.ts @@ -0,0 +1,99 @@ +import type { GoogleTranslateParams, GoogleTranslateResponse } from '@/tools/google_translate/types' +import type { ToolConfig } from '@/tools/types' + +export const googleTranslateTool: ToolConfig = { + id: 'google_translate_text', + name: 'Google Translate', + description: + 'Translate text between languages using the Google Cloud Translation API. Supports auto-detection of the source language.', + version: '1.0.0', + + params: { + apiKey: { + type: 'string', + required: true, + visibility: 'user-only', + description: 'Google Cloud API key with Cloud Translation API enabled', + }, + text: { + type: 'string', + required: true, + visibility: 'user-or-llm', + description: 'The text to translate', + }, + target: { + type: 'string', + required: true, + visibility: 'user-or-llm', + description: 'Target language code (e.g., "es", "fr", "de", "ja")', + }, + source: { + type: 'string', + required: false, + visibility: 'user-or-llm', + description: + 'Source language code. If omitted, the API will auto-detect the source language.', + }, + format: { + type: 'string', + required: false, + visibility: 'user-or-llm', + description: 'Format of the text: "text" for plain text, "html" for HTML content', + }, + }, + + request: { + url: 'https://translation.googleapis.com/language/translate/v2', + method: 'POST', + headers: () => ({ + 'Content-Type': 'application/json', + }), + body: (params) => { + const body: Record = { + q: params.text, + target: params.target, + key: params.apiKey, + } + if (params.source) body.source = params.source + if (params.format) body.format = params.format + return body + }, + }, + + transformResponse: async (response: Response) => { + const data = await response.json() + + if (data.error) { + return { + success: false, + output: { + translatedText: '', + detectedSourceLanguage: null, + }, + error: data.error.message ?? 'Google Translate API error', + } + } + + const translation = data.data?.translations?.[0] + + return { + success: true, + output: { + translatedText: translation?.translatedText ?? '', + detectedSourceLanguage: translation?.detectedSourceLanguage ?? null, + }, + } + }, + + outputs: { + translatedText: { + type: 'string', + description: 'The translated text', + }, + detectedSourceLanguage: { + type: 'string', + description: 'The detected source language code (if source was not specified)', + optional: true, + }, + }, +} diff --git a/apps/sim/tools/google_translate/types.ts b/apps/sim/tools/google_translate/types.ts new file mode 100644 index 0000000000..2ceffd18f5 --- /dev/null +++ b/apps/sim/tools/google_translate/types.ts @@ -0,0 +1,28 @@ +import type { ToolResponse } from '@/tools/types' + +export interface GoogleTranslateParams { + apiKey: string + text: string + target: string + source?: string + format?: 'text' | 'html' +} + +export interface GoogleTranslateResponse extends ToolResponse { + output: { + translatedText: string + detectedSourceLanguage: string | null + } +} + +export interface GoogleTranslateDetectParams { + apiKey: string + text: string +} + +export interface GoogleTranslateDetectResponse extends ToolResponse { + output: { + language: string + confidence: number | null + } +} diff --git a/apps/sim/tools/registry.ts b/apps/sim/tools/registry.ts index 5a2f5787c7..ab49e04850 100644 --- a/apps/sim/tools/registry.ts +++ b/apps/sim/tools/registry.ts @@ -738,6 +738,7 @@ import { googleSlidesUpdateSlidesPositionTool, googleSlidesWriteTool, } from '@/tools/google_slides' +import { googleTranslateDetectTool, googleTranslateTool } from '@/tools/google_translate' import { createMattersExportTool, createMattersHoldsTool, @@ -2891,6 +2892,8 @@ export const tools: Record = { google_maps_speed_limits: googleMapsSpeedLimitsTool, google_maps_timezone: googleMapsTimezoneTool, google_maps_validate_address: googleMapsValidateAddressTool, + google_translate_detect: googleTranslateDetectTool, + google_translate_text: googleTranslateTool, google_sheets_read: googleSheetsReadTool, google_sheets_write: googleSheetsWriteTool, google_sheets_update: googleSheetsUpdateTool, From f383aa51fbbd9d2a94bcff8777d7dc2b57a4f245 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Wed, 25 Feb 2026 13:06:02 -0800 Subject: [PATCH 2/2] fix(google-translate): api key as query param, fix docsLink, rename tool file --- .../docs/content/docs/en/tools/google_translate.mdx | 13 +++++++++---- apps/sim/blocks/blocks/google_translate.ts | 2 +- apps/sim/tools/google_translate/detect.ts | 7 +++++-- apps/sim/tools/google_translate/index.ts | 2 +- .../google_translate/{translate.ts => text.ts} | 7 +++++-- 5 files changed, 21 insertions(+), 10 deletions(-) rename apps/sim/tools/google_translate/{translate.ts => text.ts} (93%) diff --git a/apps/docs/content/docs/en/tools/google_translate.mdx b/apps/docs/content/docs/en/tools/google_translate.mdx index 437a2d0081..2e890b1149 100644 --- a/apps/docs/content/docs/en/tools/google_translate.mdx +++ b/apps/docs/content/docs/en/tools/google_translate.mdx @@ -20,19 +20,24 @@ Translate and detect languages using the Google Cloud Translation API. Supports ### `google_translate_text` +Translate text between languages using the Google Cloud Translation API. Supports auto-detection of the source language. + #### Input | Parameter | Type | Required | Description | | --------- | ---- | -------- | ----------- | +| `apiKey` | string | Yes | Google Cloud API key with Cloud Translation API enabled | +| `text` | string | Yes | The text to translate | +| `target` | string | Yes | Target language code \(e.g., "es", "fr", "de", "ja"\) | +| `source` | string | No | Source language code. If omitted, the API will auto-detect the source language. | +| `format` | string | No | Format of the text: "text" for plain text, "html" for HTML content | #### Output | Parameter | Type | Description | | --------- | ---- | ----------- | -| `translatedText` | string | Translated text | -| `detectedSourceLanguage` | string | Detected source language code | -| `language` | string | Detected language code | -| `confidence` | number | Detection confidence score | +| `translatedText` | string | The translated text | +| `detectedSourceLanguage` | string | The detected source language code \(if source was not specified\) | ### `google_translate_detect` diff --git a/apps/sim/blocks/blocks/google_translate.ts b/apps/sim/blocks/blocks/google_translate.ts index ba74b4f717..881feea0e5 100644 --- a/apps/sim/blocks/blocks/google_translate.ts +++ b/apps/sim/blocks/blocks/google_translate.ts @@ -7,7 +7,7 @@ export const GoogleTranslateBlock: BlockConfig = { description: 'Translate text using Google Cloud Translation', longDescription: 'Translate and detect languages using the Google Cloud Translation API. Supports auto-detection of the source language.', - docsLink: 'https://docs.sim.ai/tools/google-translate', + docsLink: 'https://docs.sim.ai/tools/google_translate', category: 'tools', bgColor: '#E0E0E0', icon: GoogleTranslateIcon, diff --git a/apps/sim/tools/google_translate/detect.ts b/apps/sim/tools/google_translate/detect.ts index 2b90d468d1..48941276f3 100644 --- a/apps/sim/tools/google_translate/detect.ts +++ b/apps/sim/tools/google_translate/detect.ts @@ -29,14 +29,17 @@ export const googleTranslateDetectTool: ToolConfig< }, request: { - url: 'https://translation.googleapis.com/language/translate/v2/detect', + url: (params) => { + const url = new URL('https://translation.googleapis.com/language/translate/v2/detect') + url.searchParams.set('key', params.apiKey) + return url.toString() + }, method: 'POST', headers: () => ({ 'Content-Type': 'application/json', }), body: (params) => ({ q: params.text, - key: params.apiKey, }), }, diff --git a/apps/sim/tools/google_translate/index.ts b/apps/sim/tools/google_translate/index.ts index 3d2c4450ae..ddc89124f7 100644 --- a/apps/sim/tools/google_translate/index.ts +++ b/apps/sim/tools/google_translate/index.ts @@ -1,4 +1,4 @@ import { googleTranslateDetectTool } from './detect' -import { googleTranslateTool } from './translate' +import { googleTranslateTool } from './text' export { googleTranslateDetectTool, googleTranslateTool } diff --git a/apps/sim/tools/google_translate/translate.ts b/apps/sim/tools/google_translate/text.ts similarity index 93% rename from apps/sim/tools/google_translate/translate.ts rename to apps/sim/tools/google_translate/text.ts index 6e191ca921..8f74df318c 100644 --- a/apps/sim/tools/google_translate/translate.ts +++ b/apps/sim/tools/google_translate/text.ts @@ -43,7 +43,11 @@ export const googleTranslateTool: ToolConfig { + const url = new URL('https://translation.googleapis.com/language/translate/v2') + url.searchParams.set('key', params.apiKey) + return url.toString() + }, method: 'POST', headers: () => ({ 'Content-Type': 'application/json', @@ -52,7 +56,6 @@ export const googleTranslateTool: ToolConfig = { q: params.text, target: params.target, - key: params.apiKey, } if (params.source) body.source = params.source if (params.format) body.format = params.format