docs/plugins/development/i18n.md
Plugins can provide translations for their user-facing strings.
Create a .i18n.json file alongside your plugin with the same base name:
plugins/
my_plugin.ts
my_plugin.i18n.json
The translation file structure:
{
"en": {
"cmd.do_thing": "My Plugin: Do Thing",
"cmd.do_thing_desc": "Description of the command",
"status.ready": "My plugin ready",
"status.found": "Found %{count} items",
"prompt.search": "Search:"
},
"es": {
"cmd.do_thing": "Mi Plugin: Hacer Cosa",
"cmd.do_thing_desc": "Descripción del comando",
"status.ready": "Mi plugin listo",
"status.found": "Encontrados %{count} elementos",
"prompt.search": "Buscar:"
}
}
Key conventions:
cmd.* - Command names and descriptionsstatus.* - Status bar messagesprompt.* - Prompt labels%{variable} for interpolationUse editor.t() to translate status messages:
// Simple message
editor.setStatus(editor.t("status.ready"));
// With interpolation
editor.setStatus(editor.t("status.found", { count: String(results.length) }));
Use % prefix for command names and descriptions to enable automatic translation:
// Before (hardcoded)
editor.registerCommand(
"My Plugin: Search",
"Search through files",
"my_search"
);
// After (i18n-enabled)
editor.registerCommand(
"%cmd.search",
"%cmd.search_desc",
"my_search"
);
// Before
editor.startPrompt("Search:", "my-search");
// After
editor.startPrompt(editor.t("prompt.search"), "my-search");
See these plugins for complete examples:
plugins/git_grep.ts + plugins/git_grep.i18n.jsonplugins/git_find_file.ts + plugins/git_find_file.i18n.jsonplugins/git_gutter.ts + plugins/git_gutter.i18n.jsonTranslations are automatically loaded when your plugin loads. If the user's locale isn't available in your translation file, English (en) is used as a fallback.
types/fresh.d.ts for autocomplete and type checking"myplugin:something" format for easy batch removallines_changed instead of per-keystroke handlerseditor.debug() to log values during development.i18n.json files to make your plugin accessible to international users