i18next-cli plugin for extracting i18n translation keys from Vue Single File Components (SFC).
- Full Vue Support: Supports Vue 2.6+ and Vue 3.x
- Dual-mode Parsing: Automatically handles translation calls in
<script>and<template> - Multiple Syntaxes: Supports
t()function,data-i18nattribute, dynamic bindings, and more - TypeScript Support: Complete type definitions
- Highly Configurable: Custom function names, attribute names, file patterns, and more
npm install i18next-cli-vue --save-dev// i18next.config.js
import { defineConfig } from 'i18next-cli';
import i18nextVuePlugin from 'i18next-cli-vue';
export default defineConfig({
locales: ['en', 'zh', 'fr'],
extract: {
input: 'src/**/*.{vue,ts}',
output: 'locales/{{language}}.json',
defaultNS: 'translation',
},
plugins: [i18nextVuePlugin()],
});// i18next.config.js
import { defineConfig } from 'i18next-cli';
import i18nextVuePlugin from 'i18next-cli-vue';
export default defineConfig({
locales: ['en', 'zh'],
extract: {
input: 'src/**/*.{vue,ts,js}',
output: 'locales/{{language}}/{{ns}}.json',
defaultNS: 'common',
},
plugins: [
i18nextVuePlugin({
// Explicitly specify Vue version (2 | 3)
vueVersion: 3,
// Whether to parse dynamic binding attributes (`:attr`, `v-bind:attr`)
vueBindAttr: true,
// Translation function names
functions: ['t', '$t'],
// Namespace function names
namespaceFunctions: ['useTranslation', 'withTranslation'],
// HTML attribute name
attr: 'data-i18n',
// Options attribute name
optionAttr: 'data-i18n-options',
// File patterns to match
filePatterns: ['.vue', '.nvue'],
}),
],
});<template>
<!-- data-i18n attribute -->
<h1 data-i18n="welcome.title">Welcome</h1>
<!-- Multiple keys (semicolon separated) -->
<p data-i18n="greeting;welcome.message"></p>
<!-- Dynamic binding :attr -->
<button :aria-label="t('button.submit')">Submit</button>
<!-- v-bind:attr -->
<input v-bind:placeholder="t('input.placeholder')" />
<!-- v-on:click -->
<button @click="t('button.click')">Click</button>
</template><script>
import { useTranslation } from 'vue-i18next';
export default {
setup() {
const { t } = useTranslation('namespace');
return {
// Simple key
title: t('welcome.message'),
// With default value
greeting: t('greeting', 'Hello World'),
// With namespace prefix
namespaced: t('shared:key'),
};
},
};
</script>| Option | Type | Default Value | Description |
|---|---|---|---|
vueVersion |
2 | 3 | undefined |
undefined |
Explicit Vue version |
vueBindAttr |
boolean |
true |
Parse dynamic bindings |
functions |
string[] |
['t', '$t'] |
Translation function names |
namespaceFunctions |
string[] |
['useTranslation', 'withTranslation'] |
Namespace functions |
attr |
string |
'data-i18n' |
i18n attribute name |
optionAttr |
string |
'data-i18n-options' |
Options attribute name |
filePatterns |
string[] |
['.vue', '.nvue'] |
File matching patterns |
npm installnpm run buildnpm run test # watch mode
npm run test:run # single run
npm run test:coverage # coverage reportnpm run format # format code
npm run format:check # check formatting