Translate OneDrive Documents with DeepL and Power Automate

Presentation of final flow

Prerequisites

  • A DeepL API account. A free tier is available.
  • Access to your Microsoft Power Automate default environment. We are creating an Instant Cloud Flow. Instant Cloud Flows are executed on demand by a user. In our case the user should be able to execute a translation flow after selecting a document in OneDrive. A user will only see that option if the flow is created in the default environment and not in a development environment.
  • Custom connectors are a premium feature of Microsoft Power Automate, so you need at least a Microsoft Power User plan license.
  • Some files to translate in OneDrive for Business

Custom Connectors in Power Automate

  • Import an OpenAPI or Postman Collection — If you already have a definition file for the API you can simply import that. For OpenAPI you need an OpenAPI Version 2.0 definition file.
  • Import from GitHub — Microsoft hosts a GitHub Repository which contains all standard and custom connectors available. You can import directly from there.
  • Build from scratch — You can use the visual editor to define API actions and triggers. This is done by importing sample request and response JSON and the editor automatically extracts the schema definition from that samples.

Create a custom connector

  • Download the API definition file above to your local drive
  • Go to your Power Automate environment. Make sure that your default environment is selected.
  • In the left menu open the Data menu and select Custom Connectors.
  • In the top bar click on New custom connector a select Import an OpenAPI file and enter a name for the connector.
Import an OpenAPI file
  • In the General tab you can optionally add an Icon and a background color for that icon.
  • In the top bar click on Create connector. Your imported connector is now saved and can be used in your flows.

Add a connection

  • In the left menu under Data select Connections.
  • Click on New connection and select the DeepL API connector from the list (use the top right search input to find it).
  • Paste your API Key to the form and click Create.

Create the Power Automate Flow — Upload to DeepL

  • Automatic — The flow starts when in an application or service something happens.
  • Instant — The flow starts when a user manually initiates the flow. This is what we are doing.
  • Scheduled — The flow starts periodically
  • In the left menu click on My flows and then in the top menu click on New flow and select Instant cloud flow.
  • Give your flow a meaningful name (e.g., DeepL Translate) and select the For a selected file — OneDrive for Business trigger. Then click Create.
Build an instant cloud flow
  • In the editor canvas on the For a selected file trigger click on Add an input and select Text.
  • Click on the ellipses menu and select Add a dropdown-list of options.
Dropdown Options
  • Add all supported target languages as options to the list (or at least all languages you want to support)
Input options complete
  • Add a new step below and select the Get file metadata using path — OneDrive for Business action.
  • In the File Path input select the filePath result from the For a selected file trigger.
Get file metadata using path
  • Add a new step below and select Get file content using path — OneDrive for Business action.
  • In the File Path input select the filePath result from the For a selected file trigger.
Get file metadata using path
  • Add a new step below and select Upload Document — DeepL API action. You will find your custom connector in the Custom connectors tab.
  • For Target Language select custom and then select the Language variable from For a selected file trigger (that is the input variable we defined)
  • For Document File Data select the File content variable from Get file content using path action.
  • For Document File Data (file name) select the Name variable from Get file metadata using path action.
Upload Document

Create the Power Automate Flow — Check Status

  • Add a new step after Upload document and select the Initialize variable — Variable action.
  • Set the Name to IsProcessing, the Type to boolean and Value to true. We use the variable as a criteria for the next step.
Initialize IsProcessing variable
  • Add a new step and select Do Until — Control action.
  • As criteria set IsProcessing is equal to false. This means that the Do Until loop exists when IsProcessing is set to false.
Do until critera
  • Inside the Do until add a new action and select the Delay — Schedule action. Set the delay Count to 30 and the Unit to second. During the first iteration of the Do Until look we first wait 30 seconds, before we check the translation status.
  • Right after the delay action add another action and select Document Status — Deepl API action.
  • For Document ID select the Document ID variable from the Upload Document action. For Document Key the Document Key variable from Upload Document action.
Document Status action
  • After Document Status add another action and select Condition — Control action.
  • In the first row select the Status variable from Document Status action and set the condition to is equal to done.
  • Add another row and select the Status variable from Document Status action and set the condition to is equal to error.
  • Set the row condition to OR.
Finished translation condition
  • In the If yes branch of the condition add a Set variable — Variable action.
  • Choose IsProcessing and set its value to false.
Set IsProcessing variable to false on done or error status.
Final DoUntil loop

Create the Power Automate Flow — Retrieve Translation

  • Below the DoUntil add another step and select the Condition — Control action.
  • Select the Status variable from the Document Status action and set the condition to is equal to done.
Final status condition
  • In the If yes branch add an action and select Download Document — Deepl API action.
  • Set Document ID to Document ID from the Upload Document action
  • Set Document Key to Document Key from the Upload Document action
Download document
  • Right after the Download Document action add another action and select Send an email (V2) — Office 365 Outlook. (Of course you can select any other email action).
  • Set To to User email from the For a selected file action.
  • Set Subject to Display name from the Get file metadata using path action. (you may include some additional text here)
  • In the body add some text. You can again use variables from your flow to make it more meaningful or personal.
  • Under Advanced Options set the Attachment Name to Name of the Get file metadata using path action.
  • Set Attachments content to Translated Document from the Download Document action.
Send email with translated document
  • In the If no branch add an action and select Send me an email notification — Notifications action.
  • Set some text for the Subject and the Body.

Use the Flow

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Stefan Weber

Stefan Weber

Head of Citizen Development & Low Code Practice at ISD FENIQS.