Install vue-i18n-extract using Yarnsh yarn add -D vue-i18n-extract
Or NPMsh npm install --save-dev vue-i18n-extract
Note:
vue-i18n-extractdocumentation usesyarncommands, butnpmwill also work. You can compareyarnandnpmcommands in theyarndocs, here.
Add the following section to your package.json:json { "scripts": { "vue-i18n-extract": "vue-i18n-extract" } }
Finally, run:
npm run vue-i18n-extract report -v './path/to/your/vue-files/**/*.?(js|vue)' -l './path/to/your/language-files/*.?(json|yml|yaml)'
or
yarn vue-i18n-extract report -v './path/to/your/vue-files/**/*.?(js|vue)' -l './path/to/your/language-files/*.?(json|yml|yaml)'
This will print out a table of missing keys in your language files, as well as unused keys in your language files.
You can run vue-i18n-extract directly from the CLI without having to install anything using npx
npx vue-i18n-extract report -v './path/to/your/vue-files/**/*.?(js|vue)' -l './path/to/your/language-files/*.?(json|yml|yaml)'
or
yarn dlx vue-i18n-extract report -v './path/to/your/vue-files/**/*.?(js|vue)' -l './path/to/your/language-files/*.?(json|yml|yaml)'
-v, --vueFiles RequiredThe Vue.js file(s) you want to extract i18n strings from. It can be a path to a folder or to a file. It accepts glob patterns../path/to/your/vue-files/**/*.?(js|vue)
-l, --languageFiles RequiredThe language file(s) you want to compare your Vue.js file(s) to. It can be a path to a folder or to a file. It accepts glob patterns../path/to/your/language-files/*.?(json|yml|yaml)
-o, --outputUse if you want to create a json file out of your report.-o output.json
-a, --addUse if you want to add missing keys into your language files.-a
Make sure you have vue-i18n-extract installed locally and then just import the library and uses the API:
const VueI18NExtract = require('vue-i18n-extract');
const report = VueI18NExtract.createI18NReport('./path/to/vue-files/**/*.?(js|vue)', './path/to/language-files/*.?(json|yml|yaml)');