This article describes perfectly how to implement localization with language switch functionality in Laravel and Inertia.
Sep 10, 2020
1
Level 9
Use localization with vue
After doing some research I saw a couple people recommend this library https://github.com/kg-bot/laravel-localization-to-vue .
And I'm a little confused on how to actually use it, I'm also using inertia.js so the part where they change the app.js has me a bit confused. This is my app.js code, I'm using the lang from Element-ui so I'm not sure how to add the code they use to this.
import {InertiaApp} from '@inertiajs/inertia-vue'
import Vue from 'vue'
import ElementUI from 'element-ui'
import lang from 'element-ui/lib/locale/lang/es'
import 'element-ui/lib/theme-chalk/reset.css'
import locale from 'element-ui/lib/locale'
locale.use(lang);
Vue.use(InertiaApp);
Vue.use(ElementUI);
const app = document.getElementById('app');
app.setAttribute(':class',"{'loaded': loaded}");
new Vue({
render: h => h(InertiaApp, {
props: {
initialPage: JSON.parse(app.dataset.page),
resolveComponent: name => import(`@/Pages/${name}`).then(module => module.default),
},
data(){
return{
loaded:true
}
}
}),
}).$mount(app);
I'm also confused about changing the locale, I want to use some flag icons to change the locale and translate accordingly.
Please or to participate in this conversation.