Skip to content

Commit 040931a

Browse files
authored
docs: add missing imports and fix typescript examples (#1046)
- Add missing `import VueI18n from 'vue-i18n'` vue-i18n-bridge examples - Change position of `castToVueI18n` to avoid type error in `Vue.use(i18n)`
1 parent 44ca1e7 commit 040931a

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

packages/vue-i18n-bridge/README.md

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Include `vue-i18n-bridge` after `vue`, `@vue/composition-api` and it will instal
4848

4949
```js
5050
import Vue from 'vue'
51+
import VueI18n from 'vue-i18n'
5152
import VueCompositionAPI, { createApp } from '@vue/composition-api'
5253
import { createI18n, useI18n } from 'vue-i18n-bridge'
5354

@@ -90,6 +91,7 @@ app.mount('#app')
9091

9192
```js
9293
import Vue from 'vue'
94+
import VueI18n from 'vue-i18n'
9395
import VueCompositionAPI from '@vue/composition-api'
9496
import { createI18n, useI18n } from 'vue-i18n-bridge'
9597

@@ -122,31 +124,37 @@ app.$mount('#app')
122124
For TypeScript:
123125
```ts
124126
import Vue from 'vue'
127+
import VueI18n from 'vue-i18n'
125128
import VueCompositionAPI from '@vue/composition-api'
126129
import { createI18n, useI18n, castToVueI18n } from 'vue-i18n-bridge'
127130

128131
Vue.use(VueCompositionAPI)
129132
Vue.use(VueI18n, { bridge: true })
130133

131-
const i18n = createI18n({
132-
locale: 'ja',
133-
messages: {
134-
en: {
135-
message: {
136-
hello: 'hello, {name}!'
137-
}
134+
const i18n = castToVueI18n(
135+
createI18n(
136+
{
137+
locale: 'ja',
138+
messages: {
139+
en: {
140+
message: {
141+
hello: 'hello, {name}!',
142+
},
143+
},
144+
ja: {
145+
message: {
146+
hello: 'こんにちは、{name}!',
147+
},
148+
},
149+
},
138150
},
139-
ja: {
140-
message: {
141-
hello: 'こんにちは、{name}!'
142-
}
143-
}
144-
}
145-
}, VueI18n)
151+
VueI18n
152+
)
153+
)
146154

147155
Vue.use(i18n)
148156

149-
const app = new Vue({ i18n: castToVueI18n(i18n) }) // you need to cast `i18n` instance
157+
const app = new Vue({ i18n }) // you need to cast `i18n` instance
150158
app.$mount('#app')
151159
```
152160

0 commit comments

Comments
 (0)