import { type Locale } from '@urbicon-ui/i18n'; import type { AuthLocale, PartialAuthLocale } from './keys.js'; /** * Make an `AuthLocale` bundle available to every auth component and to the * server-side mail builders, paired with the locale's subpath import: * * ```ts * import { registerAuthLocale } from '@urbicon-ui/auth'; * import { de } from '@urbicon-ui/auth/i18n/de'; * registerAuthLocale('de', de); * ``` * * **At app start** is the recommendation, not a requirement: the registry is * reactive, so a registration after mount re-renders the components that are * already on screen. Registering at start is what makes the *first* server * render already correct — put the lines in a module that both the server and * the client evaluate (e.g. a `src/lib/locales.ts` imported from * `hooks.server.ts` **and** from the root `+layout.ts`), or a locale registered * on only one side renders German HTML that hydrates into English. * * Only `en` is built in; without a registration an auth component under * `` renders English. Registering `en` replaces the * built-in English bundle — the way to restyle the whole surface at once rather * than per component through the `t` prop. It replaces rather than merges, so * build the full bundle from the shipped one: * * ```ts * import { en } from '@urbicon-ui/auth/i18n/en'; * registerAuthLocale('en', mergeAuthLocale(en, { auth: { login: { title: 'Welcome back' } } })); * ``` * * Write-strict, because a bundle that is wrong here is wrong for every * component at once: throws on a locale `@urbicon-ui/i18n` does not support, on * a non-object bundle, and on a bundle missing any key the built-in `en` has. * TypeScript already refuses an incomplete literal, but a JSON file, a * JavaScript caller and an `as AuthLocale` cast do not — and a partial bundle * under `en` would make every other locale's fallback throw at render. */ export declare function registerAuthLocale(locale: Locale, bundle: AuthLocale): void; /** * Context-scoped hook for the full AuthLocale object at the active locale. Call * during component initialisation, then read it inside a `$derived` so it stays * reactive and resolves against the nearest ``: * * ```svelte * const authLocale = useAuthLocale(); * const t = $derived(mergeAuthLocale(authLocale(), tProp)); * ``` * * Resolves to the bundle registered for the provider's locale, or to English * when that locale has none — {@link registerAuthLocale} is how a locale other * than `en` gets one. Read inside a `$derived` as above, a registration that * lands after the component mounted re-renders it; read once into a `const`, it * does not. * * Replaces the former free `getAuthLocale()`, which read the global locale * singleton and so could not be request-scoped (SSR-unsafe). */ export declare function useAuthLocale(): () => AuthLocale; /** * Deep-merge consumer locale `overrides` over a complete `base` bundle — THE * single place a `PartialAuthLocale` becomes a full `AuthLocale`. * Every component resolves its `t` prop through this, so overriding one string * (`{ auth: { login: { title: 'Welcome back' } } }`) keeps every other key from * the active bundle instead of blanking whole subtrees. Objects merge * recursively, string leaves replace, `undefined` entries are skipped. Returns * `base` itself when there is nothing to merge. * * Kind-preserving: an entry whose kind mismatches the base (`null`/array/ * primitive where the bundle has a subtree, an object where it has a string) * is skipped, keeping the base value. TypeScript rules those out, but JSON is * the natural carrier for consumer override files and cannot express * `undefined` — a hand-written `null` must not blank a whole subtree the * postcondition promises to be complete. */ export declare function mergeAuthLocale(base: AuthLocale, overrides?: PartialAuthLocale): AuthLocale; export type { AuthLocale, DeepPartial, PartialAuthLocale } from './keys.js';