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, |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame^] | 10 | /[A-Za-z0-9-_,\s]+\.json$/i, |
Dixsie Wolmers | cbcd213 | 2020-01-30 20:58:37 -0600 | [diff] [blame] | 11 | ); |
| 12 | const messages = {}; |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 13 | locales.keys().forEach((key) => { |
Dixsie Wolmers | cbcd213 | 2020-01-30 20:58:37 -0600 | [diff] [blame] | 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 |
Sukanya Pandey | 5ee04ef | 2020-03-19 10:23:23 +0530 | [diff] [blame] | 25 | locale: window.localStorage.getItem('storedLanguage'), |
Dixsie Wolmers | c85395f | 2020-02-26 13:22:12 -0600 | [diff] [blame] | 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, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 31 | messages: loadLocaleMessages(), |
Dixsie Wolmers | cbcd213 | 2020-01-30 20:58:37 -0600 | [diff] [blame] | 32 | }); |