message: reworked locale parsing to ensure locale used is always valid
diff: @@ -8,30 +8,33 @@ import osLocale from "os-locale";
  import { readFileSync } from "fs";
  import { MessageFormatElement } from "intl-messageformat-parser";
  +interface LocaleData {
  + lang: string;
  + messages: Record<string, MessageFormatElement[]>;
  +}
  +
  const cache: IntlCache = createIntlCache();
  export function getIntl(locale: string = osLocale.sync()): IntlShape<string> {
  - const lang = locale.substring(0, 2);
  - const messages = getLocaleData(lang);
  + const localeData: LocaleData = getLocaleData(locale);
  return createIntl(
  {
  - locale: lang,
  + locale: localeData.lang,
  defaultLocale: "en",
  - messages: messages,
  + messages: localeData.messages,
  },
  cache
  );
  }
  -function getLocaleData(lang: string): Record<string, MessageFormatElement[]> {
  - switch (lang) {
  - case "es":
  - return JSON.parse(
  - readFileSync(__dirname + "/../../compiled-lang/es.json", "utf-8")
  +function getLocaleData(locale: string): LocaleData {
  + const localeLang = locale.substring(0, 2);
  + const lang = ["en", "es"].includes(localeLang) ? localeLang : "en";
  + const messages = JSON.parse(
  + readFileSync(`${__dirname}/../../compiled-lang/${lang}.json`, "utf-8")
  );
  - default:
  - return JSON.parse(
  - readFileSync(__dirname + "/../../compiled-lang/en.json", "utf-8")
  - );
  - }
  + return {
  + lang: lang,
  + messages: messages,
  + };
  }
  