The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
feat(sdk,embed-js): Cover displayed column names with content-translations in additional places (#69192)
Timofey Kachalov95875a4166fc
diff --git a/e2e/test-component/scenarios/embedding-sdk/content-translations.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/content-translations.cy.spec.tsxindex 7edca872e26..fa94659ae25 100644--- a/e2e/test-component/scenarios/embedding-sdk/content-translations.cy.spec.tsx+++ b/e2e/test-component/scenarios/embedding-sdk/content-translations.cy.spec.tsx@@ -160,35 +160,143 @@ describe("scenarios > embedding-sdk > content-translations", () => {});});- it("should translate content in filter step", () => {- setupEditor();- mountEditor();+ describe("filter step", () => {+ it("should translate content for numeric field", () => {+ setupEditor();+ mountEditor();- getSdkRoot().within(() => {- popover().within(() => {- cy.findByText("DE-Orders").click();+ getSdkRoot().within(() => {+ popover().within(() => {+ cy.findByText("DE-Orders").click();+ });++ cy.findByText(+ "Füge Filter hinzu, um deine Antwort einzugrenzen",+ ).click();++ popover().within(() => {+ cy.findByText("DE-Total").should("be.visible");++ cy.findByTestId("list-search-field").type("Total");+ cy.findByText("DE-Total").should("not.exist");+ cy.findByText("Total").should("be.visible");++ cy.findByTestId("list-search-field").clear();+ cy.findByText("DE-Total").click();++ cy.findByTestId("number-filter-picker").within(() => {+ cy.findByText("DE-Total").should("be.visible");++ cy.findByPlaceholderText("Min").type("100");+ cy.findByPlaceholderText("Max").type("200");++ // "Add filter" in German locale+ cy.button("Füge einen Filter hinzu").click();+ });+ });++ // "DE-Total is between 100 and 200" - filter display with translated column name+ cy.findByText("DE-Total ist zwischen 100 und 200").should(+ "be.visible",+ );++ // "Visualize" in German locale+ cy.button("Darstellen").click();++ cy.findByTestId("interactive-question-result-toolbar").within(() => {+ cy.findByText("1 Filter").click();+ });++ popover().within(() => {+ cy.findByText("DE-Total ist zwischen 100 und 200").should(+ "be.visible",+ );+ });});+ });- cy.findByText(- "Füge Filter hinzu, um deine Antwort einzugrenzen",- ).click();+ it("should translate column name in second filter step after aggregation step", () => {+ setupEditor();+ mountEditor();- popover().within(() => {- cy.findByText("DE-Total").click();+ getSdkRoot().within(() => {+ popover().within(() => {+ cy.findByText("DE-Orders").click();+ });- cy.findByTestId("number-filter-picker").within(() => {- cy.findByText("DE-Total").should("be.visible");+ cy.findByText("Wähle eine Funktion oder Metrik aus").click();++ popover().within(() => {+ cy.findByText("Anzahl eindeutiger Werte von...").click();+ cy.findByText("DE-Total").click();+ });++ cy.findByText("Wähle eine Spalte für die Gruppierung").click();++ popover().within(() => {+ cy.findByText("DE-Created At").click();+ });++ cy.findAllByTestId("action-buttons")+ .should("have.length", 2)+ .last()+ .within(() => {+ cy.findByText("Filter").click();+ });++ popover().within(() => {+ cy.findByText("DE-Created At: Monat").click();++ cy.findByText("DE-Created At: Monat").should("be.visible");+ cy.findByText("Vorherige 3 Monate").click();+ });++ // "Visualize" in German locale+ cy.button("Darstellen").click();- cy.findByPlaceholderText("Min").type("100");- cy.findByPlaceholderText("Max").type("200");+ cy.findByTestId("interactive-question-result-toolbar").within(() => {+ cy.findByText("1 Filter").click();+ });- // "Add filter" in German locale- cy.button("Füge einen Filter hinzu").click();+ popover().within(() => {+ cy.findByText(+ "DE-Created At: Monat ist in der vorherige 3 monate",+ ).should("be.visible");+ });++ cy.findByTestId("chart-type-selector-button").click();++ popover().within(() => {+ cy.findByText("Tabelle").click();+ });++ cy.findByTestId("table-header").within(() => {+ cy.findByText("DE-Created At: Monat").should("be.visible");});});+ });++ it("should translate content for date field", () => {+ setupEditor();+ mountEditor();++ getSdkRoot().within(() => {+ popover().within(() => {+ cy.findByText("DE-People").click();+ });- // "DE-Total is between 100 and 200" - filter display with translated column name- cy.findByText("DE-Total ist zwischen 100 und 200").should("be.visible");+ cy.findByText(+ "Füge Filter hinzu, um deine Antwort einzugrenzen",+ ).click();++ popover().within(() => {+ cy.findByText("DE-Created At").click();+ });++ cy.findByTestId("clause-popover").within(() => {+ cy.findByText("DE-Created At").should("be.visible");+ });+ });});});@@ -442,7 +550,11 @@ describe("scenarios > embedding-sdk > content-translations", () => {cy.findByTestId("interactive-question-top-toolbar").within(() => {cy.findByText(- "Eindeutige Werte von DE-People - DE-Product → DE-Created At: Monat von DE-People - DE-Product → DE-Created At: Monat",+ // Currently we receive from BE display names with translated static parts and untranslated table/column names+ // It's currently unclear what we should do for such ad-hock question names:+ // - fully translate them, taking in mind that the same translated name is added to the Save Question modal+ // - ignore translation for such names at all+ "Eindeutige Werte von People - Product → Created At: Monat von People - Product → Created At: Monat",).should("be.visible");});@@ -518,8 +630,13 @@ describe("scenarios > embedding-sdk > content-translations", () => {cy.findByText("DE-User ID").click();popover().within(() => {- cy.findByText("DE-Orders").should("exist");+ cy.findByText("DE-Orders").should("be.visible");+ cy.findByTestId("list-search-field").type("Product ID");+ cy.findByText("DE-Product ID").should("not.exist");+ cy.findByText("Product ID").should("be.visible");++ cy.findByTestId("list-search-field").clear();cy.findByText("DE-Product ID").click();});@@ -536,6 +653,139 @@ describe("scenarios > embedding-sdk > content-translations", () => {});});+ describe("RTL locale (Arabic)", () => {+ const setupArabicEditor = () => {+ signInAsAdminAndEnableEmbeddingSdk();++ uploadTranslationDictionaryViaAPI([+ // Table translations+ { locale: "ar", msgid: "Orders", msgstr: "AR-Orders" },+ { locale: "ar", msgid: "Products", msgstr: "AR-Products" },+ { locale: "ar", msgid: "People", msgstr: "AR-People" },+ // Column translations+ { locale: "ar", msgid: "Total", msgstr: "AR-Total" },+ { locale: "ar", msgid: "Tax", msgstr: "AR-Tax" },+ { locale: "ar", msgid: "Quantity", msgstr: "AR-Quantity" },+ { locale: "ar", msgid: "Created At", msgstr: "AR-Created At" },+ { locale: "ar", msgid: "Product ID", msgstr: "AR-Product ID" },+ ]);++ cy.signOut();+ };++ const mountArabicEditor = () => {+ mockAuthProviderAndJwtSignIn();++ mountSdkContent(+ <Flex p="xl">+ <InteractiveQuestion questionId="new" />+ </Flex>,+ {+ sdkProviderProps: {+ locale: "ar",+ },+ },+ );++ // "Pick your starting data" in Arabic+ getSdkRoot().contains("اختر بيانات البداية الخاصة بك");+ };++ it("should translate aggregation-related columns in RTL locale", () => {+ setupArabicEditor();+ mountArabicEditor();++ getSdkRoot().within(() => {+ popover().within(() => {+ cy.findByText("AR-Orders").click();+ });++ // "Pick a function or metric" in Arabic+ cy.findByText("اختر دالة أو مقياسًا").click();++ popover().within(() => {+ // "Sum of ..." in Arabic+ cy.findByText("مجموع ...").click();+ cy.findByText("AR-Total").click();+ });++ // "Pick a column to group by" in Arabic+ cy.findByText("اختر عمودًا لتجميعه بواسطة").click();++ popover().within(() => {+ cy.findByText("AR-Product ID").click();+ });++ // "Visualize" in Arabic+ cy.button("تصور").click();++ cy.findByTestId("interactive-question-result-toolbar").within(() => {+ // "1 summary" in Arabic+ cy.findByText("1 ملخص").click();+ });++ popover().within(() => {+ // "Sum of AR-Total" — aggregation pattern with translated column+ cy.findByText("مجموع AR-Total").should("be.visible");+ });++ cy.findByTestId("chart-type-selector-button").click();++ popover().within(() => {+ // "Table" in Arabic+ cy.findByText("جدول").click();+ });++ cy.findByTestId("table-header").within(() => {+ cy.findByText("AR-Product ID").should("be.visible");+ cy.findByText("مجموع AR-Total").should("be.visible");+ });+ });+ });++ it("should translate filter display name in RTL locale", () => {+ setupArabicEditor();+ mountArabicEditor();++ getSdkRoot().within(() => {+ popover().within(() => {+ cy.findByText("AR-Orders").click();+ });++ // "Add filters to narrow your answer" in Arabic+ cy.findByText("أضف فلتر لحصر إجاباتك").click();++ popover().within(() => {+ cy.findByText("AR-Total").click();++ cy.findByTestId("number-filter-picker").within(() => {+ cy.findByText("AR-Total").should("be.visible");++ cy.findByPlaceholderText("دقيقة").type("100");+ cy.findByPlaceholderText("الأعلى").type("200");++ // "Add filter" in Arabic+ cy.button("إضافة مرشح").click();+ });+ });++ cy.findByText("AR-Total بين 100 و 200").should("be.visible");++ // "Visualize" in Arabic+ cy.button("تصور").click();++ cy.findByTestId("interactive-question-result-toolbar").within(() => {+ // "1 filter" in Arabic+ cy.findByText("1 فلتر").click();+ });++ popover().within(() => {+ cy.findByText("AR-Total بين 100 و 200").should("be.visible");+ });+ });+ });+ });+describe("collection browser", () => {it("should translate collection names, item names, and descriptions", () => {signInAsAdminAndEnableEmbeddingSdk();diff --git a/enterprise/frontend/src/metabase-enterprise/content_translation/index.ts b/enterprise/frontend/src/metabase-enterprise/content_translation/index.tsindex 831a21d7214..ed97277c827 100644--- a/enterprise/frontend/src/metabase-enterprise/content_translation/index.ts+++ b/enterprise/frontend/src/metabase-enterprise/content_translation/index.ts@@ -8,7 +8,6 @@ import {} from "./constants";import { useTranslateContent } from "./use-translate-content";import {- getTranslatedFilterDisplayName,translateColumnDisplayName,translateDisplayNames,useSortByContentTranslation,@@ -48,7 +47,6 @@ export function initializePlugin() {},translateDisplayNames,translateColumnDisplayName,- getTranslatedFilterDisplayName,ContentTranslationConfiguration,});}diff --git a/enterprise/frontend/src/metabase-enterprise/content_translation/utils.ts b/enterprise/frontend/src/metabase-enterprise/content_translation/utils.tsindex f9554981c79..3904c08535f 100644--- a/enterprise/frontend/src/metabase-enterprise/content_translation/utils.ts+++ b/enterprise/frontend/src/metabase-enterprise/content_translation/utils.ts@@ -243,7 +243,57 @@ export const translateColumnDisplayName = ();}- return tc(displayName);+ // First try direct translation of the full display name+ const directTranslation = tc(displayName);+ if (directTranslation !== displayName) {+ return directTranslation;+ }++ // If no direct translation, try space-based iteration for filter patterns+ // (handles cases like "Created At is in the previous 3 months" where only the column name is translatable)+ // TODO: temporary code, in a follow up we will get this from CLJ side++ let longestPrefix = -1;+ let longestPrefixTranslation = "";+ let longestSuffix = -1;+ let longestSuffixTranslation = "";++ for (let i = 0; i < displayName.length; i++) {+ if (displayName[i] !== " ") {+ continue;+ }++ // LTR: column at the start (keep last match = longest prefix)+ const prefix = displayName.substring(0, i);+ const translatedPrefix = translateColumnDisplayName(prefix, tc, patterns);+ if (translatedPrefix !== prefix) {+ longestPrefix = i;+ longestPrefixTranslation = translatedPrefix;+ }++ // RTL: column at the end (keep first match = longest suffix)+ if (longestSuffix === -1) {+ const suffix = displayName.substring(i + 1);+ const translatedSuffix = translateColumnDisplayName(suffix, tc, patterns);+ if (translatedSuffix !== suffix) {+ longestSuffix = i;+ longestSuffixTranslation = translatedSuffix;+ }+ }+ }++ // Prefer LTR match over RTL+ if (longestPrefix > 0) {+ return longestPrefixTranslation + displayName.substring(longestPrefix);+ }++ if (longestSuffix >= 0) {+ return (+ displayName.substring(0, longestSuffix + 1) + longestSuffixTranslation+ );+ }++ return displayName;};const isRecord = (obj: unknown): obj is Record<string, unknown> =>@@ -442,33 +492,3 @@ export const useSortByContentTranslation = () => {[tc],);};--/**- * Translates a filter's display name by translating the column name part.- * The longDisplayName is a pre-formatted string like "Plan is Business"- * where the column name part needs to be translated.- */-export const getTranslatedFilterDisplayName = (- displayName: string,- tc: ContentTranslationFunction,- columnDisplayName?: string,-): string => {- if (!displayName) {- return displayName ?? "";- }-- if (!hasTranslations(tc)) {- return displayName;- }-- if (columnDisplayName) {- const translatedColumnName = tc(columnDisplayName);-- if (translatedColumnName !== columnDisplayName) {- return displayName.replace(columnDisplayName, translatedColumnName);- }- }-- // Fallback to translate the whole string- return tc(displayName);-};diff --git a/enterprise/frontend/src/metabase-enterprise/content_translation/utils.unit.spec.ts b/enterprise/frontend/src/metabase-enterprise/content_translation/utils.unit.spec.tsindex 8a3e0abbd27..f44eed6914e 100644--- a/enterprise/frontend/src/metabase-enterprise/content_translation/utils.unit.spec.ts+++ b/enterprise/frontend/src/metabase-enterprise/content_translation/utils.unit.spec.ts@@ -11,7 +11,6 @@ import { createMockDatasetData } from "metabase-types/api/mocks";import { leaveUntranslated } from "./use-translate-content";import {- getTranslatedFilterDisplayName,translateColumnDisplayName,translateFieldValuesInSeries,} from "./utils";@@ -304,88 +303,6 @@ describe("translateFieldValuesInSeries", () => {});});-describe("getTranslatedFilterDisplayName", () => {- const tcWithPlanTranslation: ContentTranslationFunction = (str) =>- str === "Plan" ? "My new name" : str;-- const tcWithStatusTranslation: ContentTranslationFunction = (str) =>- str === "Status" ? "Estado" : str;-- const tcWithPriceTranslation: ContentTranslationFunction = (str) =>- str === "Price" ? "Preis" : str;-- it("should only replace the first occurrence of column name - 'Plan is Plan' becomes 'My new name is Plan'", () => {- const result = getTranslatedFilterDisplayName(- "Plan is Plan",- tcWithPlanTranslation,- "Plan",- );-- expect(result).toBe("My new name is Plan");- });-- it("should preserve the value when column name appears multiple times", () => {- const result = getTranslatedFilterDisplayName(- "Status is Status",- tcWithStatusTranslation,- "Status",- );-- expect(result).toBe("Estado is Status");- });-- it("should handle column name at the start of the string", () => {- const result = getTranslatedFilterDisplayName(- "Price is between 10 and 20",- tcWithPriceTranslation,- "Price",- );-- expect(result).toBe("Preis is between 10 and 20");- });-- it("should not replace anything if column name is not in display name", () => {- const tcWithQuantityTranslation: ContentTranslationFunction = (str) =>- str === "Quantity" ? "Menge" : str;-- const result = getTranslatedFilterDisplayName(- "Total is greater than 100",- tcWithQuantityTranslation,- "Quantity",- );-- expect(result).toBe("Total is greater than 100");- });-- it("should return displayName unchanged when tc returns same value (no translations)", () => {- const result = getTranslatedFilterDisplayName(- "Total is greater than 100",- mockTranslateWithoutTranslations,- "Total",- );-- expect(result).toBe("Total is greater than 100");- });-- it("should return empty string when displayName is empty", () => {- const result = getTranslatedFilterDisplayName("", tcWithPlanTranslation);-- expect(result).toBe("");- });-- it("should fallback to translating the whole string when no columnDisplayName provided", () => {- const tcWithFullTranslation: ContentTranslationFunction = (str) =>- str === "Some filter" ? "Ein Filter" : str;-- const result = getTranslatedFilterDisplayName(- "Some filter",- tcWithFullTranslation,- );-- expect(result).toBe("Ein Filter");- });-});-describe("translateColumnDisplayName", () => {const tcWithColumnTranslations: ContentTranslationFunction = (str) => {const translations: Record<string, string> = {@@ -747,4 +664,106 @@ describe("translateColumnDisplayName", () => {});});});++ describe("filter display name patterns", () => {+ const tcWithFilterTranslations: ContentTranslationFunction = (str) => {+ const translations: Record<string, string> = {+ Total: "Gesamtsumme",+ Price: "Preis",+ "Created At": "Erstellt am",+ Products: "Produkte",+ Status: "Status",+ };++ return typeof str === "string" ? (translations[str] ?? str) : str;+ };++ it("should translate column name in filter: Total is greater than 100", () => {+ const result = translateColumnDisplayName(+ "Total is greater than 100",+ tcWithFilterTranslations,+ );+ expect(result).toBe("Gesamtsumme is greater than 100");+ });++ it("should translate column name in filter: Created At is in the previous 3 months", () => {+ const result = translateColumnDisplayName(+ "Created At is in the previous 3 months",+ tcWithFilterTranslations,+ );+ expect(result).toBe("Erstellt am is in the previous 3 months");+ });++ it("should translate column name in filter: Status is Active", () => {+ const result = translateColumnDisplayName(+ "Status is Active",+ tcWithFilterTranslations,+ );+ expect(result).toBe("Status is Active");+ });++ it("should translate column name in filter: Price is between 10 and 100", () => {+ const result = translateColumnDisplayName(+ "Price is between 10 and 100",+ tcWithFilterTranslations,+ );+ expect(result).toBe("Preis is between 10 and 100");+ });++ it("should translate column name in filter: Total is empty", () => {+ const result = translateColumnDisplayName(+ "Total is empty",+ tcWithFilterTranslations,+ );+ expect(result).toBe("Gesamtsumme is empty");+ });++ it("should translate column name in filter: Total is not empty", () => {+ const result = translateColumnDisplayName(+ "Total is not empty",+ tcWithFilterTranslations,+ );+ expect(result).toBe("Gesamtsumme is not empty");+ });++ it("should translate column name in filter with contains operator", () => {+ const result = translateColumnDisplayName(+ "Status contains Active",+ tcWithFilterTranslations,+ );+ expect(result).toBe("Status contains Active");+ });++ it("should translate aggregation column in filter: Sum of Total is greater than 100", () => {+ const result = translateColumnDisplayName(+ "Sum of Total is greater than 100",+ tcWithFilterTranslations,+ );+ expect(result).toBe("Sum of Gesamtsumme is greater than 100");+ });++ it("should translate joined column in filter: Products → Price is greater than 50", () => {+ const result = translateColumnDisplayName(+ "Products → Price is greater than 50",+ tcWithFilterTranslations,+ );+ expect(result).toBe("Produkte → Preis is greater than 50");+ });++ it("should translate temporal bucket column in filter: Created At: Month is today", () => {+ const result = translateColumnDisplayName(+ "Created At: Month is today",+ tcWithFilterTranslations,+ );+ expect(result).toBe("Erstellt am: Month is today");+ });++ it("should not translate when column has no translation", () => {+ const result = translateColumnDisplayName(+ "Unknown Column is greater than 100",+ tcWithFilterTranslations,+ );+ expect(result).toBe("Unknown Column is greater than 100");+ });+ });});diff --git a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/Filter/DropdownFilterBadgeList.tsx b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/Filter/DropdownFilterBadgeList.tsxindex 79aea21b508..48f7a12d033 100644--- a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/Filter/DropdownFilterBadgeList.tsx+++ b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/Filter/DropdownFilterBadgeList.tsx@@ -1,6 +1,7 @@import { useDisclosure } from "@mantine/hooks";import { useTranslateContent } from "metabase/i18n/hooks";+import { PLUGIN_CONTENT_TRANSLATION } from "metabase/plugins";import { Group, Popover } from "metabase/ui";import { BadgeListItem } from "../util/BadgeList/BadgeListItem";@@ -24,7 +25,10 @@ const DropdownFilterBadgeListContent = ({<BadgeListItemonClick={open}onRemoveItem={() => item.onRemoveFilter()}- name={tc(item.displayName)}+ name={PLUGIN_CONTENT_TRANSLATION.translateColumnDisplayName(+ item.displayName,+ tc,+ )}/></Popover.Target><Popover.Dropdown>diff --git a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/Filter/FilterBadgeList.tsx b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/Filter/FilterBadgeList.tsxindex 1b9fd981a83..2840f71ece2 100644--- a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/Filter/FilterBadgeList.tsx+++ b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/Filter/FilterBadgeList.tsx@@ -6,6 +6,7 @@ import {} from "embedding-sdk-bundle/components/private/SdkQuestion/components/Filter/hooks/use-filter-data";import { BadgeList } from "embedding-sdk-bundle/components/private/SdkQuestion/components/util/BadgeList";import { useTranslateContent } from "metabase/i18n/hooks";+import { PLUGIN_CONTENT_TRANSLATION } from "metabase/plugins";export const FilterBadgeList = ({onAddItem,@@ -22,7 +23,13 @@ export const FilterBadgeList = ({return (<BadgeListaddButtonLabel={t`Add another filter`}- items={filterItems.map((item) => ({ item, name: tc(item.displayName) }))}+ items={filterItems.map((item) => ({+ item,+ name: PLUGIN_CONTENT_TRANSLATION.translateColumnDisplayName(+ item.displayName,+ tc,+ ),+ }))}onAddItem={onAddItem}onSelectItem={onSelectItem}onRemoveItem={onRemoveItem}diff --git a/frontend/src/embedding-sdk-bundle/lib/sdk-question/get-question-title.ts b/frontend/src/embedding-sdk-bundle/lib/sdk-question/get-question-title.tsindex 10b90ba2fd5..183662ab0b4 100644--- a/frontend/src/embedding-sdk-bundle/lib/sdk-question/get-question-title.ts+++ b/frontend/src/embedding-sdk-bundle/lib/sdk-question/get-question-title.ts@@ -1,5 +1,4 @@import type { ContentTranslationFunction } from "metabase/i18n/types";-import { PLUGIN_CONTENT_TRANSLATION } from "metabase/plugins";import {getAdHocQuestionDescription,shouldRenderAdhocDescription,@@ -26,10 +25,6 @@ export const getQuestionTitle = (const { isNative } = Lib.queryDisplayInfo(query);const adhocDescription = getAdHocQuestionDescription({question,- translateDisplayName: tc- ? (name: string) =>- PLUGIN_CONTENT_TRANSLATION.translateColumnDisplayName(name, tc)- : undefined,});if (diff --git a/frontend/src/metabase/common/components/QueryColumnPicker/QueryColumnPicker.tsx b/frontend/src/metabase/common/components/QueryColumnPicker/QueryColumnPicker.tsxindex ceca8010900..5690f4ab27c 100644--- a/frontend/src/metabase/common/components/QueryColumnPicker/QueryColumnPicker.tsx+++ b/frontend/src/metabase/common/components/QueryColumnPicker/QueryColumnPicker.tsx@@ -14,6 +14,7 @@ import { getColumnGroupIcon } from "metabase/common/utils/column-groups";import { useTranslateContent } from "metabase/i18n/hooks";import type { ColorName } from "metabase/lib/colors/types";import { isNotNull } from "metabase/lib/types";+import { PLUGIN_CONTENT_TRANSLATION } from "metabase/plugins";import {type DefinedClauseName,clausesForMode,@@ -317,8 +318,14 @@ export function QueryColumnPicker({);const renderItemName = useCallback(- (item: Item) => tc(item.displayName),- [tc],+ (item: Item) =>+ isSearching+ ? item.displayName+ : PLUGIN_CONTENT_TRANSLATION.translateColumnDisplayName(+ item.displayName,+ tc,+ ),+ [tc, isSearching],);return (diff --git a/frontend/src/metabase/plugins/oss/content-translation.ts b/frontend/src/metabase/plugins/oss/content-translation.tsindex 1cdebdd7d2d..1a4acaab497 100644--- a/frontend/src/metabase/plugins/oss/content-translation.ts+++ b/frontend/src/metabase/plugins/oss/content-translation.ts@@ -25,11 +25,6 @@ const getDefaultPluginContentTranslation = () => ({displayName: string,_tc: ContentTranslationFunction,): string => displayName,- getTranslatedFilterDisplayName: (- displayName: string,- _tc: ContentTranslationFunction,- _columnDisplayName: string | undefined,- ): string => displayName,useTranslateFieldValuesInHoveredObject: (obj?: HoveredObject | null) => obj,useTranslateSeries: (obj: Series) => obj,useSortByContentTranslation: () => (a: string, b: string) =>diff --git a/frontend/src/metabase/query_builder/components/view/ViewHeader/components/AdHocQuestionDescription/AdHocQuestionDescription.tsx b/frontend/src/metabase/query_builder/components/view/ViewHeader/components/AdHocQuestionDescription/AdHocQuestionDescription.tsxindex aaa815e0370..e34f9cd60d2 100644--- a/frontend/src/metabase/query_builder/components/view/ViewHeader/components/AdHocQuestionDescription/AdHocQuestionDescription.tsx+++ b/frontend/src/metabase/query_builder/components/view/ViewHeader/components/AdHocQuestionDescription/AdHocQuestionDescription.tsx@@ -11,8 +11,6 @@ type AdHocQuestionDescriptionProps = {type GetAdhocQuestionDescriptionProps = {question: Question;- /** Optional function to translate longDisplayName values */- translateDisplayName?: (displayName: string) => string;};export const shouldRenderAdhocDescription = ({@@ -28,7 +26,6 @@ export const shouldRenderAdhocDescription = ({export const getAdHocQuestionDescription = ({question,- translateDisplayName = (name: string) => name,}: GetAdhocQuestionDescriptionProps) => {const query = question.query();const stageIndex = getInfoStageIndex(query);@@ -44,10 +41,9 @@ export const getAdHocQuestionDescription = ({aggregations.length,): aggregations- .map((aggregation) =>- translateDisplayName(+ .map(+ (aggregation) =>Lib.displayInfo(query, stageIndex, aggregation).longDisplayName,- ),).join(t` and `);const breakoutDescription =@@ -60,10 +56,9 @@ export const getAdHocQuestionDescription = ({breakouts.length,): breakouts- .map((breakout) =>- translateDisplayName(+ .map(+ (breakout) =>Lib.displayInfo(query, stageIndex, breakout).longDisplayName,- ),).join(t` and `);diff --git a/frontend/src/metabase/querying/filters/components/FilterPicker/DateFilterPicker/DateFilterPicker.tsx b/frontend/src/metabase/querying/filters/components/FilterPicker/DateFilterPicker/DateFilterPicker.tsxindex a9d74639f6a..975b8e66fc7 100644--- a/frontend/src/metabase/querying/filters/components/FilterPicker/DateFilterPicker/DateFilterPicker.tsx+++ b/frontend/src/metabase/querying/filters/components/FilterPicker/DateFilterPicker/DateFilterPicker.tsx@@ -1,5 +1,7 @@import { useMemo } from "react";+import { useTranslateContent } from "metabase/i18n/hooks";+import { PLUGIN_CONTENT_TRANSLATION } from "metabase/plugins";import { DatePicker } from "metabase/querying/common/components/DatePicker";import type { DatePickerValue } from "metabase/querying/common/types";import { useDateFilter } from "metabase/querying/filters/hooks/use-date-filter";@@ -21,6 +23,8 @@ export function DateFilterPicker({onBack,readOnly,}: FilterPickerWidgetProps) {+ const tc = useTranslateContent();+const columnInfo = useMemo(() => {return Lib.displayInfo(query, stageIndex, column);}, [query, stageIndex, column]);@@ -67,7 +71,10 @@ export function DateFilterPicker({disabled={readOnly}withArrow={!readOnly}>- {columnInfo.longDisplayName}+ {PLUGIN_CONTENT_TRANSLATION.translateColumnDisplayName(+ columnInfo.longDisplayName,+ tc,+ )}</PopoverBackButton>) : null}diff --git a/frontend/src/metabase/querying/filters/components/FilterPicker/FilterColumnPicker/FilterColumnPicker.tsx b/frontend/src/metabase/querying/filters/components/FilterPicker/FilterColumnPicker/FilterColumnPicker.tsxindex 92cbf4276cf..3b59c42cee8 100644--- a/frontend/src/metabase/querying/filters/components/FilterPicker/FilterColumnPicker/FilterColumnPicker.tsx+++ b/frontend/src/metabase/querying/filters/components/FilterPicker/FilterColumnPicker/FilterColumnPicker.tsx@@ -13,6 +13,7 @@ import {import { getColumnGroupIcon } from "metabase/common/utils/column-groups";import { useTranslateContent } from "metabase/i18n/hooks";import { isNotNull } from "metabase/lib/types";+import { PLUGIN_CONTENT_TRANSLATION } from "metabase/plugins";import {type DefinedClauseName,clausesForMode,@@ -109,8 +110,15 @@ export function FilterColumnPicker({);const renderItemName = useCallback(- (item: Item) => tc(item.displayName),- [tc],+ (item: Item) =>+ searchText+ ? // When searching, show the untranslated display name to match the search text+ item.displayName+ : PLUGIN_CONTENT_TRANSLATION.translateColumnDisplayName(+ item.displayName,+ tc,+ ),+ [tc, searchText],);const handleSectionChange = (section: Section) => {diff --git a/frontend/src/metabase/querying/filters/components/FilterPicker/FilterPickerHeader/FilterPickerHeader.tsx b/frontend/src/metabase/querying/filters/components/FilterPicker/FilterPickerHeader/FilterPickerHeader.tsxindex dfa97807449..acf8dac5687 100644--- a/frontend/src/metabase/querying/filters/components/FilterPicker/FilterPickerHeader/FilterPickerHeader.tsx+++ b/frontend/src/metabase/querying/filters/components/FilterPicker/FilterPickerHeader/FilterPickerHeader.tsx@@ -1,6 +1,7 @@import type { ReactNode } from "react";import { useTranslateContent } from "metabase/i18n/hooks";+import { PLUGIN_CONTENT_TRANSLATION } from "metabase/plugins";import { Flex, PopoverBackButton } from "metabase/ui";interface FilterPickerHeaderProps {@@ -26,7 +27,10 @@ export function FilterPickerHeader({disabled={readOnly}withArrow={!readOnly}>- {tc(columnName)}+ {PLUGIN_CONTENT_TRANSLATION.translateColumnDisplayName(+ columnName,+ tc,+ )}</PopoverBackButton>)}{children}diff --git a/frontend/src/metabase/querying/filters/utils/display.ts b/frontend/src/metabase/querying/filters/utils/display.tsindex 3bd80866bc0..640e4bdb0b2 100644--- a/frontend/src/metabase/querying/filters/utils/display.ts+++ b/frontend/src/metabase/querying/filters/utils/display.ts@@ -9,14 +9,9 @@ export const getTranslatedFilterDisplayName = (tc: ContentTranslationFunction,): string => {const displayInfo = Lib.displayInfo(query, stageIndex, filter);- const parts = Lib.filterParts(query, stageIndex, filter);- const columnDisplayName = parts?.column- ? Lib.displayInfo(query, stageIndex, parts.column).displayName- : undefined;- return PLUGIN_CONTENT_TRANSLATION.getTranslatedFilterDisplayName(- displayInfo.longDisplayName ?? "",+ return PLUGIN_CONTENT_TRANSLATION.translateColumnDisplayName(+ displayInfo.longDisplayName,tc,- columnDisplayName,);};diff --git a/frontend/src/metabase/querying/filters/utils/display.unit.spec.ts b/frontend/src/metabase/querying/filters/utils/display.unit.spec.tsdeleted file mode 100644index 8dad32722ae..00000000000--- a/frontend/src/metabase/querying/filters/utils/display.unit.spec.ts+++ /dev/null@@ -1,36 +0,0 @@-import type { ContentTranslationFunction } from "metabase/i18n/types";-import { PLUGIN_CONTENT_TRANSLATION } from "metabase/plugins";--describe("getTranslatedFilterDisplayName (OSS)", () => {- const noopTc: ContentTranslationFunction = (str) => str;-- it("should return displayName unchanged", () => {- const result = PLUGIN_CONTENT_TRANSLATION.getTranslatedFilterDisplayName(- "Total is greater than 100",- noopTc,- "Total",- );-- expect(result).toBe("Total is greater than 100");- });-- it("should return displayName unchanged when columnDisplayName is undefined", () => {- const result = PLUGIN_CONTENT_TRANSLATION.getTranslatedFilterDisplayName(- "Some filter",- noopTc,- undefined,- );-- expect(result).toBe("Some filter");- });-- it("should return empty string when displayName is empty", () => {- const result = PLUGIN_CONTENT_TRANSLATION.getTranslatedFilterDisplayName(- "",- noopTc,- undefined,- );-- expect(result).toBe("");- });-});diff --git a/frontend/src/metabase/querying/notebook/components/JoinStep/JoinConditionColumnPicker/JoinColumnButton/JoinColumnButton.tsx b/frontend/src/metabase/querying/notebook/components/JoinStep/JoinConditionColumnPicker/JoinColumnButton/JoinColumnButton.tsxindex e8d53c077b9..bef4f2de8a5 100644--- a/frontend/src/metabase/querying/notebook/components/JoinStep/JoinConditionColumnPicker/JoinColumnButton/JoinColumnButton.tsx+++ b/frontend/src/metabase/querying/notebook/components/JoinStep/JoinConditionColumnPicker/JoinColumnButton/JoinColumnButton.tsx@@ -3,6 +3,8 @@ import { type Ref, forwardRef, useMemo } from "react";import { t } from "ttag";import { useTranslateContent } from "metabase/i18n/hooks";+import type { ContentTranslationFunction } from "metabase/i18n/types";+import { PLUGIN_CONTENT_TRANSLATION } from "metabase/plugins";import { Text } from "metabase/ui";import * as Lib from "metabase-lib";@@ -87,7 +89,7 @@ function getButtonLabel(query: Lib.Query,stageIndex: number,expression: Lib.ExpressionClause | undefined,- tc: (content: string | null | undefined) => string | null | undefined,+ tc: ContentTranslationFunction,) {if (expression == null) {return t`Pick a column…`;@@ -97,7 +99,10 @@ function getButtonLabel(Lib.isJoinConditionLHSorRHSLiteral(expression) ||Lib.isJoinConditionLHSorRHSColumn(expression)) {- return tc(Lib.displayInfo(query, stageIndex, expression).displayName);+ return PLUGIN_CONTENT_TRANSLATION.translateColumnDisplayName(+ Lib.displayInfo(query, stageIndex, expression).displayName,+ tc,+ );}return t`Custom expression`;diff --git a/frontend/src/metabase/querying/notebook/components/SortStep/SortStep.tsx b/frontend/src/metabase/querying/notebook/components/SortStep/SortStep.tsxindex 538c3c7aed4..4a9b0b29f8c 100644--- a/frontend/src/metabase/querying/notebook/components/SortStep/SortStep.tsx+++ b/frontend/src/metabase/querying/notebook/components/SortStep/SortStep.tsx@@ -3,6 +3,7 @@ import { t } from "ttag";import { QueryColumnPicker } from "metabase/common/components/QueryColumnPicker";import { useTranslateContent } from "metabase/i18n/hooks";+import { PLUGIN_CONTENT_TRANSLATION } from "metabase/plugins";import { Icon } from "metabase/ui";import * as Lib from "metabase-lib";@@ -138,6 +139,7 @@ const SortPopover = ({checkIsColumnSelected={(item) => checkColumnSelected(item, orderByIndex)}onSelect={(column: Lib.ColumnMetadata) => {const isUpdate = orderBy != null;+if (isUpdate) {onUpdateOrderByColumn(orderBy, column);} else {@@ -183,7 +185,12 @@ function SortDisplayName({disabled={disabled}><Icon name={icon} />- <span>{tc(displayInfo.longDisplayName)}</span>+ <span>+ {PLUGIN_CONTENT_TRANSLATION.translateColumnDisplayName(+ displayInfo.longDisplayName,+ tc,+ )}+ </span></button>);}