9e3f1d6b59
- add SSR-safe I18nProvider, Translate, locale hooks, catalog activation, and typed runtime APIs - add consumer-owned Lingui configuration helpers and a CLI for locale creation, extraction, compilation, and project discovery - add catalog read/write services plus a Vite development API plugin scoped to each consuming application - add the portal-based I18nDevtool, message editor, dark-theme tracking, and standalone Message Studio - document the consumer workflow and cover runtime, configuration, catalog, CLI, and Devtool behavior with tests
40 lines
892 B
TypeScript
40 lines
892 B
TypeScript
import * as React from "react"
|
|
|
|
import type { MessageRepository } from "./types"
|
|
|
|
const MessageRepositoryContext = React.createContext<MessageRepository | null>(
|
|
null
|
|
)
|
|
|
|
export interface MessageRepositoryProviderProps {
|
|
children: React.ReactNode
|
|
repository: MessageRepository
|
|
}
|
|
|
|
export function MessageRepositoryProvider({
|
|
children,
|
|
repository,
|
|
}: MessageRepositoryProviderProps) {
|
|
return (
|
|
<MessageRepositoryContext.Provider value={repository}>
|
|
{children}
|
|
</MessageRepositoryContext.Provider>
|
|
)
|
|
}
|
|
|
|
export function useMessageRepository() {
|
|
const repository = React.useContext(MessageRepositoryContext)
|
|
|
|
if (!repository) {
|
|
throw new Error(
|
|
"MessagePanel requires a MessageRepositoryProvider or a repository prop."
|
|
)
|
|
}
|
|
|
|
return repository
|
|
}
|
|
|
|
export function useOptionalMessageRepository() {
|
|
return React.useContext(MessageRepositoryContext)
|
|
}
|