You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Gmail Add-on本地化方案咨询:多语言适配及发布相关疑问

Localizing Your Gmail Add-on for 3 Languages

Got it, let's break down how to localize your Gmail Add-on for 3 languages—this is totally doable, even if the initial publishing docs don't spell it out super clearly. I've walked through this a few times for clients, so here's a straightforward, actionable guide:

1. Set Up Your Localization File Structure

First, create a _locales folder at the root of your Apps Script project (use the new editor for easiest setup: click "Add file" > "New folder", name it _locales). Inside this folder, make subfolders for each of your target languages using standard ISO 639-1 codes—like en (English), es (Spanish), fr (French).

In each language subfolder, add a messages.json file. This file stores key-value pairs for every translatable string in your add-on. For example:

  • In _locales/en/messages.json:
    {
      "addon_title": {
        "message": "My Gmail Organizer",
        "description": "Title of the add-on shown in the Gmail sidebar"
      },
      "button_archive": {
        "message": "Archive Selected",
        "description": "Label for the archive button"
      }
    }
    
  • For other languages, keep the exact same keys and descriptions, just replace the message values with your translations.

2. Reference Translations in Your Code

Server-Side Apps Script Code

Use the CardService.getText() method to pull translated strings directly into your UI components. Example:

function buildSidebar() {
  const addonTitle = CardService.newTextParagraph().setText(CardService.getText("addon_title"));
  const archiveBtn = CardService.newTextButton()
    .setText(CardService.getText("button_archive"))
    .setOnClickAction(CardService.newAction().setFunctionName("handleArchive"));
  // Build the rest of your card UI and return it
}

HTML Sidebars (If Used)

If your add-on uses HTML-based UI, embed translations directly with templated HTML:

<!DOCTYPE html>
<html>
  <body>
    <h1><?!= CardService.getText("addon_title") ?></h1>
    <button id="archiveBtn"><?!= CardService.getText("button_archive") ?></button>
    <!-- Rest of your HTML -->
  </body>
</html>

3. Update Your Manifest File

Edit your appsscript.json manifest to declare supported locales and tie your add-on's metadata to translated strings. Add a locale section, and use the __MSG_key__ syntax for fields like the add-on name:

{
  "timeZone": "America/New_York",
  "runtimeVersion": "V8",
  "addOns": {
    "gmail": {
      "name": "__MSG_addon_title__",
      "logoUrl": "https://your-logo-url.com/logo.png",
      // Your contextual triggers and universal actions go here
    }
  },
  "locale": {
    "default": "en",
    "supported": ["en", "es", "fr"]
  }
}

4. Test Before Publishing

  • User-side test: Switch your Gmail language (Settings > General > Language) to one of your target languages, reload Gmail, and open the add-on to verify translations load correctly.
  • Pro tip: In the Apps Script editor, use "Run" > "Set test locale" to preview translations without changing your actual Gmail language.

5. Publishing Notes

When you submit to the Google Workspace Marketplace, you don't need separate language builds—Google automatically serves the correct translation based on the user's Gmail language setting. Just make sure all your _locales files are included in your deployment package.


内容的提问来源于stack exchange,提问作者Jakub Michálek

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 09:42:42