* feat: add i18n foundation * feat: localize sessions sidebar * Localize multirun/scheduled tasks and fix dialog dropdown interactions * localize git sidebar surface and add zh-CN keys * feat(ui): localize context panel, diff/plan views, and context sidebar content * fix(config): resolve user config home via fs/home before embedded home * localize header/chat UI and complete model/worktree panel strings * localize worktree + github issue/pr dialog flows * localize settings sections and split settings i18n dictionaries * localize additional settings sections and sidebars * localize more settings pages and dialogs * fix settings select trigger localization * localize tunnel settings ui surface * localize additional settings sections * localize keyboard shortcuts labels in settings * localize terminal and utility dialogs surfaces * feat(i18n): localize remaining UI strings * Add Ukrainian locale * Add Spanish locale * Add Brazilian Portuguese locale * Polish locale translations
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import React from 'react';
|
|
|
|
import { useI18nStore, formatMessage, type I18nKey, type I18nParams } from './store';
|
|
import { I18nContext, type I18nContextValue } from './react-context';
|
|
import { LOCALE_LABEL_KEYS, LOCALES } from './runtime';
|
|
|
|
export const I18nProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
|
const locale = useI18nStore((state) => state.locale);
|
|
const dictionary = useI18nStore((state) => state.dictionary);
|
|
const setLocale = useI18nStore((state) => state.setLocale);
|
|
|
|
React.useEffect(() => {
|
|
if (typeof document === 'undefined') {
|
|
return;
|
|
}
|
|
document.documentElement.lang = locale;
|
|
}, [locale]);
|
|
|
|
const value = React.useMemo<I18nContextValue>(() => {
|
|
const t = (key: I18nKey, params?: I18nParams) => formatMessage(dictionary, key, params);
|
|
return {
|
|
locale,
|
|
locales: LOCALES,
|
|
setLocale,
|
|
label: (targetLocale) => t(LOCALE_LABEL_KEYS[targetLocale]),
|
|
t,
|
|
};
|
|
}, [dictionary, locale, setLocale]);
|
|
|
|
return <I18nContext.Provider value={value}>{children}</I18nContext.Provider>;
|
|
};
|