Skip to content

Instantly share code, notes, and snippets.

@m3tam3re
Created February 28, 2025 08:12
Show Gist options
  • Save m3tam3re/a9d906739975694b78dde1981c999550 to your computer and use it in GitHub Desktop.
Save m3tam3re/a9d906739975694b78dde1981c999550 to your computer and use it in GitHub Desktop.
n8n - AI translation workflow
{
"nodes": [
{
"parameters": {},
"type": "n8n-nodes-base.executeWorkflowTrigger",
"typeVersion": 1,
"position": [
-1280,
80
],
"id": "81bab7a4-8852-44a9-95d9-82a9c446c1ef",
"name": "Execute Workflow Trigger"
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "a4d8cbb2-79da-4537-971d-f7014bfcc061",
"name": "response",
"value": "SUCCESS",
"type": "string"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
1400,
-100
],
"id": "41581840-8230-4181-868d-47b6481622fa",
"name": "Response to AGENT"
},
{
"parameters": {
"fieldToSplitOut": "target_languages",
"include": "selectedOtherFields",
"fieldsToInclude": "video_id,query.source_language, query.original_title, query.original_description",
"options": {}
},
"type": "n8n-nodes-base.splitOut",
"typeVersion": 1,
"position": [
-940,
80
],
"id": "f280ae10-841e-4ae5-bf78-c75ee8373084",
"name": "Split Out"
},
{
"parameters": {
"promptType": "define",
"text": "=Translate this JSON Object from the source_language **{{ $json.source_language }}** into the target_language **{{ $json.target_language }}\n\n# Rules\n1. PRESERVE the original structure of the JSON object\n2. PRESERVE original formatting, structure, and whitespace of the field contents EXACTLY\n3. Apply CASUAL FORM using this decision flow:\n a. If language has formal/casual speech:\n - Use informal pronouns (tu/du/ты/etc)\n - Use plain verb forms (not -ます/-습니다/-요)\n - Avoid honorifics (-san/-nim/-sama)\n b. If language has T-V distinction → use T-form\n c. If no formal/casual forms → proceed normally\n4. Apply to ALL languages with grammatical formality systems including:\n Japanese, Korean, German, French, Spanish, Italian, Russian, Dutch, Portuguese, Swedish\n5. NEVER use these formal markers:\n - Polite verb conjugations\n - Honorific titles\n - Formal pronouns\n7. ONLY the translated JSON object as a valid JSON string.\n\nHere is the JSON object:\n\n{{ $json.input.toJsonString() }}"
},
"type": "@n8n/n8n-nodes-langchain.chainLlm",
"typeVersion": 1.4,
"position": [
-360,
-240
],
"id": "fd89abf3-2b6a-4e3b-b7a4-3284ba445acd",
"name": "Basic LLM Chain"
},
{
"parameters": {
"model": "qwen2.5:32b",
"options": {}
},
"type": "@n8n/n8n-nodes-langchain.lmOllama",
"typeVersion": 1,
"position": [
-360,
-80
],
"id": "073b3e00-3aba-4efb-b8e3-20fbf3b39fba",
"name": "Ollama Model",
"credentials": {
"ollamaApi": {
"id": "fXPH8vvuisTz43yf",
"name": "Ollama account"
}
}
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "17e732d8-bdc9-4872-9bfb-b28022212344",
"name": "=input.localizations.{{ $json.target_languages }}.title",
"value": "={{ $json['query.original_title'] }}",
"type": "string"
},
{
"id": "4578b55b-cdba-4d6c-ac62-f1f442b71fe1",
"name": "=input.localizations.{{ $json.target_languages }}.description",
"value": "={{ $json['query.original_description'] }}",
"type": "string"
},
{
"id": "9657e06d-d7b9-4555-8ef8-e51d9b2f5e9d",
"name": "source_language",
"value": "={{ $json['query.source_language'] }}",
"type": "string"
},
{
"id": "55574ebd-cca1-4d48-b89d-42c0a4758e5e",
"name": "target_language",
"value": "={{ $json.target_languages }}",
"type": "string"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
-600,
-240
],
"id": "48e17cb5-b86a-4a6b-8863-10f424207f47",
"name": "Set LLM inputs"
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "b2304d93-7c5c-4513-8f52-35310658607e",
"name": "=localizations.{{ $json.text.parseJson().localizations.keys()[0] }}.title",
"value": "={{ $json.text.parseJson().localizations.values()[0]['title'] }}",
"type": "string"
},
{
"id": "0a4b34f0-5fef-49cb-8080-3cfd8b01959a",
"name": "=localizations.{{ $json.text.parseJson().localizations.keys()[0] }}.description",
"value": "={{ $json.text.parseJson().localizations.values()[0]['description'] }}",
"type": "string"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
0,
-240
],
"id": "513b8d06-b03c-4ead-8063-32dda68dda92",
"name": "Parse LLM Response"
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "29731e78-39b5-4f5d-8a49-114ea834eee7",
"name": "video_id",
"value": "={{ $json.video_id }}",
"type": "string"
},
{
"id": "43e3a45e-ab2c-41be-93ba-4e09bd275a5c",
"name": "original_title",
"value": "={{ $json['query.original_title'] }}",
"type": "string"
},
{
"id": "ee088e5e-c088-442a-8ada-f39ba84b9179",
"name": "original_description",
"value": "={{ $json['query.original_description'] }}",
"type": "string"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
0,
80
],
"id": "3617bb1e-3230-4687-9af3-7a67fab791c7",
"name": "Set Video Data"
},
{
"parameters": {
"mode": "combine",
"combineBy": "combineByPosition",
"options": {}
},
"type": "n8n-nodes-base.merge",
"typeVersion": 3,
"position": [
560,
-100
],
"id": "76699f0d-e32a-44ff-9e5f-3e30c5519fd7",
"name": "Merge"
},
{
"parameters": {
"jsCode": "let merged_item = [{\n \"json\": {\n \"video_id\": $input.first().json.video_id,\n \"snippet\": {\n \"title\": $input.first().json.original_title,\n \"description\": $input.first().json.original_description,\n \"defaultLanguage\": \"EN\",\n \"categoryId\": \"27\"\n },\n \"localizations\": {}\n }\n}];\n\nfor (const item of $input.all()) {\n for (const lang in item.json.localizations) {\n merged_item[0].json.localizations[lang] = item.json.localizations[lang];\n }\n}\n\nreturn merged_item;"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
820,
-100
],
"id": "561ddf42-8bda-4e80-9bb5-d9710e7228c1",
"name": "Create JSON for Output"
},
{
"parameters": {
"fieldToSplitOut": "=target_languages",
"include": "selectedOtherFields",
"fieldsToInclude": "video_id,query.source_language, query.original_title, query.original_description",
"options": {
"disableDotNotation": false
}
},
"type": "n8n-nodes-base.splitOut",
"typeVersion": 1,
"position": [
-900,
-800
],
"id": "df6b0a1b-7f8d-4190-8cfb-91df6deacae2",
"name": "Split Out1"
},
{
"parameters": {
"method": "PUT",
"url": "https://youtube.googleapis.com/youtube/v3/videos",
"authentication": "predefinedCredentialType",
"nodeCredentialType": "youTubeOAuth2Api",
"sendQuery": true,
"queryParameters": {
"parameters": [
{
"name": "part",
"value": "localizations"
}
]
},
"sendBody": true,
"bodyParameters": {
"parameters": [
{
"name": "id",
"value": "={{ $json.video_id }}"
},
{
"name": "localizations",
"value": "={{ $json.localizations }}"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
1140,
-820
],
"id": "9352a095-2dfb-49df-b788-002763d83284",
"name": "Update Video Data on Youtube1",
"credentials": {
"youTubeOAuth2Api": {
"id": "X0o3QIy3RGOEkwKY",
"name": "YouTube PROD"
}
}
},
{
"parameters": {
"mode": "combine",
"combineBy": "combineByPosition",
"options": {}
},
"type": "n8n-nodes-base.merge",
"typeVersion": 3,
"position": [
520,
-820
],
"id": "c62242f2-2bb3-420a-9dab-82eeff600776",
"name": "Merge1"
},
{
"parameters": {
"promptType": "define",
"text": "=Translate this TEXT into from the source_language **{{ $json['query.source_language'] }}** into the target_language **{{ $json.target_languages }}**\n\n# Rules\n1. PRESERVE the original structure of the JSON object\n2. PRESERVE original formatting, structure, and whitespace of the field contents EXACTLY\n3. Apply CASUAL FORM using this decision flow:\n a. If language has formal/casual speech:\n - Use informal pronouns (tu/du/ты/etc)\n - Use plain verb forms (not -ます/-습니다/-요)\n - Avoid honorifics (-san/-nim/-sama)\n b. If language has T-V distinction → use T-form\n c. If no formal/casual forms → proceed normally\n5. Apply to ALL languages with grammatical formality systems including:\n Japanese, Korean, German, French, Spanish, Italian, Russian, Dutch, Portuguese, Swedish\n6. NEVER use these formal markers:\n - Polite verb conjugations\n - Honorific titles\n - Formal pronouns\n\n# OUTPUT\nOutput in the following format:\n{ \"{{ $json.target_languages }}\": \"TRANSLATED_TEXT\" }\n\nHere is the TEXT:\n{{ $json['query.original_title'] }}"
},
"type": "@n8n/n8n-nodes-langchain.chainLlm",
"typeVersion": 1.4,
"position": [
-340,
-1140
],
"id": "d6bd0c46-c05c-4581-892f-6c201962e71d",
"name": "Basic LLM Chain1",
"retryOnFail": true
},
{
"parameters": {
"model": "qwen2.5:32b",
"options": {}
},
"type": "@n8n/n8n-nodes-langchain.lmOllama",
"typeVersion": 1,
"position": [
-340,
-980
],
"id": "56f8ec8c-a3a9-482f-8a16-8b2eb1730924",
"name": "Ollama Model1",
"credentials": {
"ollamaApi": {
"id": "fXPH8vvuisTz43yf",
"name": "Ollama account"
}
}
},
{
"parameters": {
"promptType": "define",
"text": "=Translate this TEXT into from the source_language **{{ $json['query.source_language'] }}** into the target_language **{{ $json.target_languages }}**\n\n# Rules\n1. PRESERVE the original structure of the JSON object\n2. PRESERVE original formatting, structure, and whitespace of the field contents EXACTLY\n3. Apply CASUAL FORM using this decision flow:\n a. If language has formal/casual speech:\n - Use informal pronouns (tu/du/ты/etc)\n - Use plain verb forms (not -ます/-습니다/-요)\n - Avoid honorifics (-san/-nim/-sama)\n b. If language has T-V distinction → use T-form\n c. If no formal/casual forms → proceed normally\n5. Apply to ALL languages with grammatical formality systems including:\n Japanese, Korean, German, French, Spanish, Italian, Russian, Dutch, Portuguese, Swedish\n6. NEVER use these formal markers:\n - Polite verb conjugations\n - Honorific titles\n - Formal pronouns\n\n# OUTPUT\nOutput in the following format:\n{ \"{{ $json.target_languages }}\": \"TRANSLATED_TEXT\" }\n\nHere is the TEXT:\n{{ $json['query.original_description'] }}"
},
"type": "@n8n/n8n-nodes-langchain.chainLlm",
"typeVersion": 1.4,
"position": [
-340,
-1440
],
"id": "5c055a21-952a-4ba5-a888-8ee8a53e3c78",
"name": "Basic LLM Chain2",
"retryOnFail": true
},
{
"parameters": {
"model": "qwen2.5:32b",
"options": {}
},
"type": "@n8n/n8n-nodes-langchain.lmOllama",
"typeVersion": 1,
"position": [
-340,
-1280
],
"id": "20395975-ab36-4fc6-99f0-c9e091411743",
"name": "Ollama Model2",
"credentials": {
"ollamaApi": {
"id": "fXPH8vvuisTz43yf",
"name": "Ollama account"
}
}
},
{
"parameters": {
"mode": "combine",
"combineBy": "combineByPosition",
"options": {}
},
"type": "n8n-nodes-base.merge",
"typeVersion": 3,
"position": [
280,
-1300
],
"id": "f1312f62-179d-4bb3-923c-594162e1a592",
"name": "Merge2"
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "97874a76-6f05-40bb-bbfb-15a1546ab1d8",
"name": "=localizations.{{ $json.text.parseJson().keys()[0] }}.description",
"value": "={{ $json.text.parseJson().values()[0] }}",
"type": "string"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
20,
-1440
],
"id": "479783ee-50e7-4b14-9242-d9e7221ad13f",
"name": "Parse Description"
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "97874a76-6f05-40bb-bbfb-15a1546ab1d8",
"name": "=localizations.{{ $json.text.parseJson().keys()[0] }}.title",
"value": "={{ $json.text.parseJson().values()[0] }}",
"type": "string"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
20,
-1140
],
"id": "87258337-1842-454c-a07f-2cf91ba3dc19",
"name": "Parse Title"
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "76829613-8b95-478c-a7c1-7db28f244987",
"name": "video_id",
"value": "={{ $json['video_id'] }}",
"type": "string"
},
{
"id": "32ff148d-8ce6-466d-a574-94212bf044a2",
"name": "original_title",
"value": "={{ $json['query.original_title'] }}",
"type": "string"
},
{
"id": "6d00ce50-db51-4b0d-b55d-e23e16f37314",
"name": "original_description",
"value": "={{ $json['query.original_description'] }}",
"type": "string"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
20,
-800
],
"id": "b5ed194f-b45f-4d66-9a6e-91d33be6a2df",
"name": "Set Video Data1"
},
{
"parameters": {
"jsCode": "let merged_item = [{\n \"json\": {\n \"video_id\": $input.first().json.video_id,\n \"snippet\": {\n \"title\": $input.first().json.original_title,\n \"description\": $input.first().json.original_description,\n \"defaultLanguage\": \"EN\",\n \"categoryId\": \"27\"\n },\n \"localizations\": {}\n }\n}];\n\nfor (const item of $input.all()) {\n for (const lang in item.json.localizations) {\n merged_item[0].json.localizations[lang] = item.json.localizations[lang];\n console.log(\"lang\");\n }\n}\n\nreturn merged_item;"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
820,
-820
],
"id": "0a6a13b6-191c-4269-961d-afe164f6f9a9",
"name": "Create JSON for Output1",
"alwaysOutputData": false
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "dc48ce87-b21e-44a3-bd51-c8ef5038ea4e",
"name": "response",
"value": "SUCCESS",
"type": "string"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
1400,
-820
],
"id": "17f45f49-890f-4587-a095-b20d9f913440",
"name": "Respond to Agent1"
},
{
"parameters": {
"method": "PUT",
"url": "https://youtube.googleapis.com/youtube/v3/videos",
"authentication": "predefinedCredentialType",
"nodeCredentialType": "youTubeOAuth2Api",
"sendQuery": true,
"queryParameters": {
"parameters": [
{
"name": "part",
"value": "localizations,snippet"
}
]
},
"sendBody": true,
"bodyParameters": {
"parameters": [
{
"name": "id",
"value": "={{ $json.video_id }}"
},
{
"name": "localizations",
"value": "={{ $json.localizations }}"
},
{
"name": "snippet",
"value": "={{ $json.snippet }}"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
1140,
-100
],
"id": "0e0b375e-3193-45cb-bc40-4691fec9137c",
"name": "Update Video Data on Youtube",
"credentials": {
"youTubeOAuth2Api": {
"id": "X0o3QIy3RGOEkwKY",
"name": "YouTube PROD"
}
}
}
],
"connections": {
"Execute Workflow Trigger": {
"main": [
[
{
"node": "Split Out",
"type": "main",
"index": 0
}
]
]
},
"Split Out": {
"main": [
[
{
"node": "Set LLM inputs",
"type": "main",
"index": 0
},
{
"node": "Set Video Data",
"type": "main",
"index": 0
}
]
]
},
"Basic LLM Chain": {
"main": [
[
{
"node": "Parse LLM Response",
"type": "main",
"index": 0
}
]
]
},
"Ollama Model": {
"ai_languageModel": [
[
{
"node": "Basic LLM Chain",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Set LLM inputs": {
"main": [
[
{
"node": "Basic LLM Chain",
"type": "main",
"index": 0
}
]
]
},
"Parse LLM Response": {
"main": [
[
{
"node": "Merge",
"type": "main",
"index": 0
}
]
]
},
"Set Video Data": {
"main": [
[
{
"node": "Merge",
"type": "main",
"index": 1
}
]
]
},
"Merge": {
"main": [
[
{
"node": "Create JSON for Output",
"type": "main",
"index": 0
}
]
]
},
"Create JSON for Output": {
"main": [
[
{
"node": "Update Video Data on Youtube",
"type": "main",
"index": 0
}
]
]
},
"Split Out1": {
"main": [
[
{
"node": "Set Video Data1",
"type": "main",
"index": 0
},
{
"node": "Basic LLM Chain2",
"type": "main",
"index": 0
},
{
"node": "Basic LLM Chain1",
"type": "main",
"index": 0
}
]
]
},
"Update Video Data on Youtube1": {
"main": [
[
{
"node": "Respond to Agent1",
"type": "main",
"index": 0
}
]
]
},
"Merge1": {
"main": [
[
{
"node": "Create JSON for Output1",
"type": "main",
"index": 0
}
]
]
},
"Basic LLM Chain1": {
"main": [
[
{
"node": "Parse Title",
"type": "main",
"index": 0
}
]
]
},
"Ollama Model1": {
"ai_languageModel": [
[
{
"node": "Basic LLM Chain1",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Basic LLM Chain2": {
"main": [
[
{
"node": "Parse Description",
"type": "main",
"index": 0
}
]
]
},
"Ollama Model2": {
"ai_languageModel": [
[
{
"node": "Basic LLM Chain2",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Merge2": {
"main": [
[
{
"node": "Merge1",
"type": "main",
"index": 0
}
]
]
},
"Parse Description": {
"main": [
[
{
"node": "Merge2",
"type": "main",
"index": 0
}
]
]
},
"Parse Title": {
"main": [
[
{
"node": "Merge2",
"type": "main",
"index": 1
}
]
]
},
"Set Video Data1": {
"main": [
[
{
"node": "Merge1",
"type": "main",
"index": 1
}
]
]
},
"Create JSON for Output1": {
"main": [
[
{
"node": "Update Video Data on Youtube1",
"type": "main",
"index": 0
}
]
]
},
"Update Video Data on Youtube": {
"main": [
[
{
"node": "Response to AGENT",
"type": "main",
"index": 0
}
]
]
}
},
"pinData": {
"Execute Workflow Trigger": [
{
"query": {
"original_title": "Your title here",
"original_description": "Your description here",
"source_language": "en"
},
"video_id": "your_video_id",
"target_languages": [
"de",
"fr",
"es"
]
}
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment