Created
November 24, 2016 01:59
-
-
Save bennettscience/03dddfc306e57a453b02d9d1eb409d7b to your computer and use it in GitHub Desktop.
Link two documents for translation updates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ui = DocumentApp.getUi(); | |
var docProps = PropertiesService.getDocumentProperties(); | |
// Grab the document body. | |
// No formatting, tables, etc are kept. | |
function getText() { | |
var doc = DocumentApp.getActiveDocument(); | |
var body = doc.getBody(); | |
Logger.log(body.getText()); | |
var array = []; | |
array.push(body.getText()); | |
sendTheText(array); | |
} | |
// Check for a Doc ID to push to. If none, ask for it. | |
// Push the doc and translate to Spanish. | |
function sendTheText(e) { | |
if (docProps.getProperty("childId") == "") { | |
var prompt = ui.prompt("Child doc ID", ui.ButtonSet.OK); | |
var response = prompt.getResponseText() | |
docProps.setProperty("childId", response); | |
Logger.log(response); | |
} | |
var childDoc = DocumentApp.openById(docProps.getProperty("childId")); | |
var es = LanguageApp.translate(e, 'en', 'es'); | |
childDoc.getBody().clear(); | |
childDoc.getBody().appendParagraph(es); | |
} | |
// Reset the doc you're pushing updates to | |
function clearProps() { | |
docProps.setProperty("childId", ""); | |
} | |
function onOpen() { | |
ui.createMenu("Custom Translate").addItem("Run", "getText").addItem("Clear IDs","clearProps").addToUi(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment