{ "kind": "open-flow-workflow", "version": 1, "name": "Google Text Translator", "content": { "modelVersion": 14, "document": { "bindings": {}, "graph": { "nodes": { "n_1380e80d7afb54df": { "name": "Enter text and target language", "kind": "start", "inputDefs": [ { "jsonSchema": { "type": "string", "minLength": 1 }, "nullable": false, "handle": "text" }, { "jsonSchema": { "type": "string", "minLength": 1 }, "nullable": false, "handle": "target" } ] }, "n_94ec3df8264264e4": { "inputs": { "text": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_1380e80d7afb54df", "output": "text" } ] }, "target": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_1380e80d7afb54df", "output": "target" } ] } }, "name": "Prepare single translation", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string", "minLength": 1 }, "nullable": false, "handle": "text" }, { "jsonSchema": { "type": "string", "minLength": 1 }, "nullable": false, "handle": "target" } ], "outputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "body" } ], "name": "Prepare single translation", "moduleId": "n_6d14a8470c57ee65", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_6b4f1ab867107159": { "inputs": { "url": { "kind": "value", "value": "https://translation.googleapis.com/language/translate/v2" }, "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_94ec3df8264264e4", "output": "body" } ] }, "header.x-goog-user-project": { "kind": "value", "value": "YOUR_GOOGLE_CLOUD_PROJECT_ID" }, "auth.token": { "kind": "unset" } }, "name": "Translate with Google NMT", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": { "type": "string" }, "nullable": true, "handle": "header.x-goog-user-project" }, { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "auth.token" } ], "outputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": { "type": "object", "additionalProperties": { "type": "string" } }, "nullable": false, "handle": "headers" } ], "name": "Translate with Google NMT", "executor": { "method": "POST", "query": { "mode": "fields", "names": [] }, "headers": { "mode": "fields", "names": [ "x-goog-user-project" ] }, "bodyFormat": "json", "authentication": { "type": "bearer" }, "responseFormat": "json", "statusPolicy": "success", "kind": "http-request" } } }, "n_0a0795c6e1207fda": { "inputs": { "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_6b4f1ab867107159", "output": "body" } ] } }, "name": "Read translated text", "kind": "task", "task": { "inputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" } ], "outputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "translation" } ], "name": "Read translated text", "moduleId": "n_f1a599b500d9f151", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_48eb2b3a87ddd2fc": { "name": "Google translation result", "kind": "outputs", "outputDefs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "translation" } ], "outputMappings": { "translation": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_0a0795c6e1207fda", "output": "translation" } ] } } } }, "edges": [ { "source": "n_1380e80d7afb54df", "target": "n_94ec3df8264264e4" }, { "source": "n_94ec3df8264264e4", "target": "n_6b4f1ab867107159" }, { "source": "n_6b4f1ab867107159", "target": "n_0a0795c6e1207fda" }, { "source": "n_0a0795c6e1207fda", "target": "n_48eb2b3a87ddd2fc" } ] } }, "modules": { "n_6d14a8470c57ee65": { "name": "Prepare single translation", "imports": [], "source": "function prepareTranslation(text, target) {\n if (typeof text !== 'string' || !text.length || typeof target !== 'string' || !target.trim() || target.trim() !== target) {\n throw new Error('Enter text and a target language code');\n }\n return { q: text, target };\n}\nexport default async function translateRequest({ text, target }) {\n return { body: prepareTranslation(text, target) };\n}\n" }, "n_f1a599b500d9f151": { "name": "Read translated text", "imports": [], "source": "function readTranslation(body) {\n const translations = body && typeof body === 'object' && body.data && body.data.translations;\n if (!Array.isArray(translations) || translations.length !== 1) throw new Error('Google did not return one translation');\n const translation = translations[0];\n if (!translation || typeof translation !== 'object' || Array.isArray(translation) || typeof translation.translatedText !== 'string') {\n throw new Error('Google did not return translated text');\n }\n return translation;\n}\nexport default async function translateResult({ body }) {\n return { translation: readTranslation(body) };\n}\n" } } }, "presentation": { "designer": { "version": 1, "flow": { "direction": "vertical" } } } }