Remix & Hydrogen
API Reference
Complete API documentation for @better-i18n/remix
Complete API reference for the Remix & Hydrogen SDK.
Architecture
@better-i18n/remix is a thin wrapper around @better-i18n/core that adds:
- Request-based locale detection via
Accept-Languageheader parsing - Singleton pattern with
TtlCachefor efficient CDN fetching across requests - No client-side runtime — translations are loaded server-side and passed as loader data
createRemixI18n
The main entry point. Creates a singleton i18n instance for server-side use.
import { createRemixI18n } from "@better-i18n/remix";
const i18n = createRemixI18n({
project: "my-company/web-app",
defaultLocale: "en",
});RemixI18n Interface
Utility Functions
Types
msg() Helper Pattern
While not part of the SDK, we recommend creating a msg() helper for type-safe message access:
export function msg(
ns: Record<string, unknown> | undefined,
key: string,
fallback: string,
): string {
const val = ns?.[key];
return typeof val === "string" ? val : fallback;
}This pattern provides:
- Type safety — No unsafe casting of
unknownvalues - Fallback support — Graceful degradation when translations are missing
- Namespace scoping — Access translations by namespace (e.g.,
messages.common)