GoogleCloudTranslate
A Google API cloud based translation service.
Utilities · Google Cloud Translate
Details
| ID | GoogleCloudTranslate |
|---|---|
| Provider | |
| Category | Utilities |
| From Version | 5.0.0 |
| Docker Image | demisto/google-cloud-translate:1.0.0.9843526 |
| Supported Modules | Agentix XSIAM |
README
A Google API cloud based translation service. This integration was integrated and tested with version 2.0.0 of the Python Client of Google Cloud Translate API.
Use Cases
- Translate text from spam emails
- Translate strings found in malware analysis
Detailed Description
In order to use this integration you need the following:
- Select or create a Cloud Platform project on GCP
- Enable billing for the project
- Enable the Google Cloud Translate API
- Create a Service Account with access to Google Translate API
- Use the Service Account Private Key in JSON format and the GCP project ID to configure a new instance of Google Cloud Translate integration in Cortex XSOAR
Create a Service Account
- Go to: https://console.developers.google.com
- Select your project
- From the side-menu go to IAM & admin > Service accounts > CREATE SERVICE ACCOUNT
- Type an account name and description and click CREATE
- From the drop down list Select a role select Cloud Translation API User
- Click CONTINUE and then click CREATE KEY
- Select JSON and click CREATE. The .json file downloads.
Configure GoogleCloudTranslate on Cortex XSOAR
- Navigate to Settings > Integrations > Servers & Services.
- Search for GoogleCloudTranslate.
-
Click Add instance to create and configure a new integration instance.
- Name: a textual name for the integration instance.
- Service Account Private Key file contents (JSON)
- Project in Google Cloud Translate
- Trust any certificate (not secure)
- Use system proxy settings
- Click Test to validate the new instance.
Commands
You can execute these commands from the Cortex XSOAR CLI, as part of an automation, or in a playbook. After you successfully execute a command, a DBot message appears in the War Room with the command details.
- Returns the list of supported two-letter ISO language codes: gct-supported-languages
- Returns the translated text: gct-translate-text
1. gct-supported-languages
Returns the list of supported two-letter ISO language codes.
Base Command
gct-supported-languages
Input
There are no input arguments for this command.
Context Output
| Path | Type | Description |
|---|---|---|
| GoogleCloudTranslate.SupportedLanguages | Unknown | The list of supported two-letter ISO language codes. |
Command Example
!gct-supported-languages
Context Example
{
"GoogleCloudTranslate": {
"SupportedLanguages": [
{
"language_code": "af",
"support_source": true,
"support_target": true
},
{
"language_code": "am",
"support_source": true,
"support_target": true
},
{
"language_code": "ar",
"support_source": true,
"support_target": true
},
...
]
}
}
Human Readable Output
Languages: af, am, ar, az, be, bg, bn, bs, ca, ceb, co, cs, cy, da, de, el, en, eo, es, et, eu, fa, fi, fr, fy, ga, gd, gl, gu, ha, haw, hi, hmn, hr, ht, hu, hy, id, ig, is, it, iw, ja, jw, ka, kk, km, kn, ko, ku, ky, la, lb, lo, lt, lv, mg, mi, mk, ml, mn, mr, ms, mt, my, ne, nl, no, ny, pa, pl, ps, pt, ro, ru, sd, si, sk, sl, sm, sn, so, sq, sr, st, su, sv, sw, ta, te, tg, th, tl, tr, uk, ur, uz, vi, xh, yi, yo, zh-CN, zh-TW, zu
2. gct-translate-text
Returns the translated text.
Base Command
gct-translate-text text="hello world" target="hr"
Input
| Argument Name | Description | Required |
|---|---|---|
| text | The text to translate. | Required |
| target | The two-letter ISO language code of the target language. Default is "en" (English). | Optional |
| source | The two-letter ISO language code of the source language. Default is "autodetect". | Optional |
Context Output
| Path | Type | Description |
|---|---|---|
| GoogleCloudTranslate.TranslateText.ID | String | The ID of the request. |
| GoogleCloudTranslate.TranslateText.detected_language_code | String | The detected two-letter ISO language code of the source language. Null, if no source argument is defined. |
| GoogleCloudTranslate.TranslateText.source_language_code | String | The source language as specified in the source argument. Null, if no source argument is defined. |
| GoogleCloudTranslate.TranslateText.target_language_code | String | The two letter ISO language code to which the text was translated. |
| GoogleCloudTranslate.TranslateText.text | String | The source (original) text that was translated. |
| GoogleCloudTranslate.TranslateText.translated_text | String | The translated text. |
Command Example
!gct-translate-text text="ciao" target="iw"
Context Example
{
"GoogleCloudTranslate.TranslateText": {
"ID": <ID>,
"detected_language_code": "it",
"source_language_code": null,
"target_language_code": "iw",
"text": "ciao",
"translated_text": "\u05e9\u05dc\u05d5\u05dd"
}
}
Human Readable Output
Translation: שלום Source Language Detected: it
</p>
Additional Information
Known Limitations
The following features are not supported yet:
- AutoML models
- Glossaries
- Labels
- Batch requests
- Multple target language codes
</ul>
Troubleshooting
Configuration parameters
service_account_json— Service Account Private Key file contents (JSON)project_creds— Project in Google Cloud Translateproject— Project in Google Cloud Translateproxy— Use system proxy settingsinsecure— Trust any certificate (not secure)
Commands (2)
-
gct-supported-languagesReturns the list of supported two-letter ISO language codes.
-
gct-translate-textReturns the translated text.
from GoogleCloudTranslate import supported_languages, translate_text # noqa MOCK_GET_SUPPORTED_LANGUAGES = [ {"language_code": "aa", "support_source": True, "support_target": False}, {"language_code": "bb", "support_source": False, "support_target": True}, ] MOCK_TRANSLATE_TEXT = {"translated_text": "foo", "detected_language_code": "aa"} class MockClient: def get_supported_languages(self): return MOCK_GET_SUPPORTED_LANGUAGES def translate_text(self, text, target, source=None): if source is None: return MOCK_TRANSLATE_TEXT result = MOCK_TRANSLATE_TEXT.copy() result.update({"detected_language_code": None}) return result def test_supported_languages(mocker): mclient = MockClient() readable, outputs, result = supported_languages(mclient) assert isinstance(readable, str) assert outputs == {"GoogleCloudTranslate": {"SupportedLanguages": MOCK_GET_SUPPORTED_LANGUAGES}} assert result == MOCK_GET_SUPPORTED_LANGUAGES def test_translate_text_1(mocker): mclient = MockClient() readable, outputs, result = translate_text(mclient, {"text": "bar"}) mock_result = { "ID": "95040f0a44fd692842831b107dfa9d92", "text": "bar", "translated_text": "foo", "source_language_code": None, "detected_language_code": "aa", "target_language_code": "en", } assert isinstance(readable, str) assert outputs == {"GoogleCloudTranslate.TranslateText(val.ID && val.ID==obj.ID)": mock_result} assert result == MOCK_TRANSLATE_TEXT def test_translate_text_2(mocker): mclient = MockClient() readable, outputs, result = translate_text(mclient, {"text": "bar", "target": "it"}) mock_result = { "ID": "2bda6ec4740ec87b49e90dbe6587fd14", "text": "bar", "translated_text": "foo", "source_language_code": None, "detected_language_code": "aa", "target_language_code": "it", } assert isinstance(readable, str) assert outputs == {"GoogleCloudTranslate.TranslateText(val.ID && val.ID==obj.ID)": mock_result} assert result == MOCK_TRANSLATE_TEXT def test_translate_text_3(mocker): mclient = MockClient() readable, outputs, result = translate_text(mclient, {"text": "bar", "target": "it", "source": "hr"}) mock_result = { "ID": "d2124c37f6b3c436a3f18a7920227a22", "text": "bar", "translated_text": "foo", "source_language_code": "hr", "detected_language_code": None, "target_language_code": "it", } assert isinstance(readable, str) assert outputs == {"GoogleCloudTranslate.TranslateText(val.ID && val.ID==obj.ID)": mock_result} assert result == {"translated_text": "foo", "detected_language_code": None}