/**
* Runtime catalog loader. Compiled `id → string` catalogs live in `./compiled/`
* (generated by `npm run i18n` via the FormatJS CLI) and are bundled eagerly by
* Vite so a locale switch is synchronous with no network round-trip.
*
* The source locale (`en`) intentionally has **no** catalog: every message keeps
* its inline `defaultMessage`, so react-intl renders English straight from the
* components. Only non-source locales need a catalog.
* @module gui/i18n/loadMessages
*/
import { DEFAULT_LOCALE } from "./config.js";
// Eagerly import every compiled catalog. Keyed by path, value is the JSON's
// default export (an `{ [id]: string }` map). Empty until `npm run i18n` runs.
const compiled = import.meta.glob("./compiled/*.json", {
eager: true,
import: "default"
});
/**
* Messages for a locale, suitable for `<IntlProvider messages>`.
* @param {string} locale A resolved, supported locale code.
* @returns {(Object<string,string>|undefined)} The catalog, or `undefined` for
* the source locale (react-intl then uses each message's `defaultMessage`).
*/
export function messagesFor(locale) {
if (locale === DEFAULT_LOCALE) return undefined;
return compiled[`./compiled/${locale}.json`];
}