import Vue from "vue";
// eslint-disable-next-line
import VueI18n, { LocaleMessages } from "vue-i18n";

Vue.use(VueI18n);

function loadLocaleMessages (): LocaleMessages {
  const locales = require.context("./locales", true, /[A-Za-z0-9-_,\s]+\.json$/i);
  const messages: LocaleMessages = {};
  locales.keys().forEach(key => {
    const matched = key.match(/([A-Za-z0-9-_]+)\./i);
    if (matched && matched.length > 1) {
      const locale = matched[1];

export default new VueI18n({
  locale: process.env.VUE_APP_I18N_LOCALE || "en_US",
  fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || "en_US",
  messages: loadLocaleMessages()
});
      messages[locale] = locales(key);
    }
  });
  return messages;
}