Dixsie Wolmers | cbcd213 | 2020-01-30 20:58:37 -0600 | [diff] [blame] | 1 | import Vue from 'vue'; |
| 2 | import VueI18n from 'vue-i18n'; |
| 3 | |
| 4 | Vue.use(VueI18n); |
| 5 | |
| 6 | function 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 | |
| 23 | export default new VueI18n({ |
Dixsie Wolmers | c85395f | 2020-02-26 13:22:12 -0600 | [diff] [blame] | 24 | // 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 Wolmers | cbcd213 | 2020-01-30 20:58:37 -0600 | [diff] [blame] | 31 | messages: loadLocaleMessages() |
| 32 | }); |