Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auto detection of Language #178

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ import MobileCommand from './components/mobile/mobile-pages/Command.vue'
Vue.use(VueAxios, axios)
Vue.use(VueMaterial)
Vue.use(Snotify)
Vue.use(VModal, { dialog: true, dynamic: true })
Vue.use(VModal, {
dialog: true,
dynamic: true
})
Vue.use(VueTabs)

// VueOnsen components
Expand Down Expand Up @@ -90,6 +93,21 @@ if (token) {
console.log('No authentication token found')
}

// Map of navigator language with the corresponding value

const mapLanguage = {
'it-it': 'it',
'en-en': 'en',
'en': 'en',
'nl': 'nl',
'nl-be': 'nl',
'ro': 'ro',
'ro-mo': 'ro',
'ru': 'ru',
'ru-mo': 'ru',
'sk': 'sk'
}

Vue.config.productionTip = false

Vue.directive('focus', {
Expand All @@ -106,5 +124,14 @@ new Vue({
router,
store,
template: '<App/>',
components: { App }
components: {
App
},
mounted () {
// lowercase for new and old browser
const language = window.navigator.language.toLocaleLowerCase()
if (!(mapLanguage[language] === undefined)) {
this.$i18n.set(mapLanguage[language])
}
}
})