A VS Code extension to highlight missing translations in next-intl JSON files and show missing languages on hover.
Download at VSCode Marketplace
- Highlights JSON keys missing in other language files, including nested properties (e.g.,
nested.message). - Shows missing languages on hover for warned keys.
- Supports two translation file structures:
- Single-File Mode: One JSON file per language (e.g.,
messages/en.json,messages/de.json). - Folder Mode: Language-specific subfolders with multiple JSON files (e.g.,
messages/en/common.json,messages/en/errors.json).
- Single-File Mode: One JSON file per language (e.g.,
- In folder mode, compares only equivalent files (e.g.,
en/common.jsonwithde/common.json, notde/errors.json). - Configurable translations folder path and mode via settings.
- Dynamically updates diagnostics when translation files (
*.json) are created, renamed, or deleted within the translations folder. - Handles complex JSON structures, including nested objects and escaped keys.
- Treats empty strings (
"") as missing translations for stricter validation. - Optimized performance with caching for large translation files and frequent hover interactions.
- Translation files must be organized in one of two ways:
- Single-File Mode: JSON files directly in the translations folder, named by language (e.g.,
messages/en.json). - Folder Mode: Language-specific subfolders containing one or more JSON files (e.g.,
messages/en/common.json).
- Single-File Mode: JSON files directly in the translations folder, named by language (e.g.,
- The extension detects the structure automatically (
automode prioritizes folder mode) or uses the configured mode. - A workspace folder must be open in VS Code.
- JSON files must be valid (malformed JSON will trigger an error notification).
- The extension uses
jsonc-parserfor robust JSON parsing. If building from source, ensurejsonc-parseris installed (npm install jsonc-parser).
This extension contributes the following settings:
nextIntlHlpr.translationsFolder: Path to the folder containing translation files (relative to workspace root). Defaults tomessages.nextIntlHlpr.translationsMode: Preferred mode for translation files. Options:auto: Detects based on folder contents, prioritizing folder mode (subfolders) over single-file mode (default).single-file: Expects one JSON file per language (e.g.,en.json).folder: Expects language subfolders with JSON files (e.g.,en/common.json).
- Language codes (e.g.,
en,de) are derived from file names (single-file mode) or folder names (folder mode). Ensure names match across languages for accurate comparisons. Future versions may support configurable language code validation.
- Install the extension from the VS Code Marketplace or by sideloading the
.vsixfile. - Ensure your translation files are in the
messagesfolder (or configurenextIntlHlpr.translationsFolder). - Open a JSON translation file to start seeing diagnostics and hover information.
- Place translation JSON files in a folder (e.g.,
messages/or as configured) using one of these structures:// Single-File Mode messages/ ├── en.json ├── de.json// Folder Mode messages/ ├── en/ │ ├── common.json │ ├── errors.json ├── de/ │ ├── common.json - Configure the mode in VS Code settings if needed:
- Go to Preferences > Settings and search for
nextIntlHlpr. - Set
nextIntlHlpr.translationsModetosingle-fileorfolderto enforce a mode, or leave asauto. - Set
nextIntlHlpr.translationsFolderif your translations are not inmessages.
- Go to Preferences > Settings and search for
- Open a JSON file to see warnings for missing translations.
- Hover over a warned key to see missing languages.
- Rename, add, or delete translation files, and diagnostics will update automatically.
If migrating from single-file to folder mode:
- Start with single-file structure:
messages/ ├── en.json ├── de.json - Set
nextIntlHlpr.translationsModetosingle-filein settings. - Move files to folders:
messages/ ├── en/ │ ├── common.json ├── de/ │ ├── common.json - Change
nextIntlHlpr.translationsModetofolderor leave asauto(it will prioritize folder mode). - The extension will process the new structure and update diagnostics dynamically.
messages/en.json:
{
"greeting": "Hello",
"nested": { "message": "Nested message" }
}messages/de.json:
{
"greeting": "Hallo"
}Opening messages/en.json will show a warning on nested.message (missing in de). Hovering over nested.message shows:
**Missing Translations**
Key: `nested.message`
Missing languages: `de`
messages/en/common.json:
{
"greeting": "Hello",
"nested": { "message": "Nested message" }
}messages/en/errors.json:
{
"error404": "Not Found"
}messages/de/common.json:
{
"greeting": "Hallo"
}Opening messages/en/common.json will show a warning on nested.message (missing in de/common.json). Hovering over nested.message shows:
**Missing Translations**
Key: `nested.message`
Missing languages: `de`
Renaming common.json to newCommon.json will automatically update diagnostics to compare en/newCommon.json with de/newCommon.json.
- No diagnostics appear:
- Ensure the translations folder exists and is correctly configured (
nextIntlHlpr.translationsFolder). - Verify the file structure matches the mode (
single-fileorfolder). - Check the VS Code console (
Developer: Toggle Developer Tools) for errors.
- Ensure the translations folder exists and is correctly configured (
- Diagnostics don’t update after renaming files:
- Ensure a workspace folder is open.
- Restart VS Code to reinitialize the file system watcher if changes are not detected.
- Errors about malformed JSON:
- Fix invalid JSON in the reported file (notifications will show the file path).
- Performance issues:
- For large translation files, ensure
nextIntlHlpr.translationsModeis set correctly to avoid unnecessary processing.
- For large translation files, ensure
- Language codes (e.g.,
en,de) are not validated; any folder or file name is treated as a language. - JSONC (JSON with comments) is parsed correctly, but comments are ignored and do not affect translation key detection.
- Multi-root workspaces use the first workspace folder containing the translations folder.
- Fixed Production Failure: Resolved an issue where the extension failed to activate in production due to a missing
jsonc-parserdependency (Cannot find module 'jsonc-parser'). The extension now works reliably when installed as a.vsixor from the VSCode Marketplace. - Removed
jsonc-parserDependency: Replacedjsonc-parserwith Node’s built-inJSON.parsefor parsing translation JSON files, eliminating external dependencies and simplifying bundling. This ensures compatibility with standard JSON files but requires valid JSON (no comments or trailing commas).
- Enhanced Logging: Added detailed logging to the
next-intl-hlprOutput channel to aid debugging. Logs include activation, file loading, and diagnostics events, making it easier to diagnose issues. - Improved Activation: Added
onStartupFinishedto activation events, ensuring reliable activation even if JSON files are not immediately opened. - Manual Diagnostics Refresh: Introduced the
nextIntlHlpr.refreshDiagnosticscommand to manually trigger diagnostics updates via the Command Palette.
- The JSON parser requires valid JSON without comments or trailing commas. Ensure your translation files are standard-compliant to avoid parsing errors.
- The key position parser for diagnostics and hover is simpler than the previous
jsonc-parserimplementation. Report any misaligned diagnostics with sample JSON files.
- v0.0.2: Initial diagnostics and hover support for translation JSON files.
- Non-standard JSON files (e.g., with comments) may cause parsing errors. Clean your JSON files or report issues for support.
- Complex JSON structures may lead to inaccurate key position detection. Share sample files to improve the parser.
Contributions are welcome! Please open an issue or pull request on the GitHub repository.
MIT License. See LICENSE for details.
