Skip to content

Commit 3c8c6df

Browse files
hasanakgitamargiv
authored andcommitted
Setup i18n
1 parent 55cd664 commit 3c8c6df

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

resources/js/app.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
import './bootstrap';
2-
import i18n from 'vue-banana-i18n';
32
import { createStore } from './store';
4-
import i18nMessages from './lib/i18n';
53
import {createApp, h} from 'vue';
64
import {createInertiaApp} from '@inertiajs/inertia-vue3';
5+
import i18nMessages, { I18nMessages } from './lib/i18n';
6+
import {createI18n} from 'vue-banana-i18n'
77
import bubble from './lib/bubble';
88
import Error from './Pages/Error.vue';
99
import Layout from './Pages/Layout.vue';
1010

1111
Vue.use(bubble);
1212

1313
// Retrieve i18n messages and setup the Vue instance to handle them.
14-
async function setupI18n(locale: string): Promise<void>{
15-
const messages = await i18nMessages(locale);
16-
Vue.use(i18n, { locale, messages });
14+
async function setupI18n(locale: string): Promise<I18nMessages>{
15+
return await i18nMessages(locale);
1716
}
1817

1918
// Only bootstrap inertia if setup is successful. Display generic error
2019
// component otherwise
2120
(async () => {
2221
try {
23-
await setupI18n(document.documentElement.lang);
2422
const store = createStore();
25-
23+
const locale = document.documentElement.lang;
24+
const i18nMessages = await setupI18n(locale);
25+
const i18nPlugin = createI18n({
26+
locale: locale,
27+
messages: i18nMessages
28+
});
2629
createInertiaApp({
2730
resolve: name => {
2831
const page = require(`./Pages/${name}`).default;
@@ -35,6 +38,7 @@ async function setupI18n(locale: string): Promise<void>{
3538
createApp({
3639
render: () => h(app, props)
3740
})
41+
.use(i18nPlugin)
3842
.use(plugin)
3943
.mount(el)
4044
}

resources/js/lib/i18n.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import axios from 'axios';
22

3-
interface I18nMessages {
3+
export interface I18nMessages {
44
[lang: string]: {
55
[key: string]: string
66
}

0 commit comments

Comments
 (0)