therepo/packages/i18n/tests/fixtures.ts
2025-08-15 14:00:52 +12:00

30 lines
784 B
TypeScript

import I18n, { type I18nOptions } from "@websnacksjs/i18n";
export type Fixtures = {
base: {
common: typeof import("./fixtures/base/messages/en/common.json");
drama: typeof import("./fixtures/base/messages/en/drama.json");
};
};
export const withFixture = <F extends keyof Fixtures>(
fixture: F,
overrides: Partial<I18nOptions<Fixtures[F]>> = {},
): I18n<Fixtures[F]> => {
switch (fixture) {
case "base": {
return new I18n<Fixtures["base"]>({
supportedLocales: ["en", "fr", "fr-Arab"],
namespaces: ["drama"],
messagesUrlTemplate: new URL(
"./fixtures/base/messages/:locale/:namespace.json",
import.meta.url,
),
...(overrides as Partial<I18nOptions<Fixtures["base"]>>),
});
}
default: {
throw new Error("unreachable");
}
}
};