Describe the problem/error/question
Hello,
this is my workflow. I try to translate the data with DeepL. DeepL does translate it, but the output format should stay the same as in imput format. What must I do to keep the data in the same format?
Greetings Max
What is the error message (if any)?
Please share your workflow
Share the output returned by the last node
Information on your n8n setup
- n8n version:
- Database (default: SQLite):
- n8n EXECUTIONS_PROCESS setting (default: own, main):
- Running n8n via (Docker, npm, n8n cloud, desktop app):
- Operating system:
Hey @hair2heart you need to translate only the words inside your data, not the structure itself.
Right now, you’re feeding the whole structure to DeepL instead use a code node to first pull out all the words that need translating. Then after DeepL translates them, use another code node to put those translated words back into the exact same structure.
This way, the labels and format stay the same, and only the text gets translated. Hope this helps
Hello @Bringasher , thank you for your reply. Can you give me a hint which node to use to pull out only the words and then put them back into the original structure?
@hair2heart you will use the function node.
I am struggling with the java script in the function node that pulls out the data that needs to be translated and then puts the words back into the same structur as it was before
This node will extract all text values that need translation from your JSON object
const originalData = $input.all()[0].json;
const items = [];
items.push({
json: {
originalData: originalData,
textToTranslate: originalData.text
},
pairedItem: $input.all()[0].pairedItem
});
return items;
Next configure your DeepL node to translate the extracted text
This node puts the translated text back into the original structure
const translatedText = $input.all()[0].json.text;
const originalData = $input.all()[0].json.originalData;
const reconstructedData = {
...originalData,
text: translatedText
};
return [{
json: reconstructedData,
pairedItem: $input.all()[0].pairedItem
}];
Let me know what you think
Its not working yet as it should.
This is my flow now. I am not sure what I must input into the field “Text” in the DeepL node. I also tried it with “data” but there was no output when I did that.
@hair2heart your DeepL node should be looking for {{ $json.textToTranslate }}
Your DeepL node is configured to look for text at this path {{ $json.originalData.data[0].Keywords }}
After the translate node, if you attach a function(requires javascript) OR an AI model and instruction in his system prompt to d extract the text from the json … there are plenty ways to do that, with coding exp or without…