Creating Translation Files
Create a.i18n.json file alongside your plugin with the same base name:
Translation File Structure
The translation file uses a simple two-level structure: locale → key → translation.Key Conventions
Organize your translation keys using prefixes:cmd.*
Command names and descriptions
status.*
Status bar messages
prompt.*
Prompt labels
error.*
Error messages
Interpolation
Use%{variable} syntax for variable interpolation:
Using Translations
Translating Status Messages
Useeditor.t() to translate status messages:
The
editor.t() method is available through the pluginTranslate API function.Translating Command Registration
Use% prefix for command names and descriptions to enable automatic translation:
Translating Prompt Labels
Translation API
pluginTranslate
Translate a string for a plugin using the current locale.string
required
Name of the plugin (matches the .ts file name)
string
required
Translation key (e.g., “status.ready”)
Record<string, unknown>
required
Variables for interpolation
string
Translated string with variables interpolated
getCurrentLocale
Get the currently active locale.string
Current locale code (e.g., “en”, “es”, “fr”)
Translation Loading
Translations 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.
Fallback Chain
- User’s configured locale (e.g.,
es) - English (
en) - Original key string
Complete Example
Plugin File (git_grep.ts)
Translation File (git_grep.i18n.json)
Best Practices
Always provide English translations
Always provide English translations
English (
en) is the fallback locale. All plugins should include English translations.Use consistent key naming
Use consistent key naming
Follow the convention of prefixing keys by category:
cmd.*, status.*, prompt.*, etc.Keep translations concise
Keep translations concise
Status bar messages and command names should be short and clear in all languages.
Test with different locales
Test with different locales
Test your plugin with different locale settings to ensure translations display correctly.
Use type-safe interpolation
Use type-safe interpolation
Always convert numbers to strings for interpolation:
Example Plugins with i18n
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.json