feat(i18n): add Lingui runtime and development tooling

- 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
This commit is contained in:
Maofeng
2026-07-29 21:23:00 +08:00
parent 011e7d8115
commit 9e3f1d6b59
39 changed files with 2897 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
import * as React from "react"
import type { MessageDescriptor, MessageId, MessageOptions } from "@lingui/core"
import { useLingui } from "@lingui/react"
import { I18nRuntimeContext } from "./context"
import type { LocaleDefinition, TranslateFunction } from "./types"
export function useTranslate(): TranslateFunction {
return useLingui()._
}
export function useMessage(descriptor: MessageDescriptor): string
export function useMessage(
id: MessageId,
values?: Record<string, unknown>,
options?: MessageOptions
): string
export function useMessage(
descriptorOrId: MessageDescriptor | MessageId,
values?: Record<string, unknown>,
options?: MessageOptions
) {
const translate = useTranslate()
return React.useMemo(
() =>
typeof descriptorOrId === "string"
? translate(descriptorOrId, values, options)
: translate(descriptorOrId),
[descriptorOrId, options, translate, values]
)
}
export function useLocale(): string {
const runtime = React.useContext(I18nRuntimeContext)
const { i18n } = useLingui()
return runtime?.locale ?? i18n.locale
}
export function useLocales(): readonly LocaleDefinition[] {
const runtime = React.useContext(I18nRuntimeContext)
const { i18n } = useLingui()
return (
runtime?.locales ?? [
{
direction: "ltr",
label: i18n.locale,
locale: i18n.locale,
},
]
)
}