Skip to content
Snippets Groups Projects
Verified Commit 92fde644 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Fix #386: Autoselect best language based on browser configuration

parent b58da3e9
No related branches found
No related tags found
No related merge requests found
Autoselect best language based on browser configuration (#386)
......@@ -93,6 +93,8 @@ import axios from 'axios'
import _ from 'lodash'
import {mapState} from 'vuex'
import translations from '@/translations'
import Sidebar from '@/components/Sidebar'
import Raven from '@/components/Raven'
import ServiceMessages from '@/components/ServiceMessages'
......@@ -115,6 +117,7 @@ export default {
},
created () {
let self = this
this.autodetectLanguage()
setInterval(() => {
// used to redraw ago dates every minute
self.$store.commit('ui/computeLastDate')
......@@ -138,6 +141,21 @@ export default {
if (confirm) {
this.$store.commit('instance/instanceUrl', null)
}
},
autodetectLanguage () {
let userLanguage = navigator.language || navigator.userLanguage
let available = _.keys(translations)
let matching = available.filter((a) => {
return userLanguage.replace('-', '_') === a
})
let almostMatching = available.filter((a) => {
return userLanguage.replace('-', '_').split('_')[0] === a.split('_')[0]
})
if (matching.length > 0) {
this.$language.current = matching[0]
} else if (almostMatching.length > 0) {
this.$language.current = almostMatching[0]
}
}
},
computed: {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment