How to Translate a Google Sheets Column With an AI Custom Function
Create a =TRANSLATEAI() function in Google Sheets that uses an AI model to translate any cell into a target language.
Translating a column of product names or support replies one by one is tedious. This guide builds a =TRANSLATEAI() custom function that sends each cell to an AI model and returns the translation, so you can translate a whole column by dragging one formula.
- A Google Sheet with text to translate
- An OpenAI API key
- Access to the sheet's Apps Script editor
- About 7 minutes
Step 1: Open Apps Script and add the function
From the sheet choose Extensions then Apps Script. Paste the function below. It takes the text and a target language code so the same formula handles any language.
const OPENAI_KEY = "sk-PASTE_YOUR_KEY";
function TRANSLATEAI(text, lang) {
if (!text) return "";
const res = UrlFetchApp.fetch("https://api.openai.com/v1/chat/completions", {
method: "post",
contentType: "application/json",
headers: { Authorization: "Bearer " + OPENAI_KEY },
payload: JSON.stringify({
model: "gpt-5-mini",
messages: [
{ role: "system", content: "Translate the text to " + lang + ". Return only the translation." },
{ role: "user", content: text },
],
}),
});
return JSON.parse(res.getContentText()).choices[0].message.content.trim();
}Step 2: Save and return to the sheet
Click Save in the editor, then switch back to your spreadsheet tab. The new function is available immediately as if it were built in.
Step 3: Use the formula with a language argument
In an empty cell type the formula referencing your source cell and a language. The first run asks you to authorize external requests; approve it once.
=TRANSLATEAI(A2, "French")Step 4: Fill the column
Grab the small square at the bottom right of the cell and drag it down to translate the rest of the column. Each row fires its own call, so give large columns a moment to finish.
Result: a reusable translation function lives in your sheet. Change the second argument to Spanish, German, or any language and the same formula adapts instantly.
Watch related tutorials
5:42
24:16
33:42
41:18
28:05
3:12