DEV Community

Cover image for Chrome Extension Localization: A Practical i18n Walkthrough
ExtensionBooster
ExtensionBooster

Posted on Originally published at extensionbooster.net

Chrome Extension Localization: A Practical i18n Walkthrough

Originally published on ExtensionBooster.

Chrome extension localization is mostly a file-structure problem, not a translation problem: get the structure right once and adding a language later is just adding a file. Here is how the built-in i18n system works, how to use it from every part of your extension, and the habits that keep translations from breaking.

Why bother with multiple languages

Chrome's user base is spread across many languages. The original guide ranks top locales by share of Chrome users, led by English, Simplified Chinese and Spanish, and suggests starting with the top five languages instead of translating everything at once.

The file structure

The idea is simple: your code never contains display text, only message keys. Each language lives in its own folder, so adding Spanish or Arabic later means adding a folder rather than touching your logic.

Every locale gets its own folder under _locales, each with a messages.json. The manifest names the fallback language with default_locale.

my-extension/
  manifest.json
  _locales/
    en/messages.json
    es/messages.json
    ar/messages.json
Enter fullscreen mode Exit fullscreen mode
{
  "default_locale": "en",
  "name": "__MSG_extName__",
  "description": "__MSG_extDescription__"
}
Enter fullscreen mode Exit fullscreen mode

Anatomy of a message

Each entry in messages.json has a message string. Two optional fields are worth using from day one:

  • description: context for translators, so "Save" is not guessed wrong
  • placeholders: named slots for variable values
{
  "welcomeUser": {
    "message": "Welcome, $NAME$!",
    "description": "Greeting shown after sign-in",
    "placeholders": {
      "name": { "content": "$1", "example": "Ana" }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

This is why the description field matters: translators see your intent, not just the English string. Named placeholders can be combined in one message, and they can hold static content such as a brand name. To print a literal dollar sign, write $$.

Using messages everywhere

Where How
JavaScript chrome.i18n.getMessage("welcomeUser", ["Ana"])
manifest.json __MSG_extName__
CSS __MSG_name__ references
HTML a data-i18n attribute that a small script fills in

The HTML case needs a few lines of your own code:

document.querySelectorAll("[data-i18n]").forEach((el) => {
  el.textContent = chrome.i18n.getMessage(el.dataset.i18n);
});
Enter fullscreen mode Exit fullscreen mode

Predefined messages and right-to-left languages

You do not need to detect the language yourself to get text direction and fonts right, because Chrome exposes them as ready-made messages.

Chrome ships built-ins such as @@ui_locale, @@bidi_dir and @@font_family. For right-to-left languages like Arabic and Hebrew, use the direction built-ins in CSS and set the dir attribute from JavaScript so layouts mirror correctly.

Best practices

Most localization bugs come from a handful of shortcuts. Avoiding these five keeps translations accurate and layouts intact:

  1. Write a description for every message.
  2. Prefer named placeholders over positional guesses.
  3. Never build sentences by concatenating translated strings; word order differs between languages.
  4. Test layouts with long text, since translations are often longer than English.
  5. Hardcode no user-facing strings anywhere.

For dynamic content that is not in your message files, the original guide points to Chrome's on-device Translator and Language Detection APIs.

Treat these as a checklist you run before every release: scan for hardcoded strings, switch your browser to a long-text language and look for clipped buttons, and open an RTL language to confirm the layout mirrors.

Key takeaways

  • One messages.json per locale under _locales, plus default_locale in the manifest.
  • Use chrome.i18n.getMessage() in scripts and __MSG_name__ in the manifest and CSS.
  • Add translator descriptions and named placeholders from the start.
  • Handle RTL with the predefined direction messages.
  • Start with your top five languages, then expand.

Want the full walkthrough? Read the complete Chrome extension localization i18n guide, and see how ExtensionBooster helps extension developers grow their listings.

Which language did you localize your extension into first, and did it move your install numbers?

Top comments (0)