From 37c8418f0e643317f04bee66a8188f1aed37323b Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 20 Jan 2025 15:40:32 +1100 Subject: [PATCH] Pass locale information through to plugins (#8917) --- src/frontend/src/components/plugins/PluginContext.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/frontend/src/components/plugins/PluginContext.tsx b/src/frontend/src/components/plugins/PluginContext.tsx index e902b07d81..075193d7e4 100644 --- a/src/frontend/src/components/plugins/PluginContext.tsx +++ b/src/frontend/src/components/plugins/PluginContext.tsx @@ -29,6 +29,8 @@ import { type UserStateProps, useUserState } from '../../states/UserState'; * @param navigate - The navigation function (see react-router-dom) * @param theme - The current Mantine theme * @param colorScheme - The current Mantine color scheme (e.g. 'light' / 'dark') + * @param host - The current host URL + * @param locale - The current locale string (e.g. 'en' / 'de') * @param context - Any additional context data which may be passed to the plugin */ export type InvenTreeContext = { @@ -38,6 +40,7 @@ export type InvenTreeContext = { userSettings: SettingsStateProps; globalSettings: SettingsStateProps; host: string; + locale: string; navigate: NavigateFunction; theme: MantineTheme; colorScheme: MantineColorScheme; @@ -45,7 +48,7 @@ export type InvenTreeContext = { }; export const useInvenTreeContext = () => { - const host = useLocalState((s) => s.host); + const [locale, host] = useLocalState((s) => [s.language, s.host]); const navigate = useNavigate(); const user = useUserState(); const { colorScheme } = useMantineColorScheme(); @@ -57,6 +60,7 @@ export const useInvenTreeContext = () => { return { user: user, host: host, + locale: locale, api: api, queryClient: queryClient, navigate: navigate, @@ -69,6 +73,7 @@ export const useInvenTreeContext = () => { user, host, api, + locale, queryClient, navigate, globalSettings,