Prendre contact
Grand rue 29,
CP 116,
[email protected]
Tél : +41 21 561 28 48
Retour

Hack du jour : traduire directement dans une feuille de calcul Google à l'aide de l'API Deepl Pro

When did you last feel you found a secret weapon to boost your productivity? For me, it was this week when I discovered you could call the Deepl Pro API inside a Google Spreadsheet.

Switzerland is not your typical country as we handle a lot of languages in our day to day. Switching from English to French is already a challenge; we know that for French people. You add Italian and German and are on for a substantial loss of productivity.

Now, here is a simple tutorial on how I made it:

Setup

  1. In your Google Sheet, from the “Extensions” menu, select “Apps Script” to open the Apps Script editor.
  2. Create a script file named DeepL.gs and copy the contents of the DeepL.gs file in this repo into it.
  3. Modify line 26 of the script to include your DeepL Authentication Key. This line looks like const authKey = "..";, and it comes after the license text.
  4. Close the Apps Script editor and return to your sheet.

Setup tutorial

This guide walks you through the setup using a new, blank Google Sheet. But you can also use the add-on with an existing Sheet (including if that Sheet already has App Scripts). In the case of a sheet that already has App Scripts, you’d need to add a new Apps Script file (e.g., “DeepL.gs”) and add the code provided below.

Create a new Google Sheet. In the top toolbar, click “Extensions” then “Apps Script”.

Extensions menu -> App Script button

A new Apps Script tab will open. It should look something like this:

Apps Script tab

Delete the function myFunction()… placeholder code so that this “Code.gs” section on the Apps Script tab is empty.

Deleting the placeholder code

Replace the “Code.gs” section in the Apps Script tab with the contents of the “DeepL.gs” file in this git repository. Click here to get the raw contents from GitHub, and copy and paste the contents into the Apps Script tab.

Go to deepl.com and sign in to your DeepL API account

If you don’t yet have a DeepL API account, create one here.

Login to DeepL API account

Go to the Account tab in your API account

DeepL Account tab

Scroll down to find your authentication key.

Copy your authentication key.

Copy your authentication key

Go back to the Apps Script tab. Paste your DeepL API authentication key in between the quotation marks (” “) on line 26 of the Code.gs file.

Line 26 of the Code.gs file should look something like this:

const authKey = "ab7be987-af47-8776-815f-0fad93fe87b8:fx"; // Replace with your authentication key

Rename your Apps Script project

Click on the “Untitled project” title and give the project a new name. You can use any name you like.

Rename the Apps Script project

Click on the “Save” icon in the Apps Script toolbar

Save the Apps Script project

You can now close the Apps Script tab and navigate back to the Sheet you created at the start of setup. Let’s get translating!

Usage

The example includes two functions: DeepLTranslate and DeepLUsage.

Each function has “pop-up” documentation you’ll see when you start typing it into a cell in your sheet.

Popup documentation for DeepLTranslate function
Popup documentation for DeepLUsage function

Note that you cannot create glossaries using this Google Sheets add-on. You can only reference glossary IDs of glossaries that were already created with the DeepL API.

In addition, here are some examples that might help you get started.

=DeepLTranslate("Bonjour!")
    “Hello!” (or equivalent in your system language)

DeepLTranslate("Guten Tag", "auto", "FR")
    “Bonjour”

=DeepLTranslate("Hello", "en", "de", "61a74456-b47c-48a2-8271-bbfd5e8152af")
    “Moin” (translating using a glossary)

=DeepLUsage()
    “106691 of 500000 characters used.”

=DeepLUsage("count")
    106691

Usage Tutorial

Type some sample source text into cells A1 and A2.

I’ll use the following sentences:

  • “The weather sure is nice today.”
  • “I wonder if it’s supposed to rain later this week.”
Example sentences for using DeepL plugin

In cell B1, type =DeepLTranslate( to start using the DeepL function we created.

Typing in the DeepLTranslate formula

We’ll use the following parameters:

  • input: A1 (cell A1—but you can also type in your own text)
  • source_lang: “auto” (DeepL will auto-detect the source language)
  • target_lang: “DE” (German—or feel free to select a 2-letter language code of your choice from the target_lang section on this page)
  • glossary_id: We’ll skip this parameter, as we aren’t using a glossary in this example.

The resulting function call will look like this:

=DeepLTranslate(A1, "auto", "DE")

Press enter to run the function.

Success! Cell A1 was translated into German.

Translating the first cell

To translate our second cell of source text, you can copy cell B1 and paste it into B2.

Translating the second cell

Congrats! You’ve reached the end of this tutorial. Happy translating!

Haider Alleg
Haider Alleg
https://haideralleg.com/
Entrepreneur Haider developed a toolbox for bringing brand performances to life, helping organisations of various shapes and sizes navigate the unknown and generate growth. This led him to build Kainjoo in 2012, a fast-growing consulting firm supporting ambitious leaders from top 500 Fortune companies. With Allegory Capital, he supports regulated industries to innovate through portfolios of emerging tech and channels.

Leave a Reply

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

S'inscrire à ma lettre d'information

Événement TechEx

NextPharma Dubrovnik 2020

EyeforPharma Tokyo 2020

Événement TechEx 2022