How to: Translate Cells in Google Spreadsheets from English to Spanish (maybe!)

Chip Oglesby bio photo By Chip Oglesby

I should start by saying that I don’t speak Spanish and I certainly cannot translate it, but I thought it would be a fun exercise to see if I could programmatically translate cells in Google Spreadsheets from English to Spanish. This script uses Google Translate to automatically translate sentences after they’re typed into a spreadsheet. It could be helpful for writing Spanish ads for Google Adwords.

function onEdit(e) {
var sheet = SpreadsheetApp.getActiveSheet();
var name = sheet.getName();
var cell = sheet.getActiveCell();
var value = cell.getValue();
if (typeof value == 'string') {
var spanish = LanguageApp.translate(value, 'en', 'es');
cell.setValue(spanish);
}
}
view raw Translate.js hosted with ❤ by GitHub

I’ve read a few articles on how reliable the translations are. Is anyone familiar with how accurate the translations are? If you’re proficient with English & Spanish and care to take a look, let me know your thoughts on if this actually works.