Translate text into over 30 languages with this custom oepration, powered by DeepL.
Speaker 0: The Directus AI text translator operation allows you to provide some text and a target language, and it will be translated into the target language. This operation extension is powered by DeepL, so you will need a DeepL API key in order to get started. Now here in our directors project, we have an episodes collection, and here we have moved transcript into a translation, which means that this bass here in English is actually not in this collection. It's actually held within the episodes translations. You can read more about translations and directors inside of our documentation, but just to give you the high level understanding, we have an item.
The item relates to episodes translations, which contains, a link to the item, a link to the target language, and the specific translated fields in that language for that item, and we have a languages collection. In this case, just English and German. We're assuming that content will always be authored in English, and then you will be translating it into German. But, of course, you can build more flexible workflows using prompt confirmation dialogues or looping flows or stuff like that. So our goal will be to have a button here translate to German and the German translation will be applied by creating a new item in the episodes translations collection.
Let's create a new flow called translate to German, and this will be a manual trigger on the episodes page. So this returns the ID of the item where we click the button which is actually perfect for our use case. What we're gonna do is we we're now gonna kind of cross reference and instead of grabbing data from this item we're gonna go grab the existing English translation for this item, so we have the English base to translate. So we are gonna read the data from the episodes translations collection with the following filter. We want to make sure that the item is from this, the translation item is related to this episode item and that we are only grabbing the English.
So we will hit save. So this should return, an array with 1 item in it which contains the translation. We are then gonna send this to the AI trans the AI translation operation. Now you will need a DeepL API key. Here's one I made earlier, and select which API plan you're on.
And in here, we pass in some text. We could hard code it, but we actually want it from the previous operation. Transcript, trans script. Yeah, and we pick a target language that this operation supports. So this should return, this should return just a string not an object just a pure string of that content in German instead.
And the final thing we want to do is create a new translation. So we will create data in the episodes translations collection, and the payload will be as follows. The episode ID needs to match the initial one, the language that we've translated to, so this is the language code for German, and the string inside of transcript. So we'll hit save on all of those. So just to reiterate, we click the button on the episode.
We grab the existing English translation for that item. We translate it to German, and we create a new translation item. So let's go to our episode. Let's hit translate to German, and there is our German translation for the same content. Once again you can build really powerful workflows here by looping or maybe by allowing a specific language selection as part of a confirmation prompt dialogue.
That is how the AI, text translator operation extension works. Hope you found this interesting. We'll see you next time.