У меня есть приложение laravel/VueJs
, которое поддерживает несколько языков, но есть одна проблема: когда я меняю язык в теге html Lang VueJs, он не меняется.
<!doctype html>
<html lang = "{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset = "utf-8">
<meta name = "viewport" content = "width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name = "csrf-token" content = "{{ csrf_token() }}" />
<title>{{ config('app.name', 'Laravel') }}</title>
<link href = "{{ asset('css/app.css') }}" rel = "stylesheet" />
<style>body{ margin-bottom: 60px !important;}</style>
</head>
<body style = "overflow:hidden;">
<noscript>
<strong>We're sorry but Xtreme Vuesax doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id = "app"></div>
<script src = "{{ asset('js/app.js') }}"></script>
<script>
window.default_locale = "{{ config('app.locale') }}";
window.fallback_locale = "{{ config('app.fallback_locale') }}";
</script>
</body>
</html>
app.js
import VueI18n from 'vue-i18n'
Vue.use(VueI18n)
import localesData from './components/Layouts/localesData'
Vue.component('locale-dropdown', require('./components/Layouts/locales').default);
const i18n = new VueI18n({
locale: 'en',
messages: localesData,
})
const app = new Vue({
el: '#app',
router,
store,
i18n,
render: h => h(App)
});
Мне нужно, чтобы эта строка <html lang = "{{ str_replace('_', '-', app()->getLocale()) }}">
была изменена на выбранный язык в VueJs.
есть идеи, как это изменить?
Из вашего компонента Vue «выпадающий список локали», когда пользователь выбирает локаль, вы можете
//say the data property on your component which holds the selected locale is called locale
let h = document.querySelector('html');
h.setAttribute('lang', this.locale);
Потрясающе, спасибо.