Hover translator
VS Code extension to translate text and words on hover with support for multiple formats and languages.
Features
- ✨ Translate text on hover: Hover over any word or text to see translations
- 📝 Smart format detection: Automatically detects and translates identifiers in various formats:
snake_case (e.g., user_name)
camelCase (e.g., userName)
PascalCase (e.g., UserName)
kebab-case (e.g., user-name)
Title Case (e.g., User Name)
- 🔍 Block translation: Select and translate entire code blocks
- 📄 Automatic string literal translation: Automatically detects and translates string literals (quoted text) in your code
- Supports single quotes (
'text'), double quotes ("text"), and template literals (`text`)
- Automatically detects non-English text and translates it
- If you have a selection, translates the entire selected block
- 💾 Smart caching:
- Caches translations for faster performance
- Cache expires after 7 days to ensure fresh translations
- Automatic cache cleanup of expired entries
- 🌍 Support for multiple languages:
- English, Vietnamese, French, German, Spanish, Italian, Portuguese, Russian, Chinese, Japanese, Korean
- ⚙️ Easy configuration: Select language from status bar
- 🎛️ Quick toggle: Click on status bar to enable/disable
Usage
- Hover translation: Hover over any word, identifier, or string literal in your code to see its translation
- String literal translation: Hover over quoted text (strings) to automatically translate non-English text
- Block translation: Select a block of text and hover to translate the entire selection
- Command translation: Use the command "Translate Selected Block" to translate and optionally replace or copy the translated text
- Status bar controls: Click on the status bar to:
- Toggle the extension on/off
- Select translation language
Translation Behavior
- With selection: If you have text selected, hovering will translate the entire selection
- Without selection:
- If cursor is on a string literal (quoted text), it will translate the string content
- If cursor is on a word/identifier, it will translate that word
- Automatically detects non-English text in strings and translates it
Configuration
Configure in VS Code settings:
hoverTranslator.enabled: Enable/disable translation on hover (default: true)
hoverTranslator.targetLanguage: Target language for translation (default: Vietnamese)
Example Configuration
{
"hoverTranslator.enabled": true,
"hoverTranslator.targetLanguage": "Vietnamese"
}
Cache Management
The extension automatically manages translation cache:
- Translations are cached for faster performance
- Cache entries expire after 7 days
- Expired entries are automatically cleaned up
- Cache is persisted to disk and survives VS Code restarts
Commands
Variable Translate: Toggle Variable Translate: Toggle extension on/off
Variable Translate: Select Translation Language: Select translation language
Variable Translate: Translate Selected Block: Translate selected text block and optionally replace or copy
| |