Reputation: 25
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
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