@astralarium/localizable
v0.1.0
Published
Renders `*.messages.json` text through the app's l10n system. Connects to `repo-l10n` automatically. Without a provider, renders source text.
Readme
@astralarium/localizable
Renders *.messages.json text through the app's l10n system.
Connects to repo-l10n automatically.
Without a provider, renders source text.
import { useFormat } from "@astralarium/localizable";
import messages from "./dialog.messages.json" with { type: "json" };
export function Title({ name }: { name: string }) {
const format = useFormat();
return <h2>{format(messages.title, { name })}</h2>;
}To use another l10n system, pass a format:
import { type FormatMessage, MessagesProvider } from "@astralarium/localizable";
import type { ReactNode } from "react";
const format: FormatMessage = (message, values) => t(message.id, values);
export function App({ children }: { children: ReactNode }) {
return (
<MessagesProvider format={format} locale="pl">
{children}
</MessagesProvider>
);
}