Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Move the frontend locale context into common/hooks/use-locale (#82000)

Fraser75bd580d9114
diff --git a/frontend/src/metabase/common/hooks/use-locale/frontend-locale-context.ts b/frontend/src/metabase/common/hooks/use-locale/frontend-locale-context.ts
new file mode 100644
index 00000000000..4f7349658b2
--- /dev/null
+++ b/frontend/src/metabase/common/hooks/use-locale/frontend-locale-context.ts
@@ -0,0 +1,7 @@
+import { type Context, createContext } from "react";
+
+/** context for the locale used in the sdk and in public/static from the #locale parameter */
+export const FrontendLocaleContext = createContext({}) as unknown as Context<{
+ locale: string | null;
+ isLocaleLoading: boolean;
+}>;
diff --git a/frontend/src/metabase/common/hooks/use-locale/use-locale.ts b/frontend/src/metabase/common/hooks/use-locale/use-locale.ts
index 2a052f0a089..348c6df1ed1 100644
--- a/frontend/src/metabase/common/hooks/use-locale/use-locale.ts
+++ b/frontend/src/metabase/common/hooks/use-locale/use-locale.ts
@@ -2,9 +2,10 @@ import { useContext } from "react";
import { useInstanceLocale } from "metabase/common/hooks/use-instance-locale";
import { getUser } from "metabase/current-user";
-import { FrontendLocaleContext } from "metabase/embedding/LocaleProvider";
import { useSelector } from "metabase/redux";
+import { FrontendLocaleContext } from "./frontend-locale-context";
+
/** Get the user's locale or, if that has not been set, the instance locale
*
* WARNING: Certain locale codes, like 'pt_BR', are not supported by the native
diff --git a/frontend/src/metabase/embedding/LocaleProvider.tsx b/frontend/src/metabase/embedding/LocaleProvider.tsx
index 3e1dc0e4be6..80104016b2a 100644
--- a/frontend/src/metabase/embedding/LocaleProvider.tsx
+++ b/frontend/src/metabase/embedding/LocaleProvider.tsx
@@ -1,13 +1,8 @@
-import {
- type Context,
- type PropsWithChildren,
- createContext,
- useEffect,
- useState,
-} from "react";
+import { type PropsWithChildren, useEffect, useState } from "react";
import { setLocaleHeader } from "metabase/api/client";
import { loadLocalization } from "metabase/api/localization";
+import { FrontendLocaleContext } from "metabase/common/hooks/use-locale/frontend-locale-context";
import { isEmbeddingSdk } from "metabase/embedding-sdk/config";
import { useSetting } from "metabase/settings";
import { DatesProvider } from "metabase/ui/components/theme/DatesProvider/DatesProvider";
@@ -18,12 +13,6 @@ interface LocaleProviderProps {
shouldWaitForLocale?: boolean;
}
-/** context for the locale used in the sdk and in public/static from the #locale parameter */
-export const FrontendLocaleContext = createContext({}) as unknown as Context<{
- locale: string | null;
- isLocaleLoading: boolean;
-}>;
-
export const LocaleProvider = ({
children,
locale,