GAS vs. AI2 Translation Comparison App
In this tutorial, we will create a translation app that integrates Google Apps Script (GAS) with App Inventor.
This app will translate English text that you input into multiple languages (Spanish, French, German, Japanese, and Chinese) using LanguageApp in GAS. Furthermore, it allows you to display the GAS translation results side-by-side with the results from App Inventor’s standard translation component, so you can compare their accuracy.
The GAS script is written using Google Gemini 2.5 Pro.
Translation via GAS is fundamentally free, but for a standard Google account (e.g., @gmail.com), the number of API calls is limited to 5,000 per day. This is more than a sufficient amount for personal use and development testing.
Setting up Google Apps Script
Generate a Google Apps Script Using Gemini 2.5 Pro
Prompt
Create a Google Apps Script web app that functions as an API to translate text from a source language to a target language.
The web app should:
Be named 'Translation API'.
Use the LanguageApp service for translation.
Handle HTTP POST requests through a doPost(e) function.
Accept three parameters:
text: The text to be translated.
source: The source language code (e.g., 'en' for English).
target: The target language code (e.g., 'es' for Spanish).
Include error handling for missing parameters. If any of the required parameters are missing, it should return a JSON error message.
Return the translated text as a JSON object with a key of 'translatedText'.
The response should be served as ContentService.MimeType.JSON.
Response
/**
* @license
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Handles HTTP POST requests to translate text.
*
* @param {Object} e The event parameter for a POST request.
* @return {GoogleAppsScript.Content.TextOutput} The translated text or an error message.
*/
function doPost(e) {
// Set the response MIME type to JSON.
const response = ContentService.createTextOutput().setMimeType(ContentService.MimeType.JSON);
let postData;
try {
postData = JSON.parse(e.postData.contents);
} catch (error) {
response.setContent(JSON.stringify({
"error": "Invalid JSON format in request body."
}));
return response;
}
// Get the parameters from the POST request.
const text = postData.text;
const source = postData.source;
const target = postData.target;
// Check for missing parameters.
if (!text || !source || !target) {
response.setContent(JSON.stringify({
"error": "Missing required parameters. Please provide 'text', 'source', and 'target'."
}));
return response;
}
try {
// Translate the text using the LanguageApp service.
const translatedText = LanguageApp.translate(text, source, target);
const result = {
"translatedText": translatedText
};
response.setContent(JSON.stringify(result));
} catch (error) {
// Handle any errors during the translation process.
response.setContent(JSON.stringify({
"error": "An error occurred during translation: " + error.message
}));
}
return response;
}
Open Google Script
Navigate to https://script.google.com/ and log in with your Google account. Click on “+ New project“.
Paste the Script
Delete all the initial code in the editor (function myFunction() { ... }
) and paste the code above.
Save the Project
Click the floppy disk icon at the top to save the project. Give it a name (e.g., “Translation API").
Deploy as a Web App
To make this script callable from App Inventor, we need to publish it to the web.
① Click the blue “Deploy" button in the upper-right corner and select “New deployment“.
② Click the gear icon ⚙ next to “Select type" and choose “Web app“.
③ Configure the settings as follows:
- Description: (Optional) e.g., Translation App API
- Execute as: Me (your Google account)
- Who has access:Anyone
- Important: If this is not set to “Anyone," App Inventor will not be able to access it and you will get an error.
④ Click “Deploy“.
New deployment is shown like this.

Since the Web App URL will be used in App Inventor, be sure to click the “Copy” button and keep a record of it.
App Inventor App
From the [Projects] menu, select [Start new project] and name it “TranslateBenchmark“.