Google Docs Editor add-on quickstart
This quickstart creates a Google Docs Editor add-on that translates
selected text in a document.
Objectives
- Set up the script.
- Run the script.
Prerequisites
To use this sample, you need the following prerequisites:
- A Google Account (Google Workspace accounts might
require administrator approval).
- A web browser with access to the internet.
Set up the script
- Create a Google Docs document at docs.new.
- Click Extensions > Apps Script.
- Click Untitled project.
- Rename the Apps Script project Translate Docs and click Rename.
- Next to the
Code.gs
file, click More more_vert
> Rename. Name the file translate
.
- Click Add a file add
> HTML. Name the file
sidebar
.
Replace the contents of each file with the following corresponding code, then
click Save
.
Run the script
- In your Docs document, reload the page.
- Click Extensions >
Translate Docs
> Start.
- When prompted, authorize the add-on.
Upon authorization, the add-on will restart.
- Type some text into your document and select it.
- In the add-on, click Translate. To replace the
text in the document, click Insert.
Next steps
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-02-13 UTC.
[null,null,["Last updated 2025-02-13 UTC."],[[["This quickstart guide demonstrates how to build a Google Docs add-on using Apps Script that translates selected text within a document."],["The add-on allows users to select text, choose source and target languages, and obtain the translation, with an option to insert the translated text directly into the document."],["Users need a Google Account and a web browser to utilize this add-on, which involves setting up a script, running it, and authorizing permissions."],["The add-on provides a user interface within a sidebar in Google Docs for easy interaction and language selection."],["Further resources are available for extending Google Docs functionality with Apps Script and exploring the Document service for more advanced customizations."]]],[]]