Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/modules/emails/utils/LocalizedMailChrome.ts
T

36 lines
1.3 KiB
TypeScript

import type { MailFooterCopy, MailLanguage } from "@hivegrid/mail";
import { defaultLocale, normalizeLocaleCandidate } from "@hivegrid/i18n";
import type { MailTranslator } from "~/locale/mail-translator.server";
export type LocalizedMailChrome = {
readonly language: MailLanguage;
readonly footerCopy: MailFooterCopy;
};
function normalizeMailLanguage(locale?: string): MailLanguage {
return normalizeLocaleCandidate(locale) ?? defaultLocale;
}
/**
* Resolves the shared, user-visible mail footer from the same locale as the
* message body. Direct React-email call sites must pass this chrome explicitly
* so they cannot silently fall back to the package's English preview defaults.
*/
export function localizedMailChrome(t: MailTranslator, locale?: string): LocalizedMailChrome {
return {
language: normalizeMailLanguage(locale),
footerCopy: {
privacyLabel: t("common.legal.privacyLabel"),
termsLabel: t("common.legal.termsLabel"),
imprintLabel: t("common.legal.imprintLabel"),
unsubscribeLabel: t("common.legal.unsubscribeLabel"),
supportBefore: t("common.support.htmlBefore"),
supportLinkLabel: t("common.support.emailLinkLabel"),
supportAfter: t("common.support.htmlAfter"),
signoffClosing: t("common.signoff.closing"),
signoffTeam: t("common.signoff.team"),
},
};
}