
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
@intlify-lry/unplugin-vue-i18n
Advanced tools
unplugin for Vue I18n
npm i @intlify/unplugin-vue-i18n
// vite.config.ts
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite'
export default defineConfig({
plugins: [
VueI18nPlugin({ /* options */ }),
],
})
const VueI18nPlugin = require('@intlify/unplugin-vue-i18n/webpack')
// webpack.config.js
module.exports = {
/* ... */
plugins: [
VueI18nPlugin({ /* options */ })
]
}
// nuxt.config.ts
import { defineNuxtConfig } from 'nuxt'
import VueI18nPlugin from '@intlify/unplugin-vue-i18n'
export default defineNuxtConfig({
vite: {
plugins: [
VueI18nPlugin.vite({ /* options */ }),
],
},
// When using Webpack
// builder: '@nuxt/webpack-builder',
webpack: {
plugins: [
VueI18nPlugin.webpack({ /* options */ }),
]
}
})
Since vue-i18n@v9.x
, the locale messages are handled with message compiler, which converts them to javascript functions after compiling. After compiling, message compiler converts them into javascript functions, which can improve the performance of the application.
However, with the message compiler, the javascript function conversion will not work in some environments (e.g. CSP). For this reason, vue-i18n@v9.x
and later offer a full version that includes compiler and runtime, and a runtime only version.
If you are using the runtime version, you will need to compile before importing locale messages by managing them in a file such as .json
.
The below example that examples/vite/src/App.vue
have i18n
custom block:
<template>
<form>
<label>{{ t('language') }}</label>
<select v-model="locale">
<option value="en">en</option>
<option value="ja">ja</option>
</select>
</form>
<p>{{ t('hello') }}</p>
<Banana />
</template>
<script>
import { useI18n } from 'vue-i18n'
import Banana from './Banana.vue'
export default {
name: 'App',
components: {
Banana
},
setup() {
const { t, locale } = useI18n({
inheritLocale: true,
useScope: 'local'
})
return { t, locale }
}
}
</script>
<i18n>
{
"en": {
"language": "Language",
"hello": "hello, world!"
},
"ja": {
"language": "θ¨θͺ",
"hello": "γγγ«γ‘γ―γδΈηοΌ"
}
}
</i18n>
You can be used by specifying the following format in the lang
attribute:
example yaml
format:
<i18n lang="yaml">
en:
hello: 'Hello World!'
ja:
hello: 'γγγ«γ‘γ―γδΈηοΌ'
</i18n>
unplugin-vue-i18n allows you to statically bundle i18n resources such as json
or yaml
specified by the include
option of the plugin described below as locale messages with the import
syntax.
In this case, only one i18n resource can be statically bundled at a time with import
syntax, so the these code will be redundant for multiple locales.
import { createApp } from 'vue'
import { createI18n } from 'vue-i18n'
/*
* The i18n resources in the path specified in the plugin `include` option can be read
* as vue-i18n optimized locale messages using the import syntax
*/
import en from './src/locales/en.json'
import ja from './src/locales/ja.yaml'
import fr from './src/locales/fr.json5'
const i18n = createI18n({
locale: 'en',
messages: {
en,
ja,
fr
}
})
const app = createApp()
app.use(i18n).mount('#app')
unplugin-vue-i18n can use the bundler virtual mechanism to import all locales at once, using the special identifier @intlify/unplugin-vue-i18n/messages
, as the bellow:
import { createApp } from 'vue'
import { createI18n } from 'vue-i18n'
/*
* All i18n resources specified in the plugin `include` option can be loaded
* at once using the import syntax
*/
import messages from '@intlify/unplugin-vue-i18n/messages'
const i18n = createI18n({
locale: 'en',
messages
})
const app = createApp()
app.use(i18n).mount('#app')
If you want type definition of @intlify/unplugin-vue-i18n/messages
, add unplugin-vue-i18n/messages
to compilerOptions.types
of your tsconfig:
{
"compilerOptions": {
"types": ["@intlify/unplugin-vue-i18n/messages"]
}
}
As noted here, NPM provides many different builds of Vue I18n.
This plugin will automatically select and bundle Vue I18n build according to the following behavior:
vue-i18n.esm-bundler.js
vue-i18n.runtime.esm-bundler.js
About details, See the here
petite-vue-i18n
This plugin will automatically select and bundle petite-vue-i18n
build according to the following vite behavior:
petite-vue-i18n.esm-bundler.js
petite-vue-i18n.runtime.esm-bundler.js
include
Type: string | string[] | undefined
Default: undefined
A minimatch pattern, or array of patterns, you can specify a path to pre-compile i18n resources files. The extensions of i18n resources to be precompiled are as follows:
- json
- json5
- yaml
- yml
Note json
resources matches this option, it will be handled before the internal json plugin of bundler, and will not be processed afterwards, else the option doesn't match, the bundler side will handle.
runtimeOnly
Type: boolean
Default: true
Whether or not to automatically use Vue I18n runtime-only in production build, set vue-i18n.runtime.esm-bundler.js
in the vue-i18n
field of bundler config, the below:
- vite config: `resolve.alias`
- webpack config: `resolve.alias`
If false
is specified, Vue I18n (vue-i18n) package.json module
field will be used.
For more details, See here
compositionOnly
Type: boolean
Default: true
Whether to make vue-i18n API only composition API. By default the legacy API is tree-shaken.
For more details, See here
fullInstall
Type: boolean
Default: true
Whether to install the full set of APIs, components, etc. provided by Vue I18n. By default, all of them will be installed.
If false
is specified, buld-in components and directive will not be installed in vue and will be tree-shaken.
For more details, See here
forceStringify
Type: boolean
Default: false
Whether pre-compile number and boolean values as message functions that return the string value.
For example, the following json resources:
{
"trueValue": true,
"falseValue": false,
"nullValue": null,
"numberValue": 1
}
after pre-compiled (development):
export default {
"trueValue": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize(["true"])};fn.source="true";return fn;})(),
"falseValue": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize(["false"])};fn.source="false";return fn;})(),
"nullValue": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize(["null"])};fn.source="null";return fn;})(),
"numberValue": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize(["1"])};fn.source="1";return fn;})()
}
defaultSFCLang
Type: string
Default: 'json'
Specify the content for all your inlined i18n
custom blocks on your SFC
.
defaultSFCLang
must have one of the following values:
- json
- json5
- yaml
- yml
On inlined i18n
custom blocks that have specified the lang
attribute, the defaultSFCLang
is not applied.
For example, with defaultSFCLang: "yaml"
or defaultSFCLang: "yml"
, this custom block:
<i18n lang="yaml">
en:
hello: Hello
es:
hello: Hola
</i18n>
and this another one, are equivalent:
<i18n>
en:
hello: Hello
es:
hello: Hola
</i18n>
globalSFCScope
Type: boolean
Default: undefined
Whether to include all i18n
custom blocks on your SFC
on global
scope.
If true
, it will be applied to all inlined i18n
or imported
custom blocks.
Warning: beware enabling globalSFCScope: true
, all i18n
custom blocks in all your SFC
will be on global
scope.
For example, with globalSFCScope: true
, this custom block:
<i18n lang="yaml" global>
en:
hello: Hello
es:
hello: Hola
</i18n>
and this another one, are equivalent:
<i18n lang="yaml">
en:
hello: Hello
es:
hello: Hola
</i18n>
You can also use defaultSFCLang: "yaml"
, following with previous example, this another is also equivalent to previous ones:
<i18n>
en:
hello: Hello
es:
hello: Hola
</i18n>
bridge
Type: boolean
Default: false
The mode to birdge the i18n custom block to work in both vue-i18n@v8.x and vue-i18n@v9.x environments.
To support in a smooth transition from vue-i18n@v8.x to vue-i18n@v9.x, we provide a mode that bundles the i18n custom block to be available in either version.
β οΈ Note that if you set
bridge: true
, the bundle size will increase. It is recommended to disable this mode after the migration from vue-i18n@v8.26 to vue-i18n@v9.x is completed.
esm
Type: boolean
Default: true
For bridge
option is true
, whether to bundle locale resources with ESM. By default ESM, if you need to bundl with commonjs for especialy webpack, you need to set false
useClassComponent
Type: boolean
Default: false
This option that to use i18n custom blocks in vue-class-component
.
useVueI18nImportName
(Experimental)Type: boolean
Default: false
Whether to use the import name of petite-vue-i18n
with the same import name as vue-i18n (import { xxx } from 'vue-i18n'
).
This option allows a smooth migration from petite-vue-i18n
to vue-i18n
and allows progressive enhacement.
Details changes for each release are documented in the CHANGELOG.md
FAQs
unplugin for Vue I18n
The npm package @intlify-lry/unplugin-vue-i18n receives a total of 47 weekly downloads. As such, @intlify-lry/unplugin-vue-i18n popularity was classified as not popular.
We found that @intlify-lry/unplugin-vue-i18n demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.