This extension now supports multiple languages through a comprehensive localization system. Currently, it includes built-in support for English (en) and Spanish (es), with the ability for users to add custom translations.
resources/locales/
├── en.json # English translations
└── es.json # Spanish translations
Each file contains organized translation keys grouped by category:
commands: Command titles and labelsmessages: User notifications and dialog messagesplaceholders: Input box placeholders
Language preferences and custom translations are stored in:
~/.config/remote-dev/localization.json
This file contains:
{
"language": "en",
"customTranslations": {
"messages": {
"customKey": "Your custom translation"
}
}
}import LocalizationManager from './controllers/localization.controller';
const i18n = LocalizationManager.getInstance();
// Simple translation
const message = i18n.t('messages.fileDeleted');
// Translation with variable substitution (supports {0}, {1}, etc.)
const message = i18n.t('messages.fileDeleted', filename);
const message = i18n.t('messages.ftpConnectionError', protocol, errorMessage);The LocalizationManager must be initialized early in the extension's activation:
// In extension.ts
await LocalizationManager.getInstance().init(context);Users can change the language using the Change Language command:
- Open Command Palette (
Cmd+Shift+P) - Search for "Change Language"
- Select the desired language from the quick pick menu
Users can add custom translations by:
- Running the Change Language command
- Selecting Edit Custom Translations
- Adding keys and values in the JSON format
Example custom translation:
{
"messages": {
"myCustomMessage": "This is my custom translation"
}
}Edit resources/locales/en.json and resources/locales/es.json:
{
"messages": {
"newFeatureMessage": "New feature message in English"
}
}const i18n = LocalizationManager.getInstance();
vscode.window.showInformationMessage(i18n.t('messages.newFeatureMessage'));- Category:
commands,messages,placeholders - Format:
camelCasefor sub-keys - Variables: Use
{0},{1}, etc. for substitution
Example:
{
"messages": {
"errorConnectingServer": "Error connecting to server: {0}",
"fileDeleted": "File deleted: {0}"
}
}Custom translations are merged with default translations and take precedence. This allows users to:
- Override existing translations
- Add translations for custom features
- Contribute new language translations
- Place custom translations in
~/.config/remote-dev/custom-translations.json - The system will automatically merge them with default translations
- Restart the extension for changes to take effect
The system detects language automatically based on:
- Saved preference in
localization.json - Falls back to English if not set
To add a new language:
- Create
resources/locales/{languageCode}.jsonwith all keys from English - Update
LanguageControllerto include the new language in the quick pick menu - Update the
LocalizationManagertype definitions if needed
Example:
// In language.controller.ts
const quickPickItems = [
{
label: 'English',
language: 'en' as const,
},
{
label: 'Español',
language: 'es' as const,
},
{
label: 'Français', // New language
language: 'fr' as const,
},
];- If a translation key is not found in the current language, the key path is returned
- If a language file is missing, the system falls back to English
- Custom translations are checked before falling back
- Always use the i18n system for user-facing strings
- Keep keys organized by category (commands, messages, placeholders)
- Use meaningful key names that describe the message
- Add variables for dynamic content instead of string concatenation
- Test with multiple languages to ensure UI doesn't break
- Verify the key path is correct in the translation file
- Check that the language file is in
resources/locales/ - Ensure the extension is restarted after changing translations
- Check for typos in the key name
- Verify the
custom-translations.jsonfile is in the correct location - Ensure the JSON syntax is valid
- Restart the extension after editing
- If a language file is missing, the system logs an error and falls back to English
- Check the VS Code output channel for error messages