import { LocaleTemplates } from "./i18n.js"; import { T as TemplateRenderer } from "../packem_shared/types.d-I-KeZ5w2.js"; /** * Loads a named template in every locale that has a file on disk. * * For a name such as `welcome`, the directory is searched for `welcome.{locale}.html`, and each * match is keyed by its locale. The un-suffixed `welcome.html` is registered under `defaultLocale`. * The result plugs straight into {@link renderI18n}, which then resolves `de-AT` to `de` and falls * back to the default locale. * * Only files are read, and only names built from the directory listing. The requested name must not * contain a path separator or `..`, and a locale is never turned into a path, so a locale taken from * user input (such as `Accept-Language`) only selects a key in the returned map. * @param directory The directory that holds the template files. * @param name The template name, without locale or extension. * @param options The default locale and file extension. See {@link LocaleFileOptions}. * @returns The file contents keyed by locale. See {@link LocaleTemplates}. * @throws {EmailError} When the name is unsafe, the directory cannot be read, no file matches, the * un-suffixed file has no `defaultLocale`, the default locale has both files, or two locales differ * only by case. * @example * ```ts * const templates = await loadLocaleTemplates("./emails", "welcome", { defaultLocale: "en" }); * await renderI18n(templates, "de-AT", renderHandlebars, { name: "Ada" }, { defaultLocale: "en" }); * ``` */ declare const loadLocaleTemplates: (directory: string, name: string, options?: LocaleFileOptions) => Promise; /** * Creates a renderer that loads a named template from disk for a locale and renders it with an * engine, falling back to the default locale. Binding `defaultLocale` once here means the fallback * cannot be left out of a call. * @param directory The directory that holds the template files. * @param renderer The text template engine, such as `renderHandlebars` or `renderMjml`. * @param options The default locale and file extension. See {@link LocaleFileOptions}. * @returns A {@link LocaleFileRenderer}. * @example * ```ts * import { renderHandlebars } from "@visulima/email/template/handlebars"; * import { createLocaleFileRenderer } from "@visulima/email/template/locale-files"; * * const render = createLocaleFileRenderer("./emails", renderHandlebars, { defaultLocale: "en" }); * await render("welcome", "fr", { name: "Ada" }); // reads welcome.html when there is no welcome.fr.html * ``` */ declare const createLocaleFileRenderer: (directory: string, renderer: TemplateRenderer, options?: LocaleFileOptions) => LocaleFileRenderer; /** * Options for {@link loadLocaleTemplates} and {@link createLocaleFileRenderer}. */ interface LocaleFileOptions { /** * Locale the un-suffixed file (`name` plus `extension`) is registered under. It is also the * fallback for any locale without its own file. Required when that file exists. */ defaultLocale?: string; /** * File extension, including the leading dot. * @default ".html" */ extension?: string; } /** * Renders a named template from disk for a locale. Each call reads the directory again, so cache * the result yourself if the templates do not change at runtime. */ type LocaleFileRenderer = (name: string, locale: string, data?: Record, rendererOptions?: Record) => Promise; export { LocaleFileOptions, LocaleFileRenderer, createLocaleFileRenderer, loadLocaleTemplates };