我有一种语言的谷歌文档,需要翻译。
我知道有"Tools > Translate“选项,但这意味着每次更改时我都必须手动翻译它。
翻译后的文档是否与原始文档同步,这样每次我对原始文档进行更改时,翻译后的文档也会进行适当的更改吗?
在电子表格中有GOOGLETRANSLATE函数
我想通过一个应用程序脚本命令LanguageApp.translate是可能的
但我不知道如何从原始文档中导入这些内容
编辑
目前,我在目标文档上设置了这个脚本。
function translate() {
var original = DocumentApp.openById('Oringinal document id');
var translated = LanguageApp.translate(original, 'zh', 'en');
Logger.log(translated);
return translated;
}我不知道它是否翻译了,或者什么,日志只显示了文档,我不知道如何获得变量的内容,我也不知道如何将变量打印到新文档中。
在触发器中我只看到时间驱动的触发器?我应该在原始文档上设置脚本吗?
发布于 2016-11-24 17:37:05
这只是概念的证明。该脚本工作,但不会保持格式或图像。记住,Google没有onEdit触发器。您可以创建自定义的时间触发器,但是如果文档没有更新,它将继续在后台运行,这可能是可取的,也可能是不可取的。
// Grab the document body. No formatting, tables, etc are kept.
function getText() {
var sourceDoc = DocumentApp.openById('idHere');
var sourceBody = sourceDoc.getBody();
// Push the body to an array for translating in the destination
var array = [];
array.push(sourceBody.getText());
translateText(array);
}
// Take the array and translate to Spanish.
function translateText(e) {
// Translate the array
var es = LanguageApp.translate(e, 'en', 'es');
// Open the doc to hold the translation
var childDoc = DocumentApp.getActiveDocument();
// Clear out any previously-held text and then append the updated text from source.
childDoc.getBody().clear();
childDoc.getBody().appendParagraph(es);
}这很粗糙,但是如果将它添加到您的子文档并从脚本编辑器中运行,它就会工作。还可以从源重构它,并将其推送到子文档中。它还可以设置一个变量来保存文档的原始ID,这样您就不必用PropertiesService硬编码它了。只是一些改进的想法。不要忘记,这只会抓取正文文本,没有任何格式。
https://stackoverflow.com/questions/40767646
复制相似问题