Phyks (Lucas Verney)
a57d9ce8e3
* Init Webpack / Babel / etc setup. * Build the app using Vue, Vue-router, Vuex. * i18n Some backends changes were made to match the webapp development: * Return the flat status as a single string ("new" rather than "FlatStatus.new") * Completely switch to calling Weboob API directly for fetching * Use Canister for Bottle logging * Handle merging of details dict better * Add a WSGI script * Keep track of duplicates * Webserver had to be restarted to fetch external changes to the db * Handle leboncoin module better Also add contributions guidelines. Closes issue #3 Closes issue #14.
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
import Vue from 'vue'
|
|
import VueI18n from 'vue-i18n'
|
|
|
|
// Import translations
|
|
import en from './en'
|
|
|
|
Vue.use(VueI18n)
|
|
|
|
export function getBrowserLocales () {
|
|
let langs = []
|
|
|
|
if (navigator.languages) {
|
|
// Chrome does not currently set navigator.language correctly
|
|
// https://code.google.com/p/chromium/issues/detail?id=101138
|
|
// but it does set the first element of navigator.languages correctly
|
|
langs = navigator.languages
|
|
} else if (navigator.userLanguage) {
|
|
// IE only
|
|
langs = [navigator.userLanguage]
|
|
} else {
|
|
// as of this writing the latest version of firefox + safari set this correctly
|
|
langs = [navigator.language]
|
|
}
|
|
|
|
// Some browsers does not return uppercase for second part
|
|
const locales = langs.map(function (lang) {
|
|
const locale = lang.split('-')
|
|
return locale[1] ? `${locale[0]}-${locale[1].toUpperCase()}` : lang
|
|
})
|
|
|
|
return locales
|
|
}
|
|
|
|
const messages = {
|
|
'en': en
|
|
}
|
|
|
|
const locales = getBrowserLocales()
|
|
|
|
var locale = 'en' // Safe default
|
|
// Get best matching locale
|
|
for (var i = 0; i < locales.length; ++i) {
|
|
if (messages[locales[i]]) {
|
|
locale = locales[i]
|
|
break // Break at first matching locale
|
|
}
|
|
}
|
|
|
|
export default new VueI18n({
|
|
locale: locale,
|
|
messages
|
|
})
|