blob: c60573cadb3b4d2fb66dfebd58d954585245abb3 [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,
Ed Tanous81323992024-02-27 11:26:24 -080010 /[A-Za-z0-9-_,\s]+\.json$/i,
Dixsie Wolmerscbcd2132020-01-30 20:58:37 -060011 );
12 const messages = {};
Derick Montague602e98a2020-10-21 16:20:00 -050013 locales.keys().forEach((key) => {
Dixsie Wolmerscbcd2132020-01-30 20:58:37 -060014 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
Sukanya Pandey5ee04ef2020-03-19 10:23:23 +053025 locale: window.localStorage.getItem('storedLanguage'),
Dixsie Wolmersc85395f2020-02-26 13:22:12 -060026 // 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 Montague602e98a2020-10-21 16:20:00 -050031 messages: loadLocaleMessages(),
Dixsie Wolmerscbcd2132020-01-30 20:58:37 -060032});