# Migration from Vue 2
## `vue-i18n-bridge`
:::danger NOTE
vue-i18n-bridge will not be provided in v10 due to Vue 2 EOL. v9.13 will be the last version.
:::
### What is `vue-i18n-bridge`?
`vue-i18n-bridge` is a bridge to make the upgrade as easy as possible between vue-i18n@v8.26.1 or later and vue-i18n@v9.x.
It can be used in Vue 2 applications that you have already built with vue-i18n@v8.26.1 or later.
And, also some features are backported from vue-i18n@v9.x:
- Vue I18n Composition API, that is powered by `@vue/composition-api` and `vue-demi`
- Message format syntax, that is powered by `@intlify/message-compiler`
### Installation
#### Package manager
::: code-group
```sh [npm]
npm install vue-i18n-bridge
```
```sh [yarn]
yarn add vue-i18n-bridge
```
```sh [pnpm]
pnpm add vue-i18n-bridge
```
:::
You must install the below packages before using this library:
- vue-i18n: >= v8.26.1 < v9
- vue-demi: >= v0.13.5
- @vue/composition-api: >= v1.2.0 (if you will use Vue 2.6)
#### CDN
**For Vue 2.7**:
Include `vue-i18n-bridge` after `vue`, `vue-demi` and it will install.
```html
```
**For Vue 2.6**:
Include `vue-i18n-bridge` after `vue`, `@vue/composition-api`, `vue-demi` and it will install.
```html
```
### Usage
#### Composition API
**For Vue 2.7**:
```js
import Vue from 'vue'
import { createApp } from 'vue-demi'
import { createI18n, useI18n } from 'vue-i18n-bridge'
Vue.use(VueI18n, { bridge: true }) // you must specify '{ bridge: true }' plugin option when install vue-i18n
// `createI18n` options is almost same vue-i18n (vue-i18n@v9.x) API
const i18n = createI18n({
legacy: false,
locale: 'ja',
messages: {
en: {
message: {
hello: 'hello, {name}!'
}
},
ja: {
message: {
hello: 'こんにちは、{name}!'
}
}
}
}, VueI18n) // `createI18n` which is provide `vue-i18n-bridge` has second argument, you **must** pass `VueI18n` constructor which is provide `vue-i18n`
const app = createApp({
setup() {
// `useI18n` options is almost same vue-i18n (vue-i18n@v9.x) API
const { t, locale } = useI18n()
// ... todo something
return { t, locale }
}
})
app.use(i18n) // you must install `i18n` instance which is created by `createI18n`
app.mount('#app')
```
**For Vue 2.6**:
```js
import Vue from 'vue'
import VueCompositionAPI, { createApp } from '@vue/composition-api'
import { createI18n, useI18n } from 'vue-i18n-bridge'
Vue.use(VueCompositionAPI)
Vue.use(VueI18n, { bridge: true }) // you must specify '{ bridge: true }' plugin option when install vue-i18n
// `createI18n` options is almost same vue-i18n (vue-i18n@v9.x) API
const i18n = createI18n({
legacy: false,
locale: 'ja',
messages: {
en: {
message: {
hello: 'hello, {name}!'
}
},
ja: {
message: {
hello: 'こんにちは、{name}!'
}
}
}
}, VueI18n) // `createI18n` which is provide `vue-i18n-bridge` has second argument, you **must** pass `VueI18n` constructor which is provide `vue-i18n`
const app = createApp({
setup() {
// `useI18n` options is almost same vue-i18n (vue-i18n@v9.x) API
const { t, locale } = useI18n()
// ... todo something
return { t, locale }
}
})
app.use(i18n) // you must install `i18n` instance which is created by `createI18n`
app.mount('#app')
```
#### Legacy API
**For Vue 2.7**:
```js
import Vue from 'vue'
import { createI18n, useI18n } from 'vue-i18n-bridge'
Vue.use(VueI18n, { bridge: true }) // you must specify '{ bridge: true }' plugin option when install vue-i18n
// `createI18n` options is almost same vue-i18n (vue-i18n@v9.x) API
const i18n = createI18n({
locale: 'ja',
messages: {
en: {
message: {
hello: 'hello, {name}!'
}
},
ja: {
message: {
hello: 'こんにちは、{name}!'
}
}
}
}, VueI18n) // `createI18n` which is provide `vue-i18n-bridge` has second argument, you **must** pass `VueI18n` constructor which is provide `vue-i18n`
Vue.use(i18n) // you must install `i18n` instance which is created by `createI18n`
const app = new Vue({ i18n })
app.$mount('#app')
```
**For Vue 2.6**:
```js
import Vue from 'vue'
import VueCompositionAPI from '@vue/composition-api'
import { createI18n, useI18n } from 'vue-i18n-bridge'
Vue.use(VueCompositionAPI)
Vue.use(VueI18n, { bridge: true }) // you must specify '{ bridge: true }' plugin option when install vue-i18n
// `createI18n` options is almost same vue-i18n (vue-i18n@v9.x) API
const i18n = createI18n({
locale: 'ja',
messages: {
en: {
message: {
hello: 'hello, {name}!'
}
},
ja: {
message: {
hello: 'こんにちは、{name}!'
}
}
}
}, VueI18n) // `createI18n` which is provide `vue-i18n-bridge` has second argument, you **must** pass `VueI18n` constructor which is provide `vue-i18n`
Vue.use(i18n) // you must install `i18n` instance which is created by `createI18n`
const app = new Vue({ i18n })
app.$mount('#app')
```
**For TypeScript:**
```ts
import Vue from 'vue'
import VueCompositionAPI from '@vue/composition-api'
import { createI18n, useI18n, castToVueI18n } from 'vue-i18n-bridge'
Vue.use(VueCompositionAPI)
Vue.use(VueI18n, { bridge: true })
// you need to cast `i18n` instance
const i18n = castToVueI18n(createI18n({
locale: 'ja',
messages: {
en: {
message: {
hello: 'hello, {name}!'
}
},
ja: {
message: {
hello: 'こんにちは、{name}!'
}
}
}
}, VueI18n))
Vue.use(i18n)
const app = new Vue({ i18n })
app.$mount('#app')
```
### Usage UMD module in browser
#### For Vue 2.7
```js
const { createApp } = VueDemi // exported UMD which is named by `VueDemi`
const { createI18n, useI18n } = VueI18nBridge // exported UMD which is named by `VueI18nBridge`
Vue.use(VueI18n, { bridge: true })
const i18n = createI18n({
locale: 'ja',
messages: {
// ...
}
}, VueI18n)
const app = createApp({}, {
// ...
})
app.use(i18n)
app.mount('#app') // Vue app host container element
```
#### For Vue 2.6
```js
const { createApp } = VueCompositionAPI // exported UMD which is named by `VueCompositionAPI`
const { createI18n, useI18n } = VueI18nBridge // exported UMD which is named by `VueI18nBridge`
Vue.use(VueCompositionAPI)
Vue.use(VueI18n, { bridge: true })
const i18n = createI18n({
locale: 'ja',
messages: {
// ...
}
}, VueI18n)
const app = createApp({}, {
// ...
})
app.use(i18n)
app.mount('#app') // Vue app host container element
```
### Limitations
- In Legacy API mode, You **cannot use [new message format syntax](https://vue-i18n.intlify.dev/guide/essentials/syntax.html)** by porting from `vue-i18n`
- it use possible only Composition API mode
- In Legacy API mode, You **cannot use back-ported components that are following components** by porting from `vue-i18n`
- Translation components: ``
- DateTime format components: ``
- Number format components: ``
- In Composition API mode, the below APIs is prefixed with `$` is **global scope**
- `$t`
- `$d`
- `$n`
### Explanation of Different Builds
In the [dist/ directory of the npm package](https://unpkg.com/browse/vue-i18n-bridge@9.2.0-beta.6/dist/) you will find many different builds of `vue-i18n-bridge`. Here is an overview of which dist file should be used depending on the use-case.
#### From CDN or without a Bundler
- **`vue-i18n-bridge(.runtime).global(.prod).js`**:
- For direct use via `