-
Notifications
You must be signed in to change notification settings - Fork 3.3k
feat(google-translate): add Google Translate integration #3337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| --- | ||
| title: Google Translate | ||
| description: Translate text using Google Cloud Translation | ||
| --- | ||
|
|
||
| import { BlockInfoCard } from "@/components/ui/block-info-card" | ||
|
|
||
| <BlockInfoCard | ||
| type="google_translate" | ||
| color="#E0E0E0" | ||
| /> | ||
|
|
||
| ## 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 | | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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' }, | ||
| ], | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Source language dropdown missing 18 languages from targetMedium Severity The Additional Locations (1) |
||
| 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' }, | ||
| }, | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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, | ||
| }, | ||
| }, | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import { googleTranslateDetectTool } from './detect' | ||
| import { googleTranslateTool } from './text' | ||
|
|
||
| export { googleTranslateDetectTool, googleTranslateTool } |


Uh oh!
There was an error while loading. Please reload this page.