appscript.dev
Automation Intermediate Slides

Auto-translate a deck into another language

Localise all text boxes in a Northwind deck in place — German, Spanish, or any LanguageApp target.

Published Aug 17, 2025

When Northwind pitches to a client abroad, the deck has to be in their language — and the slow way is to copy each slide, paste every line into a translation tool, and paste the result back, box by box, for forty slides. It takes an afternoon and it is easy to miss a stray text box.

This script does the whole pass in seconds. Point it at a deck, give it a source and target language, and it walks every shape on every slide, translating the text in place with Google’s built-in LanguageApp. It is best run on a copy of the deck, so you keep the original and get a localised version alongside it.

What you’ll need

  • The ID of the Slides deck to translate — copy the original first if you want to keep an English version.
  • A source and target language as two-letter codes: en, de, es, fr, ja, and so on.
  • Edit access to the deck from the account running the script.

The script

/**
 * Translates every non-empty text box in a deck in place.
 *
 * @param {string} deckId The ID of the Slides deck to translate.
 * @param {string} sourceLang Two-letter source language code, e.g. 'en'.
 * @param {string} targetLang Two-letter target language code, e.g. 'de'.
 */
function translateDeck(deckId, sourceLang, targetLang) {
  const deck = SlidesApp.openById(deckId);
  const slides = deck.getSlides();
  if (!slides.length) {
    Logger.log('Deck has no slides — nothing to translate.');
    return;
  }

  let boxes = 0;

  // 1. Walk every slide in the deck.
  for (const slide of slides) {
    // 2. Walk every shape on the slide.
    for (const shape of slide.getShapes()) {
      const textRange = shape.getText();
      const text = textRange.asString();

      // 3. Skip shapes with no text (images, lines, empty boxes).
      if (!text.trim()) continue;

      // 4. Translate the text and write it straight back into the shape.
      textRange.setText(
        LanguageApp.translate(text, sourceLang, targetLang)
      );
      boxes++;
    }
  }

  Logger.log('Translated ' + boxes + ' text box(es) into ' + targetLang + '.');
}

/**
 * Convenience wrapper: translates a fixed deck from English to German.
 * Edit the IDs and codes, or call translateDeck directly.
 */
function translateNorthwindDeck() {
  translateDeck('1abcDeckId', 'en', 'de');
}

How it works

  1. translateDeck opens the deck by ID and gets its slides. A short guard stops the run if the deck is empty.
  2. It loops over every slide, then over every shape on that slide — titles, body placeholders, free-floating text boxes, the lot.
  3. For each shape it reads the text as a string and skips anything blank, so images, lines and empty boxes are passed over without an API call.
  4. It calls LanguageApp.translate with the source and target codes and writes the result straight back into the same text range with setText — the translation lands exactly where the original text was.
  5. translateNorthwindDeck is a thin wrapper so you can run the job from the editor without passing arguments; edit its IDs and language codes to suit.

Example run

Run translateDeck('1abcDeckId', 'en', 'de') on a deck whose title slide reads:

Northwind Studio Brand strategy and design

After the run the same slide, same layout, reads:

Northwind Studio Markenstrategie und Design

Every text box across every slide is converted in one pass — the proper noun “Northwind Studio” is left effectively unchanged, the descriptive line is in German.

Run it

This is an on-demand job — you translate a deck when you need it:

  1. Make a copy of the deck so the English original is preserved.
  2. Put the copy’s ID into translateNorthwindDeck (or call translateDeck directly) and set the language codes.
  3. In the Apps Script editor, select the function and click Run.
  4. Approve the authorisation prompt the first time, then open the deck to check the result.

Watch out for

  • setText replaces the whole text range, so mixed formatting inside a box — one bold word, a coloured phrase — is flattened to the box’s default style. To keep inline styling, walk each text element and translate its runs individually instead.
  • It always runs on the deck you give it. Translate a copy, or the English original is overwritten with no undo beyond Slides’ version history.
  • LanguageApp is machine translation. It is fine for internal drafts and quick turnarounds, but a client-facing pitch deserves a native-speaker review before it goes out.
  • Tables, charts and SmartArt-style grouped shapes may not expose their text via getShapes() at the top level. Text inside grouped shapes needs the group unpacked first; chart and table text may not be reached at all.
  • A large deck means many translation calls. LanguageApp is subject to daily quotas — a single deck is well within them, but translating dozens in a loop is not.

Related