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..2e890b1149 --- /dev/null +++ b/apps/docs/content/docs/en/tools/google_translate.mdx @@ -0,0 +1,60 @@ +--- +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` + +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 | The translated text | +| `detectedSourceLanguage` | string | The detected source language code \(if source was not specified\) | + +### `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..881feea0e5 --- /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..48941276f3 --- /dev/null +++ b/apps/sim/tools/google_translate/detect.ts @@ -0,0 +1,82 @@ +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: (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, + }), + }, + + 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..ddc89124f7 --- /dev/null +++ b/apps/sim/tools/google_translate/index.ts @@ -0,0 +1,4 @@ +import { googleTranslateDetectTool } from './detect' +import { googleTranslateTool } from './text' + +export { googleTranslateDetectTool, googleTranslateTool } diff --git a/apps/sim/tools/google_translate/text.ts b/apps/sim/tools/google_translate/text.ts new file mode 100644 index 0000000000..8f74df318c --- /dev/null +++ b/apps/sim/tools/google_translate/text.ts @@ -0,0 +1,102 @@ +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: (params) => { + 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', + }), + body: (params) => { + const body: Record = { + q: params.text, + target: params.target, + } + 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,