vue-i18n-extract is a development tool designed for managing `vue-i18n` localization within Vue.js projects through static code analysis. It scans Vue Single File Components (SFCs), JavaScript, and TypeScript files to identify used i18n keys and compares them against existing translation files (e.g., JSON, YAML). This helps developers find missing translations, identify unused keys that can be safely removed, and detect duplicate keys. The current stable version is 2.0.7, with an active release cadence, frequently incorporating new features and bug fixes as evidenced by recent patch releases. Its primary differentiation lies in its comprehensive static analysis approach for Vue-specific i18n usage, supporting various patterns like `$t`, `v-t`, and `Translation` components.
npm install vue-i18n-extractVerified import paths — ran on the pinned version, not inferred.
This `package.json` excerpt demonstrates how to integrate `vue-i18n-extract` into a project using npm scripts for reporting, adding, and removing translation keys.
Review the official `vue-i18n-extract` documentation for v2.x to update `--vueFiles`, `--languageFiles`, and other options. Specifically, the `output` option was replaced by `dryRun` and `emit`.
Always test your glob patterns with a tool like `glob-tester` or `ls -l` combined with your pattern to ensure they correctly match the intended files. Pay close attention to file extensions and nested directory structures.
Ensure all imports are done using ES module syntax (e.g., `import { extractI18n } from 'vue-i18n-extract';`). If using older Node.js versions or CJS, configure a build step (like Babel or TypeScript compilation) to transpile imports.Migrate your `vue-i18n` usage to its latest recommended patterns, such as using `$t` or `t` for pluralization (with `n` parameter) and `<i18n-t>` components. Consult the `vue-i18n` migration guide for your specific version.
Verify the `vueFiles` glob pattern in your command or configuration file. Use a tool like `ls -l './src/**/*.vue'` to confirm that files are matched by the pattern. Adjust the path or pattern as needed.
Check the `languageFiles` glob pattern. Ensure the path is correct and the file extensions (`.json`, `.yml`, `.yaml`) are included and properly escaped if necessary (e.g., `*.?(json|yml|yaml)`).
For Node.js projects with `'type': 'module'`, use ES module imports: `import { extractI18n } from 'vue-i18n-extract';`. If sticking to CommonJS, check if a default export or different named exports are available, or use `await import('vue-i18n-extract')` for dynamic imports.No dependency data recorded yet.