Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
82 lines
2.0 KiB
TypeScript
82 lines
2.0 KiB
TypeScript
import React, {
|
|
createContext,
|
|
useCallback,
|
|
useContext,
|
|
useMemo,
|
|
type ReactNode
|
|
} from "react";
|
|
import {
|
|
createLocaleObjectI18nModuleManifest,
|
|
type I18nRuntime
|
|
} from "@tutti-os/ui-i18n-runtime";
|
|
import * as agentGuiI18nRuntime from "./runtime.ts";
|
|
import type {
|
|
AgentGuiI18nLocale,
|
|
TranslateFn,
|
|
TranslateOptions
|
|
} from "./runtime.ts";
|
|
|
|
export const agentGuiI18nResources = agentGuiI18nRuntime.agentGuiI18nResources;
|
|
export const getActiveUiLanguage = agentGuiI18nRuntime.getActiveUiLanguage;
|
|
export const translate = agentGuiI18nRuntime.translate;
|
|
export const translateInUiLanguage = agentGuiI18nRuntime.translateInUiLanguage;
|
|
export type { AgentGuiI18nLocale, TranslateFn, TranslateOptions };
|
|
|
|
export const agentGuiI18nModule = createLocaleObjectI18nModuleManifest({
|
|
fileByLocale: {
|
|
en: "packages/agent/gui/app/renderer/i18n/locales/en.ts",
|
|
"zh-CN": "packages/agent/gui/app/renderer/i18n/locales/zh-CN.ts"
|
|
},
|
|
name: "agent-gui",
|
|
sourceRoot: "packages/agent/gui"
|
|
});
|
|
|
|
const AgentGuiI18nContext = createContext<{
|
|
locale: AgentGuiI18nLocale;
|
|
runtime: I18nRuntime<string>;
|
|
} | null>(null);
|
|
|
|
export function AgentGuiI18nProvider({
|
|
children,
|
|
locale = "en",
|
|
runtime
|
|
}: {
|
|
children: ReactNode;
|
|
locale?: AgentGuiI18nLocale;
|
|
runtime?: I18nRuntime<string> | null;
|
|
}): React.ReactElement {
|
|
const value = useMemo(
|
|
() =>
|
|
agentGuiI18nRuntime.resolveAgentGuiI18nRuntime({
|
|
locale,
|
|
runtime
|
|
}),
|
|
[locale, runtime]
|
|
);
|
|
|
|
agentGuiI18nRuntime.setCurrentAgentGuiI18nRuntime(value);
|
|
|
|
return React.createElement(AgentGuiI18nContext.Provider, { value }, children);
|
|
}
|
|
|
|
export function useTranslation(): {
|
|
i18n: I18nRuntime<string>;
|
|
locale: AgentGuiI18nLocale;
|
|
t: TranslateFn;
|
|
} {
|
|
const context =
|
|
useContext(AgentGuiI18nContext) ??
|
|
agentGuiI18nRuntime.getCurrentAgentGuiI18nRuntime();
|
|
const t = useCallback(
|
|
(key: string, options?: TranslateOptions) =>
|
|
context.runtime.t(key, options),
|
|
[context.runtime]
|
|
);
|
|
|
|
return {
|
|
i18n: context.runtime,
|
|
locale: context.locale,
|
|
t
|
|
};
|
|
}
|