Allo setting UI language via query param

This commit is contained in:
N-Pex 2021-09-25 15:08:26 +02:00
parent f9745ddb7d
commit 583f6b78cd
2 changed files with 14 additions and 2 deletions

View file

@ -2,6 +2,7 @@ import Vue from 'vue'
import App from './App.vue'
import vuetify from './plugins/vuetify';
import store from './store'
import i18n from './plugins/lang';
import router from './router'
import matrix from './services/matrix.service'
import navigation from './services/navigation.service'
@ -14,7 +15,6 @@ import VueResize from 'vue-resize';
import 'vue-resize/dist/vue-resize.css';
import VueClipboard from 'vue-clipboard2'
import VueSanitize from "vue-sanitize";
import i18n from './plugins/lang';
var defaultOptions = VueSanitize.defaults;
defaultOptions.disallowedTagsMode = "recursiveEscape";
@ -155,8 +155,8 @@ Vue.use(navigation, router);
new Vue({
vuetify,
store,
router,
i18n,
router,
matrix,
config,
cleaninsights,

View file

@ -87,6 +87,18 @@ router.beforeEach((to, from, next) => {
var authRequired = !publicPages.includes(to.path);
const loggedIn = router.app.$store.state.auth.user;
if (to.query && to.query.lang) {
// Set language via query param
const lang = to.query.lang;
// Check if valid translation
if (router.app.$i18n.messages[lang]) {
router.app.$store.commit('setLanguage', lang);
if (router.app.$i18n) {
router.app.$i18n.locale = to.query.lang;
}
}
}
if (to.name == 'Chat' || to.name == 'Join') {
if (!to.params.roomId && to.hash) {
// Public rooms start with '#', confuses the router. If hash but no roomId param, set it.