import * as React from "react" import type { I18nProjectConfig } from "../../config/lingui-config" import { I18nProvider } from "../../runtime" import { requestDevtoolJson } from "../api-client" import { I18nDevtool } from "../i18n-devtool" type ProjectState = | { status: "loading" } | { error: Error; status: "error" } | { project: I18nProjectConfig; status: "ready" } export function DevtoolApp() { const [state, setState] = React.useState({ status: "loading" }) React.useEffect(() => { requestDevtoolJson("/__i18n/project").then( (project) => setState({ project, status: "ready" }), (reason) => setState({ error: reason instanceof Error ? reason : new Error("Unable to load the i18n project."), status: "error", }) ) }, []) if (state.status !== "ready") { return (
{state.status === "error" ? state.error.message : "Loading I18n Devtool…"}
) } const locale = state.project.locales.find( (candidateLocale) => candidateLocale !== state.project.sourceLocale ) ?? state.project.sourceLocale if (!state.project.locales.includes(locale)) { return (
Add a target locale with workspace-i18n new <locale>.
) } return ( ) }