blob: 745d0504ab01d373649d6a29383405b63fda31a9 [file] [log] [blame]
Dixsie Wolmerscbcd2132020-01-30 20:58:37 -06001import Vue from 'vue';
2import VueI18n from 'vue-i18n';
3
4Vue.use(VueI18n);
5
6function loadLocaleMessages() {
7 const locales = require.context(
8 './locales',
9 true,
10 /[A-Za-z0-9-_,\s]+\.json$/i
11 );
12 const messages = {};
13 locales.keys().forEach(key => {
14 const matched = key.match(/([A-Za-z0-9-_]+)\./i);
15 if (matched && matched.length > 1) {
16 const locale = matched[1];
17 messages[locale] = locales(key);
18 }
19 });
20 return messages;
21}
22
23export default new VueI18n({
Dixsie Wolmersc85395f2020-02-26 13:22:12 -060024 // Get default locale from local storage
25 locale: localStorage.getItem('storedLanguage'),
26 // Locales that don't exist will fallback to English
27 fallbackLocale: 'en-US',
28 // Falling back to fallbackLocale generates two console warnings
29 // Silent fallback suppresses console warnings when using fallback
30 silentFallbackWarn: true,
Dixsie Wolmerscbcd2132020-01-30 20:58:37 -060031 messages: loadLocaleMessages()
32});