36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
/**
|
|
* Lets the emails speak the instance's language from the same catalogs as
|
|
* the interface. A template names each message by its id, as
|
|
* `i18n._("email.reset.title", values)`, and its words, English included,
|
|
* are written in `locales/<lang>.po` only. `lingui extract` lists the ids it
|
|
* finds there beside the interface's messages, and `lingui compile` turns
|
|
* the catalogs into the `locales/<lang>.mjs` imported here, failing when a
|
|
* language lacks one. The ids are named rather than hashed from the English,
|
|
* since the server runs no Lingui macro.
|
|
*
|
|
* @module
|
|
*/
|
|
|
|
import { type I18n, type Messages, setupI18n } from "@lingui/core";
|
|
|
|
import { EMAIL_LOCALE } from "../config.ts";
|
|
import { LOCALES } from "../../shared/locale.ts";
|
|
|
|
const catalogs: [string, Messages][] = await Promise.all(
|
|
LOCALES.map(async (locale) =>
|
|
[
|
|
locale,
|
|
(await import(`../../locales/${locale}.mjs`)).messages as Messages,
|
|
] as [string, Messages]
|
|
),
|
|
);
|
|
|
|
/**
|
|
* Translates the emails' messages, in {@link EMAIL_LOCALE}. Every catalog is
|
|
* loaded, so a test can activate another language.
|
|
*/
|
|
export const i18n: I18n = setupI18n({
|
|
locale: EMAIL_LOCALE,
|
|
messages: Object.fromEntries(catalogs),
|
|
});
|