{
  "name": "Redokun: translate a file (starter)",
  "nodes": [
    {
      "parameters": {
        "formTitle": "Translate a file with Redokun",
        "formDescription": "Upload a document and choose its languages. Redokun translates it with your Translation Memory and AI, then gives you the translated file. This usually takes a minute or two.<br><br>Language codes look like <b>en</b>, <b>it</b>, <b>de</b>, <b>fr-FR</b> or <b>pt-BR</b>.",
        "formFields": {
          "values": [
            {
              "fieldLabel": "File to translate",
              "fieldType": "file",
              "fieldName": "file",
              "multipleFiles": false,
              "acceptFileTypes": ".idml,.docx,.pptx,.xlsx,.html,.srt,.txt,.xml,.json,.xliff,.xlf,.pdf",
              "requiredField": true
            },
            {
              "fieldLabel": "Source language code",
              "fieldName": "sourceLanguage",
              "placeholder": "en",
              "requiredField": true
            },
            {
              "fieldLabel": "Target language code",
              "fieldName": "targetLanguage",
              "placeholder": "it",
              "requiredField": true
            }
          ]
        },
        "options": {
          "appendAttribution": false,
          "buttonLabel": "Translate"
        }
      },
      "id": "b07d8c11-e8bb-4ab8-b238-14c91ad1470c",
      "name": "Translation form",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.6,
      "position": [
        0,
        400
      ],
      "webhookId": "c07b3a85-2359-48bf-ba2b-ead0eb63279e"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "2ddcd78d-7b29-4321-b44b-b2a0d2d63314",
              "name": "sourceLanguage",
              "value": "={{ String($json.sourceLanguage || $json['Source language code'] || '').trim() }}",
              "type": "string"
            },
            {
              "id": "33ce2bb2-da7d-4fa7-8e0d-3b74d0c5b3fc",
              "name": "targetLanguage",
              "value": "={{ String($json.targetLanguage || $json['Target language code'] || '').trim() }}",
              "type": "string"
            },
            {
              "id": "0196f0a2-454a-4627-87b5-c154bb72fb26",
              "name": "mtVendor",
              "value": "DEEPL",
              "type": "string"
            },
            {
              "id": "c3997489-8e6a-4109-80c4-a6bd9528f836",
              "name": "confirmDrafts",
              "value": "true",
              "type": "string"
            },
            {
              "id": "d899b32a-ad55-4d06-b1ba-febba88e0f95",
              "name": "pollSecondsIndexing",
              "value": 5,
              "type": "number"
            },
            {
              "id": "317bce6e-7d75-409d-bb92-31d5a3ef840f",
              "name": "pollSecondsJobs",
              "value": 10,
              "type": "number"
            },
            {
              "id": "581eaee0-73cf-4a66-b87d-f6b83f78c2f8",
              "name": "startedAt",
              "value": "={{ $now.toISO() }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {
          "stripBinary": false
        }
      },
      "id": "a8bad625-1bcb-444f-ad01-6a2f7bef9715",
      "name": "Config",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        208,
        400
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.redokun.com/v1/documents",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "parameterType": "formBinaryData",
              "name": "file",
              "inputDataFieldName": "={{ Object.keys($binary)[0] }}"
            },
            {
              "name": "sourceLanguage",
              "value": "={{ $('Config').first().json.sourceLanguage }}"
            },
            {
              "name": "targetLanguages",
              "value": "={{ JSON.stringify([{ code: $('Config').first().json.targetLanguage }]) }}"
            }
          ]
        },
        "options": {}
      },
      "id": "46847447-faab-4dc3-b527-b94db9ebe998",
      "name": "Upload document",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        608,
        400
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "0fd65767-7b71-447f-b56e-ba18b9fcf28b",
              "leftValue": "={{ $json.status }}",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "rightValue": "UPLOADED"
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "5600c300-c1c9-4c37-82d9-24ce2d347619",
      "name": "Upload OK?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        1008,
        400
      ]
    },
    {
      "parameters": {
        "amount": "={{ $('Config').first().json.pollSecondsIndexing }}"
      },
      "id": "f12e5f3d-a278-4988-93c7-682c565f9ef7",
      "name": "Wait indexing",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        1200,
        400
      ],
      "webhookId": "919d42d8-d2f9-4546-888b-b0de5843d759"
    },
    {
      "parameters": {
        "errorMessage": "={{ 'Unexpected upload response: ' + JSON.stringify($json) }}"
      },
      "id": "915534d3-41e5-4c0a-b448-ae2fa5e9371b",
      "name": "Fail: upload",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        1200,
        608
      ]
    },
    {
      "parameters": {
        "url": "={{ $('Upload document').first().json.links.find(l => l.rel === 'self').href }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "options": {}
      },
      "id": "3bb14041-7ccc-4bd1-bac9-b7a2447550be",
      "name": "Get document",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1408,
        400
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "f8bdb38e-beef-45ce-abdc-d1b5ec0985c4",
              "leftValue": "={{ $json.status }}",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "rightValue": "INDEXED"
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "4e52b6b5-b0b3-4429-a6ce-01f57e7ac2ac",
      "name": "Indexed?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        1600,
        400
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "7da3f61e-a009-4ad1-813d-e24eb020ec08",
              "name": "phase",
              "value": "indexing",
              "type": "string"
            },
            {
              "id": "5f138aec-2646-4e97-9694-76f3b1e987f4",
              "name": "documentId",
              "value": "={{ $json.id }}",
              "type": "number"
            },
            {
              "id": "1fb6de3f-c970-4cd2-b070-4913c3001511",
              "name": "status",
              "value": "={{ $json.status }}",
              "type": "string"
            },
            {
              "id": "050eafc4-1ace-4177-91b2-3fcf1b5c3c7d",
              "name": "wordCount",
              "value": "={{ $json.wordCount }}",
              "type": "number"
            },
            {
              "id": "d9faab97-cfc4-4c0f-9d83-df05f8a1fba2",
              "name": "elapsedSeconds",
              "value": "={{ Math.round(($now.toMillis() - DateTime.fromISO($('Config').first().json.startedAt).toMillis()) / 1000) }}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "id": "e01dd03a-33b6-4788-87f5-6673fd044fde",
      "name": "Log indexing",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1808,
        304
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "0652f4d6-8a62-487b-9a27-62cc2eeda71b",
              "leftValue": "={{ $json.status }}",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "rightValue": "INDEXING_ERROR"
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "52b9f059-1eae-49ed-9b87-50d00bff7c8a",
      "name": "Indexing error?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        1808,
        608
      ]
    },
    {
      "parameters": {
        "errorMessage": "={{ 'Indexing failed: ' + $json.indexingError }}"
      },
      "id": "11f4c88c-d4cc-42b0-87e0-a4b05a1ba9c3",
      "name": "Fail: indexing",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        2000,
        528
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "81ddacc8-a065-4324-8893-60dc41399c64",
              "leftValue": "={{ $runIndex }}",
              "operator": {
                "type": "number",
                "operation": "lt"
              },
              "rightValue": 24
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "80601725-5546-4f86-bdd9-64fe4245f354",
      "name": "Retries left (indexing)?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        2000,
        720
      ]
    },
    {
      "parameters": {
        "errorMessage": "={{ 'Timeout: document still ' + $json.status + ' after polling' }}"
      },
      "id": "cfe14a03-0513-4b1d-95cb-ae321630f31f",
      "name": "Fail: indexing timeout",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        2208,
        832
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ ($('Get document').last().json.links.find(l => l.rel === 'translations') || {}).href || ($('Get document').last().json.links.find(l => l.rel === 'self').href + '/translations') }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ languages: [{ code: $('Config').first().json.targetLanguage, translationMemory: true, machineTranslation: true, machineTranslationVendor: $('Config').first().json.mtVendor }] }) }}",
        "options": {}
      },
      "id": "be48f37a-447e-426d-8803-9ac17eca9d48",
      "name": "Launch pre-translation",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        2000,
        304
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "cc37d734-1428-40dd-b20b-37f22f3ccec5",
              "leftValue": "={{ $json.translations.some(t => t.status === 'PRE_TRANSLATING') }}",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "rightValue": ""
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "6f2cce4a-0c40-4c02-bcd2-95141efc8a8b",
      "name": "Pre-translation started?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        2208,
        304
      ]
    },
    {
      "parameters": {
        "amount": "={{ $('Config').first().json.pollSecondsJobs }}"
      },
      "id": "39ed5c0c-ab94-4cf2-86a5-225ca3776853",
      "name": "Wait pre-translation",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        2400,
        304
      ],
      "webhookId": "9335b0c3-5665-48f9-9101-525b62454e5d"
    },
    {
      "parameters": {
        "errorMessage": "={{ 'Pre-translation not started: ' + JSON.stringify($json.translations.map(t => t.language.code + '=' + t.status)) }}"
      },
      "id": "e0532eba-7def-4088-8fb4-4f84a0e3b2d1",
      "name": "Fail: pre-translation start",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        2400,
        512
      ]
    },
    {
      "parameters": {
        "url": "={{ $('Launch pre-translation').first().json.links.find(l => l.rel === 'self').href }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "options": {}
      },
      "id": "317078a0-aa3e-4572-ba96-d95da242c2dd",
      "name": "Get translations",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        2608,
        304
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "f78ed86b-d1ca-4cfb-91f3-0dee6c8b0fe6",
              "leftValue": "={{ $json.translations.length > 0 && $json.translations.every(t => t.status === 'CREATED') }}",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "rightValue": ""
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "d0acb6e5-6503-43f5-b33f-07bf6aebf77d",
      "name": "Pre-translation done?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        2800,
        304
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "ae8819bb-4bff-4c68-b561-6b0946528a81",
              "name": "phase",
              "value": "pre-translation",
              "type": "string"
            },
            {
              "id": "7fb50834-10b7-4aa1-9bee-bb6a3c348dc9",
              "name": "language",
              "value": "={{ $json.translations[0].language.code }}",
              "type": "string"
            },
            {
              "id": "69e44810-da75-4b1c-8d34-21785e61978c",
              "name": "status",
              "value": "={{ $json.translations[0].status }}",
              "type": "string"
            },
            {
              "id": "79511675-a835-4b3c-82be-6d9d7504f097",
              "name": "completedPercentage",
              "value": "={{ $json.translations[0].progress.completedPercentage }}",
              "type": "number"
            },
            {
              "id": "e72fa8d0-6be2-404e-96bd-03236102c8bb",
              "name": "translatedSegments",
              "value": "={{ $json.translations[0].progress.translatedSegments }}",
              "type": "number"
            },
            {
              "id": "4600e516-94fe-444e-8345-ef74a38d1e0d",
              "name": "draftSegments",
              "value": "={{ $json.translations[0].progress.draftSegments }}",
              "type": "number"
            },
            {
              "id": "de15f390-1dbb-4aac-a46e-fbd8f87dc0d1",
              "name": "confirmedSegments",
              "value": "={{ $json.translations[0].progress.confirmedSegments }}",
              "type": "number"
            },
            {
              "id": "51ebd70a-816e-4088-ae4d-b9373e54ab61",
              "name": "elapsedSeconds",
              "value": "={{ Math.round(($now.toMillis() - DateTime.fromISO($('Config').first().json.startedAt).toMillis()) / 1000) }}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "id": "3eacce54-6213-4779-aba5-c0475a44c53f",
      "name": "Log pre-translation",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        3008,
        208
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "8f734bd1-bc86-4309-a35c-f869b83ba7b9",
              "leftValue": "={{ $json.translations.some(t => t.status === 'PRE_TRANSLATING') }}",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "rightValue": ""
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "7535b6b2-6dba-4ea5-be98-b77e96cb002b",
      "name": "Still pre-translating?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        3008,
        512
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "a16f30ce-49a2-4954-b12e-e7d4f633b1ab",
              "leftValue": "={{ $runIndex }}",
              "operator": {
                "type": "number",
                "operation": "lt"
              },
              "rightValue": 30
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "9c085266-31a5-4e7a-9be5-49024f1b11ec",
      "name": "Retries left (pre-translation)?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        3200,
        512
      ]
    },
    {
      "parameters": {
        "errorMessage": "={{ 'Unexpected status during pre-translation: ' + JSON.stringify($json.translations.map(t => t.language.code + '=' + t.status)) }}"
      },
      "id": "b7cd6cc1-3d10-4b60-9a5a-88da445f04a7",
      "name": "Fail: pre-translation status",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        3200,
        704
      ]
    },
    {
      "parameters": {
        "errorMessage": "Timeout: pre-translation still running after polling"
      },
      "id": "793fae4d-c42f-4968-8cfb-7f6566919728",
      "name": "Fail: pre-translation timeout",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        3408,
        608
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "dbbef47f-982f-46e6-a6d5-2b4ad9d6a583",
              "leftValue": "={{ $json.completedPercentage }}",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "rightValue": 0
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "40be0b54-1d99-498c-bbd3-f2d21733037c",
      "name": "Pre-translation filled?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        3200,
        208
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ ($('Get translations').last().json.translations[0].links.find(l => l.rel === 'generate') || {}).href || ($('Get translations').last().json.translations[0].links.find(l => l.rel === 'self').href + '/generate') }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "confirm",
              "value": "true"
            },
            {
              "name": "confirmDrafts",
              "value": "={{ $('Config').first().json.confirmDrafts }}"
            }
          ]
        },
        "options": {}
      },
      "id": "66788331-8227-4050-8d2a-bdca3f98f13c",
      "name": "Confirm and generate",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        3408,
        208
      ]
    },
    {
      "parameters": {
        "errorMessage": "={{ 'Pre-translation filled nothing: ' + JSON.stringify($json) }}"
      },
      "id": "466d95fb-cb54-45e4-8c33-efd9137426d6",
      "name": "Fail: empty pre-translation",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        3408,
        352
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "5d29483a-83a2-4f04-ae48-331148465c13",
              "leftValue": "={{ $json.status }}",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "rightValue": "GENERATING"
            },
            {
              "id": "d8db1d0c-48e7-4927-8721-3bfb209e0a97",
              "leftValue": "={{ $json.status }}",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "rightValue": "GENERATED"
            }
          ],
          "combinator": "or"
        },
        "options": {}
      },
      "id": "250aea53-80cb-4c53-b037-fe31f3e7cee0",
      "name": "Generation started?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        3600,
        208
      ]
    },
    {
      "parameters": {
        "amount": "={{ $('Config').first().json.pollSecondsJobs }}"
      },
      "id": "4283003d-ab93-4d9b-b8ef-6aa844f707f7",
      "name": "Wait generation",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        3808,
        208
      ],
      "webhookId": "0ef34530-676f-4214-a4d7-d4a3573879cd"
    },
    {
      "parameters": {
        "errorMessage": "={{ 'Generation not started, status: ' + $json.status }}"
      },
      "id": "229f4ec6-ece2-470b-9733-034ee7f2a07b",
      "name": "Fail: generation start",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        3808,
        352
      ]
    },
    {
      "parameters": {
        "url": "={{ $('Confirm and generate').first().json.links.find(l => l.rel === 'self').href }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "options": {}
      },
      "id": "dac125cd-b4ee-42fa-8850-745b7255a110",
      "name": "Get translation",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        4000,
        208
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "2372be9f-c8c6-40b1-826b-3427434c5c30",
              "leftValue": "={{ $json.status }}",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "rightValue": "GENERATED"
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "0468e361-77e6-4e9d-a4d9-05246d63621a",
      "name": "Generated?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        4208,
        208
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "4bde78d9-36a0-424d-8430-e1c5f7c3d69e",
              "name": "phase",
              "value": "generation",
              "type": "string"
            },
            {
              "id": "58494f15-40a2-4f93-b5ac-51a42d7f1487",
              "name": "language",
              "value": "={{ $json.language.code }}",
              "type": "string"
            },
            {
              "id": "a82aea25-2ec5-47c1-a1bd-195a2e3bfc6d",
              "name": "status",
              "value": "={{ $json.status }}",
              "type": "string"
            },
            {
              "id": "988f9c7c-167e-4390-b547-12599eb8eece",
              "name": "elapsedSeconds",
              "value": "={{ Math.round(($now.toMillis() - DateTime.fromISO($('Config').first().json.startedAt).toMillis()) / 1000) }}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "id": "adc21a7c-d4c0-4537-b407-d04eb881324a",
      "name": "Log generation",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        4400,
        112
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "80a53b7f-95c2-4eb4-b886-824afab91817",
              "leftValue": "={{ $json.status }}",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "rightValue": "GENERATING"
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "513cdf56-cbc5-4b56-93fc-89b7b706c3f0",
      "name": "Still generating?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        4400,
        400
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "53855798-1344-4cc7-b020-90f29121ef0e",
              "leftValue": "={{ $runIndex }}",
              "operator": {
                "type": "number",
                "operation": "lt"
              },
              "rightValue": 30
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "2d1405fc-85c4-4681-bf52-94513d3713f7",
      "name": "Retries left (generation)?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        4608,
        400
      ]
    },
    {
      "parameters": {
        "errorMessage": "={{ 'Unexpected status during generation: ' + $json.status }}"
      },
      "id": "64c62894-c30f-45b2-9aad-0df0d8e33328",
      "name": "Fail: generation status",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        4608,
        608
      ]
    },
    {
      "parameters": {
        "errorMessage": "Timeout: translation still GENERATING after polling"
      },
      "id": "a61b0205-5df2-4f9c-aa55-6632d97d2569",
      "name": "Fail: generation timeout",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        4800,
        512
      ]
    },
    {
      "parameters": {
        "url": "={{ $('Confirm and generate').first().json.links.find(l => l.rel === 'download').href }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "options": {
          "response": {
            "response": {
              "fullResponse": true,
              "neverError": true
            }
          }
        }
      },
      "id": "234b8ff2-46d4-4b9e-af2f-4c69d494a6a3",
      "name": "Get download URL",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        4608,
        112
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "850325a3-2541-4393-9bd0-0000418b8654",
              "leftValue": "={{ $json.statusCode }}",
              "operator": {
                "type": "number",
                "operation": "equals"
              },
              "rightValue": 200
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "8a6957b5-b34e-4049-a2a7-244bef18d16a",
      "name": "Download URL ready?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        4800,
        112
      ]
    },
    {
      "parameters": {
        "url": "={{ $('Get download URL').last().json.body.url }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "id": "87cab26f-c0fe-427b-b0d7-023d0fb9450e",
      "name": "Download translated file",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        5008,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "bc6e2d2a-1309-4ecf-b599-8622e2c4cbc6",
              "leftValue": "={{ $json.statusCode }}",
              "operator": {
                "type": "number",
                "operation": "equals"
              },
              "rightValue": 409
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "fb22fd8e-7142-48ef-8fc5-1116f7e434b9",
      "name": "File not stored yet (409)?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        5008,
        304
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "42c7294b-a7e8-4cef-99e1-b8512e7994d1",
              "leftValue": "={{ $runIndex }}",
              "operator": {
                "type": "number",
                "operation": "lt"
              },
              "rightValue": 10
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "6776677e-5679-41b1-9b11-0f0ac30307bc",
      "name": "Retries left (download)?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        5200,
        304
      ]
    },
    {
      "parameters": {
        "errorMessage": "={{ 'Download URL request failed: HTTP ' + $json.statusCode + ' ' + JSON.stringify($json.body) }}"
      },
      "id": "25e537f6-3bc0-4897-ae46-e771f3c78e78",
      "name": "Fail: download URL",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        5200,
        512
      ]
    },
    {
      "parameters": {
        "amount": 3
      },
      "id": "98d979af-a9db-43ce-ad80-77793d8ee49c",
      "name": "Wait download",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        5408,
        224
      ],
      "webhookId": "6b967a27-bbb5-45e4-8a44-541089ff2457"
    },
    {
      "parameters": {
        "errorMessage": "Timeout: download URL still answering 409"
      },
      "id": "c6d4fe5c-3ccf-444d-acfb-d41effb62a70",
      "name": "Fail: download timeout",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        5408,
        400
      ]
    },
    {
      "parameters": {
        "operation": "completion",
        "respondWith": "returnBinary",
        "completionTitle": "Your translation is ready",
        "completionMessage": "The download of the translated file starts automatically. You can also find the document in your Redokun account.",
        "options": {}
      },
      "id": "c21d9ba4-e96a-4dee-a0ee-460a81d44088",
      "name": "Return translated file",
      "type": "n8n-nodes-base.form",
      "typeVersion": 2.5,
      "position": [
        5200,
        0
      ],
      "webhookId": "d0ae0c80-7ed7-4f92-9cfb-21516b90c615"
    }
  ],
  "connections": {
    "Translation form": {
      "main": [
        [
          {
            "node": "Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config": {
      "main": [
        [
          {
            "node": "Upload document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload document": {
      "main": [
        [
          {
            "node": "Upload OK?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload OK?": {
      "main": [
        [
          {
            "node": "Wait indexing",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Fail: upload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait indexing": {
      "main": [
        [
          {
            "node": "Get document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get document": {
      "main": [
        [
          {
            "node": "Indexed?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Indexed?": {
      "main": [
        [
          {
            "node": "Log indexing",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Indexing error?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log indexing": {
      "main": [
        [
          {
            "node": "Launch pre-translation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Indexing error?": {
      "main": [
        [
          {
            "node": "Fail: indexing",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Retries left (indexing)?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Retries left (indexing)?": {
      "main": [
        [
          {
            "node": "Wait indexing",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Fail: indexing timeout",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Launch pre-translation": {
      "main": [
        [
          {
            "node": "Pre-translation started?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pre-translation started?": {
      "main": [
        [
          {
            "node": "Wait pre-translation",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Fail: pre-translation start",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait pre-translation": {
      "main": [
        [
          {
            "node": "Get translations",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get translations": {
      "main": [
        [
          {
            "node": "Pre-translation done?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pre-translation done?": {
      "main": [
        [
          {
            "node": "Log pre-translation",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Still pre-translating?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log pre-translation": {
      "main": [
        [
          {
            "node": "Pre-translation filled?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Still pre-translating?": {
      "main": [
        [
          {
            "node": "Retries left (pre-translation)?",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Fail: pre-translation status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Retries left (pre-translation)?": {
      "main": [
        [
          {
            "node": "Wait pre-translation",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Fail: pre-translation timeout",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pre-translation filled?": {
      "main": [
        [
          {
            "node": "Confirm and generate",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Fail: empty pre-translation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Confirm and generate": {
      "main": [
        [
          {
            "node": "Generation started?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generation started?": {
      "main": [
        [
          {
            "node": "Wait generation",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Fail: generation start",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait generation": {
      "main": [
        [
          {
            "node": "Get translation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get translation": {
      "main": [
        [
          {
            "node": "Generated?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generated?": {
      "main": [
        [
          {
            "node": "Log generation",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Still generating?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log generation": {
      "main": [
        [
          {
            "node": "Get download URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Still generating?": {
      "main": [
        [
          {
            "node": "Retries left (generation)?",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Fail: generation status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Retries left (generation)?": {
      "main": [
        [
          {
            "node": "Wait generation",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Fail: generation timeout",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get download URL": {
      "main": [
        [
          {
            "node": "Download URL ready?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download URL ready?": {
      "main": [
        [
          {
            "node": "Download translated file",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "File not stored yet (409)?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download translated file": {
      "main": [
        [
          {
            "node": "Return translated file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "File not stored yet (409)?": {
      "main": [
        [
          {
            "node": "Retries left (download)?",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Fail: download URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Retries left (download)?": {
      "main": [
        [
          {
            "node": "Wait download",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Fail: download timeout",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait download": {
      "main": [
        [
          {
            "node": "Get download URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate"
  }
}
