AI-generated Key Takeaways
- 
          
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.
 
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.gsfile, click More > Rename. Name the filetranslate. - Click Add a file 
> HTML. Name the file 
sidebar. Replace the contents of each file with the following corresponding code, then click Save
.
translate.gs
sidebar.html
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.