Skip to content

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

Clean up `metabase/utils/i18n` (#72887)

Romeo Van Snickcc30d8331cb5
diff --git a/frontend/src/metabase/public/LocaleProvider.tsx b/frontend/src/metabase/public/LocaleProvider.tsx
index 1ac8eae104e..2f3a8088793 100644
--- a/frontend/src/metabase/public/LocaleProvider.tsx
+++ b/frontend/src/metabase/public/LocaleProvider.tsx
@@ -7,9 +7,13 @@ import {
} from "react";
import { useSetting } from "metabase/common/hooks";
+import { isEmbeddingSdk } from "metabase/embedding-sdk/config";
import { DatesProvider } from "metabase/ui/components/theme/DatesProvider/DatesProvider";
import { setLocaleHeader } from "metabase/utils/api";
-import { loadLocalization, setUserLocale } from "metabase/utils/i18n";
+import {
+ type LocaleDataWithLanguage,
+ loadLocalization,
+} from "metabase/utils/i18n";
interface LocaleProviderProps {
locale?: string | null;
@@ -118,3 +122,17 @@ export const getLocaleToUse = (
return "en";
};
+
+/**
+ * In static embeddings/public links, there is no user locale, since there is no user in static embeddings/public links.
+ * But we reset the locale to the site locale when `withInstanceLanguage` is called. This breaks static embeddings/public links
+ * since they don't have a user locale. So this function is for them to set the locale from a URL hash as the user locale,
+ * then the translation on some part of FE still works even after `withInstanceLanguage` is called.
+ */
+export function setUserLocale(
+ translationsObject: LocaleDataWithLanguage,
+): void {
+ if (!isEmbeddingSdk()) {
+ window.MetabaseUserLocalization = translationsObject;
+ }
+}
diff --git a/frontend/src/metabase/utils/i18n.ts b/frontend/src/metabase/utils/i18n.ts
index ff30f81e571..a9b73809cb5 100644
--- a/frontend/src/metabase/utils/i18n.ts
+++ b/frontend/src/metabase/utils/i18n.ts
@@ -2,13 +2,14 @@ import dayjs from "dayjs";
import type { LocaleData } from "ttag";
import { addLocale, useLocale } from "ttag";
-import { isEmbeddingSdk } from "metabase/embedding-sdk/config";
import api from "metabase/utils/api";
import { DAY_OF_WEEK_OPTIONS } from "metabase/utils/date-time";
import MetabaseSettings from "metabase/utils/settings";
import type { DayOfWeekId } from "metabase-types/api";
-type LocaleDataWithLanguage = LocaleData & { headers: { language: string } };
+export type LocaleDataWithLanguage = LocaleData & {
+ headers: { language: string };
+};
// note this won't refresh strings that are evaluated at load time
export async function loadLocalization(
@@ -190,19 +191,3 @@ if (window.MetabaseSiteLocalization) {
if (window.MetabaseUserLocalization) {
setLocalization(window.MetabaseUserLocalization);
}
-
-/**
- * In static embeddings/public links, there is no user locale, since there is no user in static embeddings/public links.
- * But we reset the locale to the site locale when `withInstanceLanguage` is called. This breaks static embeddings/public links
- * since they don't have a user locale. So this function is for them to set the locale from a URL hash as the user locale,
- * then the translation on some part of FE still works even after `withInstanceLanguage` is called.
- *
- * @param translationsObject A translated object with the same structure as the one produced in `loadLocalization` function.
- */
-export function setUserLocale(
- translationsObject: LocaleDataWithLanguage,
-): void {
- if (!isEmbeddingSdk()) {
- window.MetabaseUserLocalization = translationsObject;
- }
-}