Skip to content

Commit

Permalink
Setup i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
hasanakg authored and itamargiv committed Nov 3, 2023
1 parent d6b7d37 commit 7cd1640
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions resources/js/app.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
import './bootstrap';
import i18n from 'vue-banana-i18n';
import { createStore } from './store';
import i18nMessages from './lib/i18n';
import Vue, {createApp, h} from 'vue';
import {createInertiaApp} from '@inertiajs/inertia-vue3';
import i18nMessages, { I18nMessages } from './lib/i18n';
import {createI18n} from 'vue-banana-i18n'
import bubble from './lib/bubble';
import Error from './Pages/Error.vue';
import Layout from './Pages/Layout.vue';

Vue.use(bubble);

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

// Only bootstrap inertia if setup is successful. Display generic error
// component otherwise
(async () => {
try {
await setupI18n(document.documentElement.lang);
const store = createStore();

const locale = document.documentElement.lang;
const i18nMessages = await setupI18n(locale);
const i18nPlugin = createI18n({
locale: locale,
messages: i18nMessages
});
createInertiaApp({
resolve: name => {
const page = require(`./Pages/${name}`).default;
Expand All @@ -35,6 +38,7 @@ async function setupI18n(locale: string): Promise<void>{
createApp({
render: () => h(app, props)
})
.use(i18nPlugin)
.use(plugin)
.mount(el)
}
Expand Down
2 changes: 1 addition & 1 deletion resources/js/lib/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios';

interface I18nMessages {
export interface I18nMessages {
[lang: string]: {
[key: string]: string
}
Expand Down

0 comments on commit 7cd1640

Please sign in to comment.