Skip to content

Commit 3606124

Browse files
iben12martinlindhe
authored andcommitted
update README.md for vue-i18n > 6.x (martinlindhe#49)
* update README.md for vue-i18n > 6.x * fix typo in README.md
1 parent 0dcfb5a commit 3606124

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

README.md

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,38 +42,51 @@ Then generate the include file with
4242
php artisan vue-i18n:generate
4343
```
4444

45-
Assuming you are using a recent version of vue-i18n, adjust your vue app with something like:
45+
Assuming you are using a recent version of vue-i18n (>=6.x), adjust your vue app with something like:
4646
```js
4747
import Vue from 'vue';
48-
import VueInternalization from 'vue-i18n';
49-
import Locales from './vue-i18n-locales.generated.js';
48+
import VueInternationalization from 'vue-i18n';
49+
import Locale from './vue-i18n-locales.generated';
5050

51-
Vue.use(VueInternalization);
51+
Vue.use(VueInternationalization);
5252

53-
Vue.config.lang = 'en';
53+
const lang = document.documentElement.lang.substr(0, 2);
54+
// or however you determine your current app locale
5455

55-
Object.keys(Locales).forEach(function (lang) {
56-
Vue.locale(lang, Locales[lang])
56+
const i18n = new VueInternationalization({
57+
locale: lang,
58+
messages: Locale
5759
});
5860

59-
...
61+
const app = new Vue({
62+
el: '#app',
63+
i18n,
64+
components: {
65+
...
66+
}
67+
}
6068
```
6169
62-
63-
For older vue-i18n, the initialization looks something like:
64-
70+
For older vue-i18n (5.x), the initialization looks something like:
6571
```js
6672
import Vue from 'vue';
6773
import VueInternationalization from 'vue-i18n';
6874
import Locales from './vue-i18n-locales.generated.js';
6975

70-
Vue.use(VueInternationalization, {
71-
lang: 'en',
72-
locales: Locales
76+
Vue.use(VueInternationalization);
77+
78+
Vue.config.lang = 'en';
79+
80+
Object.keys(Locales).forEach(function (lang) {
81+
Vue.locale(lang, Locales[lang])
7382
});
7483

7584
...
7685
```
86+
87+
88+
89+
7790
## Using vuex-i18n
7891
7992
### vuex-i18n

0 commit comments

Comments
 (0)