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:
@@ -0,0 +1,31 @@
|
||||
export type DevtoolAction = "compile" | "extract"
|
||||
|
||||
interface ApiError {
|
||||
error?: string
|
||||
}
|
||||
|
||||
export async function requestDevtoolJson<T>(
|
||||
url: string,
|
||||
init?: RequestInit
|
||||
): Promise<T> {
|
||||
const response = await fetch(url, init)
|
||||
const body = (await response.json()) as T & ApiError
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(body.error ?? `Request failed with ${response.status}.`)
|
||||
}
|
||||
|
||||
return body
|
||||
}
|
||||
|
||||
export async function runDevtoolAction(
|
||||
action: DevtoolAction,
|
||||
baseUrl = "/__i18n"
|
||||
) {
|
||||
const normalizedBaseUrl = baseUrl.replace(/\/+$/, "")
|
||||
|
||||
return requestDevtoolJson<{ output: string }>(
|
||||
`${normalizedBaseUrl}/actions/${action}`,
|
||||
{ method: "POST" }
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user