LANG SELRCT

Apps Script Reference  (Create: Create new Spreadsheet | Create new Apps Script

Friday, January 31, 2020

LanguageApp.translateで英文中の単語ごとに翻訳したい


Practice makes the impossible possible



練習 作ります その 不可能な 可能


のように単語ごとに翻訳したい。

半角スペースをsplitしてfor文で作ってもいいけれど
LanguageApp.translateを実行する回数が多くなる。

半角スペースではなく\nで区切ってやると一気に翻訳できた。



コード.gs
function myFunction() {
  var str = "Practice\nmakes\nthe\nimpossible\npossible";
  var translate = LanguageApp.translate(str, "en", "ja");
  Logger.log(translate);
}


実行結果

練習
作ります
その
不可能な
可能

Latest post

Creating a template copier app in Google Apps Script

Introduction This article will show you a template copier application in Google Apps Script.  This application will automatically copy a t...