Merge branch '386-detect-language' into 'develop'
Resolve "Detect user language from browser" Closes #386 See merge request funkwhale/funkwhale!346
This commit is contained in:
commit
4346d617ea
|
@ -0,0 +1 @@
|
||||||
|
Autoselect best language based on browser configuration (#386)
|
|
@ -93,6 +93,8 @@ import axios from 'axios'
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import {mapState} from 'vuex'
|
import {mapState} from 'vuex'
|
||||||
|
|
||||||
|
import translations from '@/translations'
|
||||||
|
|
||||||
import Sidebar from '@/components/Sidebar'
|
import Sidebar from '@/components/Sidebar'
|
||||||
import Raven from '@/components/Raven'
|
import Raven from '@/components/Raven'
|
||||||
import ServiceMessages from '@/components/ServiceMessages'
|
import ServiceMessages from '@/components/ServiceMessages'
|
||||||
|
@ -115,6 +117,7 @@ export default {
|
||||||
},
|
},
|
||||||
created () {
|
created () {
|
||||||
let self = this
|
let self = this
|
||||||
|
this.autodetectLanguage()
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
// used to redraw ago dates every minute
|
// used to redraw ago dates every minute
|
||||||
self.$store.commit('ui/computeLastDate')
|
self.$store.commit('ui/computeLastDate')
|
||||||
|
@ -138,6 +141,21 @@ export default {
|
||||||
if (confirm) {
|
if (confirm) {
|
||||||
this.$store.commit('instance/instanceUrl', null)
|
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: {
|
computed: {
|
||||||
|
|
Loading…
Reference in New Issue