2018-06-25 18:29:57 +02:00
|
|
|
import Vue from 'vue';
|
|
|
|
import VueI18n from 'vue-i18n';
|
|
|
|
|
2018-07-20 15:12:28 +02:00
|
|
|
import en from './en.json';
|
|
|
|
import fr from './fr.json';
|
2018-07-20 15:37:14 +02:00
|
|
|
import oc from './oc.json';
|
|
|
|
|
2018-07-21 18:27:02 +02:00
|
|
|
import './moment/oc';
|
|
|
|
|
2018-07-20 15:37:14 +02:00
|
|
|
export const AVAILABLE_LOCALES = [
|
|
|
|
{
|
|
|
|
iso: 'en',
|
|
|
|
name: 'English',
|
|
|
|
messages: en,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
iso: 'fr',
|
|
|
|
name: 'French',
|
|
|
|
messages: fr,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
iso: 'oc',
|
|
|
|
name: 'Occitan',
|
|
|
|
messages: oc,
|
|
|
|
},
|
|
|
|
];
|
2018-06-25 18:29:57 +02:00
|
|
|
|
2018-06-28 11:15:48 +02:00
|
|
|
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((lang) => {
|
|
|
|
const locale = lang.split('-');
|
|
|
|
return locale[1] ? `${locale[0]}-${locale[1].toUpperCase()}` : lang;
|
|
|
|
});
|
|
|
|
|
|
|
|
return locales;
|
|
|
|
}
|
|
|
|
|
2018-07-10 14:32:48 +02:00
|
|
|
Vue.use(VueI18n);
|
|
|
|
|
2018-07-20 15:37:14 +02:00
|
|
|
export const messages = {};
|
|
|
|
AVAILABLE_LOCALES.forEach((item) => {
|
|
|
|
messages[item.iso] = item.messages;
|
|
|
|
});
|
2018-06-25 18:29:57 +02:00
|
|
|
|
|
|
|
export default new VueI18n({
|
|
|
|
messages,
|
|
|
|
});
|