cygnal/src/i18n/index.js

63 lines
1.4 KiB
JavaScript
Raw Normal View History

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';
import oc from './oc.json';
2018-07-21 18:27:02 +02:00
import './moment/oc';
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
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);
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,
});