Juy
Juy

Reputation: 25

how to make this translation function code by google apps-script?

I really want to add a translation menu on my google sheet but I definitely don't know what should I do at the last part.

function onOpen(e) {
SpreadsheetApp.getUi()
  .createMenu('Translation')
  .addItem('ko to eng', 'myFunction')
  .addToUi();
}
 var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getActiveRange();
 var trans = LanguageApp.translate(sheet,'ko','en');

that is it for now. I want to make 'myFuncton' that can spread var 'trans' at the same place in the sheet. how can I code this?

Upvotes: 1

Views: 621

Answers (1)

Muhammet Yunus
Muhammet Yunus

Reputation: 589

If you'd like to print the translation e.g. on cells to the right of the selected cells, you can use this function:

function myFunction () {
  var range = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getActiveRange();
  var trans = range.getValues().map(row => [LanguageApp.translate (row,'ko','en')])
 
  range.offset(0,1).setValues(trans)
}

Upvotes: 1

Related Questions