message: added dynamic read of language strings
diff: @@ -5,18 +5,13 @@ import {
  IntlCache,
  } from "@formatjs/intl";
  import osLocale from "os-locale";
  -// import { MessageFormatElement } from "intl-messageformat-parser";
  -
  -// eslint-disable-next-line @typescript-eslint/no-require-imports,@typescript-eslint/no-var-requires
  -const enMessages = require("../../compiled-lang/en.json");
  -// eslint-disable-next-line @typescript-eslint/no-require-imports,@typescript-eslint/no-var-requires
  -const esMessages = require("../../compiled-lang/es.json");
  +import { readFileSync } from "fs";
  +import { MessageFormatElement } from "intl-messageformat-parser";
  const cache: IntlCache = createIntlCache();
  -export function getIntl(): IntlShape<string> {
  - const locale: string = osLocale.sync(); // can make async if top-level await is available
  - const messages = locale.substring(0, 2) == "es" ? esMessages : enMessages;
  +export function getIntl(locale: string = osLocale.sync()): IntlShape<string> {
  + const messages = getLocaleData(locale);
  return createIntl(
  {
  locale: locale,
  @@ -27,16 +22,15 @@ export function getIntl(): IntlShape<string> {
  );
  }
  -// TODO: find way to use dynamic import without top-level await statements in command files
  -// async function loadLocaleData(
  -// locale: string
  -// ): Promise<Record<string, MessageFormatElement[]>> {
  -// switch (locale) {
  -// case "es":
  -// // eslint-disable-next-line @typescript-eslint/no-require-imports
  -// return require("../../compiled-lang/es.json");
  -// default:
  -// // eslint-disable-next-line @typescript-eslint/no-require-imports
  -// return require("../../compiled-lang/en.json");
  -// }
  -// }
  +function getLocaleData(locale: string): Record<string, MessageFormatElement[]> {
  + switch (locale.substring(0, 2)) {
  + case "es":
  + return JSON.parse(
  + readFileSync(__dirname + "/../../compiled-lang/es.json", "utf-8")
  + );
  + default:
  + return JSON.parse(
  + readFileSync(__dirname + "/../../compiled-lang/en.json", "utf-8")
  + );
  + }
  +}
  