Docs / Translate / Extension messages.json
Translate extension messages.json files
Translate _locales/en/messages.json for Chrome, Edge and Firefox extensions into every language, with $PLACEHOLDER$ tokens kept and descriptions used as context.
How it works
localize-dev translate reads _locales/en/messages.json, sends each message’s description with it as context, and writes _locales/es/messages.json, _locales/pt_BR/messages.json and so on, with the underscore locale names extensions use.
Named $COUNT$ and positional $1 tokens are kept, and each message’s placeholders block is copied into every language, because each language’s file declares its own.
Before and after
Real output of localize-dev translate --locales es on the first file. The extension name stays as written, and the placeholders block comes along with the translated message.
{
"extName": { "message": "Tab Tidy", "description": "Extension name in the Chrome Web Store" },
"popupTitle": { "message": "Tidy your tabs" },
"closedTabs": {
"message": "Closed $COUNT$ tabs in $WINDOW$",
"description": "Shown after the user tidies a window",
"placeholders": {
"count": { "content": "$1", "example": "12" },
"window": { "content": "$2", "example": "Work" }
}
}
}{
"extName": {
"message": "Tab Tidy"
},
"popupTitle": {
"message": "Organiza tus pestañas"
},
"closedTabs": {
"message": "Cerradas $COUNT$ pestañas en $WINDOW$",
"placeholders": {
"count": {
"content": "$1",
"example": "12"
},
"window": {
"content": "$2",
"example": "Work"
}
}
}
}What stays intact
$NAME$and$1tokens, checked- The
placeholdersblock of every message that has one - Underscore locale folders (
pt_BR,zh_CN) - The source file’s indentation
Common mistakes, and how they’re avoided
Translations without their placeholders
$COUNT$ is filled in from the placeholders declared in the same language’s file. Without them the browser can’t fill it in, so the block is copied with every translation.
Hyphenated locale folders
Extensions use pt_BR, not pt-BR, for folder names. New languages are created with the spelling extensions expect.
Store listings
The name and description in messages.json are what the Chrome Web Store shows in each language. Give them a description so brand names stay as written and the summary fits the store.
Run it
In the folder that holds your locale files. Languages without a file yet get one. --dry-run shows what would change first.
npx localize-dev login
# Preview, then write the missing translations
npx localize-dev translate --dry-run -l es,fr,de
npx localize-dev translate -l es,fr,deThen keep it complete in CI. This needs no API key and fails when a language is missing translations:
npx localize-dev check --only translationsFree for 1,000 strings a month. A string counts once however many languages it goes into. Create a free account