Skip to content

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

feat(sdk, embed-js): Add joined tables/temporal/bins content translations for aggregations and breakouts and question title (#68954)

Timofey Kachalov9bacef5fc144
diff --git a/e2e/support/helpers/e2e-notebook-helpers.ts b/e2e/support/helpers/e2e-notebook-helpers.ts
index 8ca2afcb94e..a1a641b6e46 100644
--- a/e2e/support/helpers/e2e-notebook-helpers.ts
+++ b/e2e/support/helpers/e2e-notebook-helpers.ts
@@ -507,3 +507,19 @@ function getSortItems(stageIndex: number) {
export function clauseStepPopover() {
return popover({ testId: "clause-popover" });
}
+
+export function openPopoverFromDefaultBucketSize(
+ column: string,
+ bucket: string,
+) {
+ cy.findAllByTestId("dimension-list-item")
+ .filter(`:contains("${column}")`)
+ .as("targetListItem")
+ .realHover()
+ .within(() => {
+ cy.findByTestId("dimension-list-item-binning")
+ .as("listItemSelectedBinning")
+ .should("contain", bucket)
+ .click();
+ });
+}
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.tsx
index 7d05bae3a0b..7edca872e26 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
@@ -4,7 +4,11 @@ import {
} from "@metabase/embedding-sdk-react";
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
-import { createQuestion, popover } from "e2e/support/helpers";
+import {
+ createQuestion,
+ openPopoverFromDefaultBucketSize,
+ popover,
+} from "e2e/support/helpers";
import { uploadTranslationDictionaryViaAPI } from "e2e/support/helpers/e2e-content-translation-helpers";
import { getSdkRoot } from "e2e/support/helpers/e2e-embedding-sdk-helpers";
import {
@@ -91,6 +95,7 @@ describe("scenarios > embedding-sdk > content-translations", () => {
// Table translations
{ locale: "de", msgid: "Orders", msgstr: "DE-Orders" },
{ locale: "de", msgid: "Products", msgstr: "DE-Products" },
+ { locale: "de", msgid: "Product", msgstr: "DE-Product" },
{ locale: "de", msgid: "People", msgstr: "DE-People" },
{ locale: "de", msgid: "Reviews", msgstr: "DE-Reviews" },
// Column translations
@@ -104,6 +109,8 @@ describe("scenarios > embedding-sdk > content-translations", () => {
{ locale: "de", msgid: "User ID", msgstr: "DE-User ID" },
{ locale: "de", msgid: "Subtotal", msgstr: "DE-Subtotal" },
{ locale: "de", msgid: "Address", msgstr: "DE-Address" },
+ { locale: "de", msgid: "Latitude", msgstr: "DE-Latitude" },
+ { locale: "de", msgid: "Longitude", msgstr: "DE-Longitude" },
]);
cy.signOut();
@@ -131,25 +138,25 @@ describe("scenarios > embedding-sdk > content-translations", () => {
setupEditor();
mountEditor();
- popover().within(() => {
- // Use .should("exist") instead of .should("be.visible") because
- // elements in scrollable popovers might be below the fold
- cy.findByText("DE-Products").should("exist");
+ getSdkRoot().within(() => {
+ popover().within(() => {
+ // Use .should("exist") instead of .should("be.visible") because
+ // elements in scrollable popovers might be below the fold
+ cy.findByText("DE-Products").should("exist");
- cy.findByText("DE-Orders").click();
- });
+ cy.findByText("DE-Orders").click();
+ });
- getSdkRoot().within(() => {
// "Add a filter to narrow down your answer" in German locale
cy.findByText(
"Füge Filter hinzu, um deine Antwort einzugrenzen",
).click();
- });
- popover().within(() => {
- cy.findByText("DE-Total").should("exist");
- cy.findByText("DE-Tax").should("exist");
- cy.findByText("DE-Quantity").should("exist");
+ popover().within(() => {
+ cy.findByText("DE-Total").should("exist");
+ cy.findByText("DE-Tax").should("exist");
+ cy.findByText("DE-Quantity").should("exist");
+ });
});
});
@@ -157,33 +164,29 @@ describe("scenarios > embedding-sdk > content-translations", () => {
setupEditor();
mountEditor();
- 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").click();
- });
+ popover().within(() => {
+ cy.findByText("DE-Total").click();
- popover().within(() => {
- cy.findByTestId("number-filter-picker").within(() => {
- cy.findByText("DE-Total").should("be.visible");
+ cy.findByTestId("number-filter-picker").within(() => {
+ cy.findByText("DE-Total").should("be.visible");
- cy.findByPlaceholderText("Min").type("100");
- cy.findByPlaceholderText("Max").type("200");
+ cy.findByPlaceholderText("Min").type("100");
+ cy.findByPlaceholderText("Max").type("200");
- // "Add filter" in German locale
- cy.button("Füge einen Filter hinzu").click();
+ // "Add filter" in German locale
+ cy.button("Füge einen Filter hinzu").click();
+ });
});
- });
- getSdkRoot().within(() => {
// "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");
});
@@ -193,37 +196,33 @@ describe("scenarios > embedding-sdk > content-translations", () => {
setupEditor();
mountEditor();
- popover().within(() => {
- cy.findByText("DE-Orders").click();
- });
-
getSdkRoot().within(() => {
+ popover().within(() => {
+ cy.findByText("DE-Orders").click();
+ });
+
// "Pick a function or metric" in German locale
cy.findByText("Wähle eine Funktion oder Metrik aus").click();
- });
- popover().within(() => {
- // "Sum of..." in German locale
- cy.findByText("Summe von...").click();
+ popover().within(() => {
+ // "Sum of..." in German locale
+ cy.findByText("Summe von...").click();
- cy.findByText("DE-Orders").should("exist");
- cy.findByText("DE-Discount").should("exist");
- });
+ cy.findByText("DE-Orders").should("exist");
+ cy.findByText("DE-Discount").should("exist");
- popover().within(() => {
- cy.findByText("DE-Total").click();
- });
+ cy.findByText("DE-Total").click();
+ });
- getSdkRoot().within(() => {
// "Pick a column to group by" in German locale
cy.findByText("Wähle eine Spalte für die Gruppierung").click();
- });
- popover().within(() => {
- cy.findByText("DE-Orders").should("exist");
- cy.findByText("DE-Product ID").should("exist");
+ popover().within(() => {
+ cy.findByText("DE-Orders").should("exist");
+ cy.findByText("DE-Product ID").should("exist");
- cy.findByText("DE-Total").click();
+ cy.findByText("DE-Total").click();
+ });
});
});
@@ -231,28 +230,24 @@ describe("scenarios > embedding-sdk > content-translations", () => {
setupEditor();
mountEditor();
- popover().within(() => {
- cy.findByText("DE-Orders").click();
- });
-
getSdkRoot().within(() => {
+ popover().within(() => {
+ cy.findByText("DE-Orders").click();
+ });
+
cy.findByText("Wähle eine Funktion oder Metrik aus").click();
- });
- popover().within(() => {
- cy.findByText("Summe von...").click();
- cy.findByText("DE-Total").click();
- });
+ popover().within(() => {
+ cy.findByText("Summe von...").click();
+ cy.findByText("DE-Total").click();
+ });
- getSdkRoot().within(() => {
cy.findByText("Wähle eine Spalte für die Gruppierung").click();
- });
- popover().within(() => {
- cy.findByText("DE-Product ID").click();
- });
+ popover().within(() => {
+ cy.findByText("DE-Product ID").click();
+ });
- getSdkRoot().within(() => {
// "Visualize" in German locale
cy.button("Darstellen").click();
@@ -282,26 +277,221 @@ describe("scenarios > embedding-sdk > content-translations", () => {
});
});
- it("should translate content in sort step", () => {
+ it("should translate columns with temporal bucket patterns", () => {
setupEditor();
mountEditor();
- popover().within(() => {
- cy.findByText("DE-Orders").click();
+ getSdkRoot().within(() => {
+ popover().within(() => {
+ cy.findByText("DE-Orders").click();
+ });
+
+ 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();
+ });
+
+ // "Visualize" in German locale
+ cy.button("Darstellen").click();
+
+ cy.findByTestId("interactive-question-result-toolbar").within(() => {
+ // "1 grouping" in German locale
+ cy.findByText("1 Gruppierung").click();
+ });
+
+ popover().within(() => {
+ cy.findByText("DE-Created At").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 columns with binning patterns", () => {
+ setupEditor();
+ mountEditor();
getSdkRoot().within(() => {
- // "Sort" in German locale
- cy.button("Sortieren").click();
+ popover().within(() => {
+ // Select People table which has Latitude/Longitude fields
+ cy.findByText("DE-People").click();
+ });
+
+ cy.findByText("Wähle eine Funktion oder Metrik aus").click();
+
+ popover().within(() => {
+ cy.findByText("Anzahl eindeutiger Werte von...").click();
+ cy.findByText("DE-Latitude").click();
+ });
+
+ cy.findByTestId("step-summarize-0-0").within(() => {
+ cy.findByText("Eindeutige Werte von DE-Latitude").should(
+ "be.visible",
+ );
+ });
+
+ cy.findByText("Wähle eine Spalte für die Gruppierung").click();
+
+ popover().within(() => {
+ openPopoverFromDefaultBucketSize(
+ "DE-Latitude",
+ "Automatische Klasseneinteilung",
+ );
+
+ cy.findByText("Eine Klasse pro 10 Grad").click();
+ });
+
+ cy.findByText("DE-Latitude: 10°").should("be.visible");
+
+ // "Visualize" in German locale
+ cy.button("Darstellen").click();
+
+ cy.findByTestId("interactive-question-result-toolbar").within(() => {
+ // "1 grouping" in German locale
+ cy.findByText("1 Gruppierung").click();
+ });
+
+ popover().within(() => {
+ cy.findByText("DE-Latitude").should("be.visible");
+ });
+
+ cy.findByTestId("chart-type-selector-button").click();
+
+ popover().within(() => {
+ cy.findByText("Tabelle").click();
+ });
+
+ cy.findByTestId("table-header").within(() => {
+ cy.findByText("DE-Latitude: 10°").should("be.visible");
+ });
});
+ });
- popover().within(() => {
- cy.findByText("DE-User ID").should("exist");
+ it("should translate aggregation-related columns for joined tables", () => {
+ setupEditor();
+ mountEditor();
+
+ getSdkRoot().within(() => {
+ popover().within(() => {
+ cy.findByText("DE-Orders").click();
+ });
+
+ // "Join data" in German locale
+ cy.button("Daten verknüpfen").click();
+
+ popover().within(() => {
+ cy.findByText("DE-People").click();
+ });
+
+ cy.findByText("DE-User ID").click();
- cy.findByText("DE-Total").click();
+ popover().within(() => {
+ cy.findByText("DE-Product ID").click();
+ });
+
+ cy.findByText("DE-ID").click();
+
+ popover().within(() => {
+ cy.findByText("DE-ID").click();
+ });
+
+ cy.findByText("Wähle eine Funktion oder Metrik aus").click();
+
+ popover().within(() => {
+ cy.findByText("Anzahl eindeutiger Werte von...").click();
+ cy.findByText("DE-People").click();
+
+ cy.findByText("DE-Created At").click();
+ });
+
+ cy.findByTestId("step-summarize-0-0").within(() => {
+ cy.findByText(
+ "Eindeutige Werte von DE-People - DE-Product → DE-Created At: Monat",
+ ).should("be.visible");
+ });
+
+ cy.findByText("Wähle eine Spalte für die Gruppierung").click();
+
+ popover().within(() => {
+ cy.findByText("DE-People").click();
+ cy.findByText("DE-Created At").click();
+ });
+
+ cy.findByText("DE-People - DE-Product → DE-Created At: Monat").should(
+ "be.visible",
+ );
+
+ // "Visualize" in German locale
+ cy.button("Darstellen").click();
+
+ 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",
+ ).should("be.visible");
+ });
+
+ cy.findByTestId("interactive-question-result-toolbar").within(() => {
+ // "1 grouping" in German locale
+ cy.findByText("1 Gruppierung").click();
+ });
+
+ popover().within(() => {
+ cy.findByText("DE-People - DE-Product → DE-Created At").should(
+ "be.visible",
+ );
+ });
+
+ cy.findByTestId("chart-type-selector-button").click();
+
+ popover().within(() => {
+ cy.findByText("Tabelle").click();
+ });
+
+ cy.findByTestId("table-header").within(() => {
+ cy.findByText("DE-People - DE-Product → DE-Created At: Monat").should(
+ "be.visible",
+ );
+ cy.findByText(
+ "Eindeutige Werte von DE-People - DE-Product → DE-Created At: Monat",
+ ).should("be.visible");
+ });
});
+ });
+
+ it("should translate content in sort step", () => {
+ setupEditor();
+ mountEditor();
getSdkRoot().within(() => {
+ popover().within(() => {
+ cy.findByText("DE-Orders").click();
+ });
+
+ // "Sort" in German locale
+ cy.button("Sortieren").click();
+
+ popover().within(() => {
+ cy.findByText("DE-User ID").should("exist");
+
+ cy.findByText("DE-Total").click();
+ });
+
cy.findByText("DE-Total").should("be.visible");
});
});
@@ -310,44 +500,36 @@ describe("scenarios > embedding-sdk > content-translations", () => {
setupEditor();
mountEditor();
- popover().within(() => {
- cy.findByText("DE-Orders").click();
- });
-
getSdkRoot().within(() => {
+ popover().within(() => {
+ cy.findByText("DE-Orders").click();
+ });
+
// "Join data" in German locale
cy.button("Daten verknüpfen").click();
- });
- getSdkRoot().within(() => {
// "Left table" in German locale
cy.findByLabelText("Linke Tabelle").should("have.text", "DE-Orders");
- });
- popover().within(() => {
- cy.findByText("DE-People").click();
- });
+ popover().within(() => {
+ cy.findByText("DE-People").click();
+ });
- getSdkRoot().within(() => {
cy.findByText("DE-User ID").click();
- });
- popover().within(() => {
- cy.findByText("DE-Orders").should("exist");
+ popover().within(() => {
+ cy.findByText("DE-Orders").should("exist");
- cy.findByText("DE-Product ID").click();
- });
+ cy.findByText("DE-Product ID").click();
+ });
- getSdkRoot().within(() => {
cy.findByText("DE-ID").click();
- });
- popover().within(() => {
- cy.findByText("DE-People").should("exist");
- cy.findByText("DE-Address").click();
- });
+ popover().within(() => {
+ cy.findByText("DE-People").should("exist");
+ cy.findByText("DE-Address").click();
+ });
- getSdkRoot().within(() => {
cy.findByText("DE-Product ID").should("be.visible");
cy.findByText("DE-Address").should("be.visible");
});
diff --git a/e2e/test/scenarios/binning/correctness/longitude.cy.spec.js b/e2e/test/scenarios/binning/correctness/longitude.cy.spec.js
index 5375454ad77..87b4e9a6fdc 100644
--- a/e2e/test/scenarios/binning/correctness/longitude.cy.spec.js
+++ b/e2e/test/scenarios/binning/correctness/longitude.cy.spec.js
@@ -1,3 +1,5 @@
+import { openPopoverFromDefaultBucketSize } from "e2e/support/helpers";
+
const { H } = cy;
import { LONGITUDE_OPTIONS } from "./shared/constants";
@@ -59,19 +61,6 @@ describe("scenarios > binning > correctness > longitude", () => {
});
});
-function openPopoverFromDefaultBucketSize(column, bucket) {
- cy.findAllByTestId("dimension-list-item")
- .filter(`:contains("${column}")`)
- .as("targetListItem")
- .realHover()
- .within(() => {
- cy.findByTestId("dimension-list-item-binning")
- .as("listItemSelectedBinning")
- .should("contain", bucket)
- .click();
- });
-}
-
function getTitle(title) {
cy.findByText(title);
}
diff --git a/enterprise/frontend/src/embedding-sdk-ee/metabot/QuestionTitle.tsx b/enterprise/frontend/src/embedding-sdk-ee/metabot/QuestionTitle.tsx
index 650545eeea9..a0b97fe0d3d 100644
--- a/enterprise/frontend/src/embedding-sdk-ee/metabot/QuestionTitle.tsx
+++ b/enterprise/frontend/src/embedding-sdk-ee/metabot/QuestionTitle.tsx
@@ -1,10 +1,12 @@
-import { getQuestionTitle } from "embedding-sdk-bundle/components/private/QuestionTitle";
import { useSdkQuestionContext } from "embedding-sdk-bundle/components/private/SdkQuestion/context";
+import { getQuestionTitle } from "embedding-sdk-bundle/lib/sdk-question/get-question-title";
+import { useTranslateContent } from "metabase/i18n/hooks";
import { Text } from "metabase/ui";
export function QuestionTitle() {
const { question } = useSdkQuestionContext();
- const titleText = getQuestionTitle({ question });
+ const tc = useTranslateContent();
+ const titleText = getQuestionTitle(question, tc);
if (titleText === null) {
return null;
diff --git a/enterprise/frontend/src/metabase-enterprise/content_translation/index.ts b/enterprise/frontend/src/metabase-enterprise/content_translation/index.ts
index 952dff0d411..831a21d7214 100644
--- a/enterprise/frontend/src/metabase-enterprise/content_translation/index.ts
+++ b/enterprise/frontend/src/metabase-enterprise/content_translation/index.ts
@@ -9,7 +9,7 @@ import {
import { useTranslateContent } from "./use-translate-content";
import {
getTranslatedFilterDisplayName,
- translateAggregationDisplayName,
+ translateColumnDisplayName,
translateDisplayNames,
useSortByContentTranslation,
useTranslateFieldValuesInHoveredObject,
@@ -47,7 +47,7 @@ export function initializePlugin() {
);
},
translateDisplayNames,
- translateAggregationDisplayName,
+ translateColumnDisplayName,
getTranslatedFilterDisplayName,
ContentTranslationConfiguration,
});
diff --git a/enterprise/frontend/src/metabase-enterprise/content_translation/utils.ts b/enterprise/frontend/src/metabase-enterprise/content_translation/utils.ts
index adb7cbbe44b..f9554981c79 100644
--- a/enterprise/frontend/src/metabase-enterprise/content_translation/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/content_translation/utils.ts
@@ -7,6 +7,7 @@ import _ from "underscore";
import type { ContentTranslationFunction } from "metabase/i18n/types";
import { isCartesianChart } from "metabase/visualizations";
import type { HoveredObject } from "metabase/visualizations/types";
+import * as Lib from "metabase-lib";
import type {
DictionaryArray,
MaybeTranslatedSeries,
@@ -65,15 +66,22 @@ export const translateContentString: TranslateContentStringFunction = (
return msgstr;
};
-export type AggregationPattern = (value: string) => string;
+export type ColumnDisplayNamePattern = (value: string) => string;
/**
- * Patterns for aggregation display names.
- * These must match the patterns used in the backend (metabase.lib.aggregation).
+ * Patterns for column display names.
+ * These must match the patterns used in the backend:
+ * - Aggregations: metabase.lib.aggregation
+ * - Binning: metabase.lib.binning
+ * - Temporal buckets: metabase.lib.temporal_bucket
+ *
* Each pattern is a function that takes a column name and returns the full display name.
* More specific patterns must come before less specific ones.
*/
-const AGGREGATION_PATTERNS: AggregationPattern[] = [
+const COLUMN_DISPLAY_NAME_PATTERNS: ColumnDisplayNamePattern[] = [
+ // Aggregation patterns (from metabase.lib.aggregation)
+ // More specific patterns must come first
+ (value: string) => t`Sum of ${value} matching condition`,
(value: string) => t`Average of ${value}`,
(value: string) => t`Count of ${value}`,
(value: string) => t`Cumulative count of ${value}`,
@@ -83,17 +91,39 @@ const AGGREGATION_PATTERNS: AggregationPattern[] = [
(value: string) => t`Median of ${value}`,
(value: string) => t`Min of ${value}`,
(value: string) => t`Standard deviation of ${value}`,
- (value: string) => t`Sum of ${value} matching condition`,
(value: string) => t`Sum of ${value}`,
(value: string) => t`Variance of ${value}`,
+
+ // Binning patterns (from metabase.lib.binning)
+ // Auto binned (default strategy)
+ (value: string) => t`${value}: Auto binned`,
+ // Numeric binning strategies: num-bins (10, 50, 100)
+ (value: string) => `${value}: 10 bins`,
+ (value: string) => `${value}: 50 bins`,
+ (value: string) => `${value}: 100 bins`,
+ // Coordinate binning strategies: bin-width with degree symbol
+ (value: string) => `${value}: 0.1°`,
+ (value: string) => `${value}: 1°`,
+ (value: string) => `${value}: 10°`,
+ (value: string) => `${value}: 20°`,
+ (value: string) => `${value}: 0.05°`,
+ (value: string) => `${value}: 0.01°`,
+ (value: string) => `${value}: 0.005°`,
+
+ // Temporal bucket patterns (from metabase.lib.temporal_bucket)
+ // Generated dynamically using the same Lib functions the backend uses,
+ // ensuring the translated suffixes match (e.g., "Month" → "Monat" in German)
+ ...Lib.availableTemporalUnits().map(
+ (unit) => (value: string) => `${value}: ${Lib.describeTemporalUnit(unit)}`,
+ ),
];
// Unique marker to find where the value placeholder is in a pattern
const VALUE_MARKER = "\u0000";
/**
- * Translates an aggregation column display name by recursively parsing the
- * aggregation pattern and translating the inner column name.
+ * Translates a column display name by recursively parsing known patterns
+ * (aggregations, binning, temporal buckets) and translating the inner column name.
*
* Handles patterns where the value can be:
* - At the start: "{value} של סכום" (Hebrew, right-to-left)
@@ -101,14 +131,27 @@ const VALUE_MARKER = "\u0000";
* - Wrapped: "Somme de {value} totale" (hypothetical)
*
* Examples:
- * - "Total" => tc("Total") (no aggregation pattern matched)
+ * - "Total" => tc("Total") (no pattern matched)
* - "Sum of Total" => t`Sum of ${tc("Total")}`
* - "Sum of Min of Total" => t`Sum of ${t`Min of ${tc("Total")}`}`
+ * - "Created At: Month" => t`${tc("Created At")}: Month`
+ * - "Total: Auto binned" => t`${tc("Total")}: Auto binned`
*/
-export const translateAggregationDisplayName = (
+// Separator used for binning and temporal bucket suffixes (e.g., "Total: Day", "Total: 10 bins")
+const COLON_SEPARATOR = ": ";
+
+// Separator used for joined table column names (e.g., "Products → Created At")
+// See: src/metabase/lib/field.cljc - field-display-name-add-fk-or-join-display-name
+const JOIN_SEPARATOR = " → ";
+
+// Separator used for implicit join aliases (e.g., "People - Product")
+// See: src/metabase/lib/join.cljc - standard-join-name
+const IMPLICIT_JOIN_SEPARATOR = " - ";
+
+export const translateColumnDisplayName = (
displayName: string,
tc: ContentTranslationFunction,
- patterns: AggregationPattern[] = AGGREGATION_PATTERNS,
+ patterns: ColumnDisplayNamePattern[] = COLUMN_DISPLAY_NAME_PATTERNS,
): string => {
if (!hasTranslations(tc)) {
return displayName;
@@ -131,13 +174,75 @@ export const translateAggregationDisplayName = (
if (innerStart <= innerEnd) {
const innerPart = displayName.substring(innerStart, innerEnd);
- return pattern(
- translateAggregationDisplayName(innerPart, tc, patterns),
- );
+ return pattern(translateColumnDisplayName(innerPart, tc, patterns));
}
}
}
+ // Handle colon-separated patterns for backend-translated temporal bucket suffixes
+ // (e.g., "Created At: Monat" where "Monat" is already translated by the backend).
+ // Explicit binning patterns are already handled above in COLUMN_DISPLAY_NAME_PATTERNS.
+ const colonIndex = displayName.lastIndexOf(COLON_SEPARATOR);
+
+ if (colonIndex > 0) {
+ const columnPart = displayName.substring(0, colonIndex);
+ const suffixPart = displayName.substring(
+ colonIndex + COLON_SEPARATOR.length,
+ );
+
+ // Only split if the column part actually has a translation.
+ // This avoids incorrectly splitting column names that contain ": " literally.
+ const translatedColumn = translateColumnDisplayName(
+ columnPart,
+ tc,
+ patterns,
+ );
+ if (translatedColumn !== columnPart) {
+ return translatedColumn + COLON_SEPARATOR + suffixPart;
+ }
+ }
+
+ // Handle joined table column names like "Products → Created At"
+ // or nested joins like "Orders → Products → Created At: Monat"
+ // We split on the FIRST arrow to preserve nested patterns in the column part.
+ const arrowIndex = displayName.indexOf(JOIN_SEPARATOR);
+ if (arrowIndex > 0) {
+ const joinAliasPart = displayName.substring(0, arrowIndex);
+ const columnPart = displayName.substring(
+ arrowIndex + JOIN_SEPARATOR.length,
+ );
+
+ // The join alias may contain an implicit join separator " - " (e.g., "People - Product")
+ // which combines the joined table name and the FK field name.
+ // We only split on " - " here (within the arrow context) to avoid incorrectly
+ // splitting question names or other strings that contain dashes.
+ const dashIndex = joinAliasPart.indexOf(IMPLICIT_JOIN_SEPARATOR);
+ let translatedJoinAlias: string;
+ if (dashIndex > 0) {
+ const tablePart = joinAliasPart.substring(0, dashIndex);
+ const fkPart = joinAliasPart.substring(
+ dashIndex + IMPLICIT_JOIN_SEPARATOR.length,
+ );
+ translatedJoinAlias =
+ translateColumnDisplayName(tablePart, tc, patterns) +
+ IMPLICIT_JOIN_SEPARATOR +
+ translateColumnDisplayName(fkPart, tc, patterns);
+ } else {
+ translatedJoinAlias = translateColumnDisplayName(
+ joinAliasPart,
+ tc,
+ patterns,
+ );
+ }
+
+ // columnPart may have more patterns (arrows, colons, aggregations)
+ return (
+ translatedJoinAlias +
+ JOIN_SEPARATOR +
+ translateColumnDisplayName(columnPart, tc, patterns)
+ );
+ }
+
return tc(displayName);
};
@@ -165,13 +270,13 @@ export const translateDisplayNames = <T>(
fieldsToTranslate.includes(key as string) &&
typeof value === "string";
- // We can't detect if an element is an aggregation-related or not here.
+ // We can't detect if an element has a special pattern (aggregation, binning, temporal bucket) or not here.
// We can't rely on the `source` field as for cases when a question containing aggregations is a base for another question,
// the `source` field contains the `fields` value, not the `aggregation` one.
- // As the solution, we always try to translate the display name as an aggregation one,
- // and inside `translateAggregationDisplayName` we fallback to regular tc() call if no aggregation pattern is matched.
+ // As the solution, we always try to translate the display name using pattern matching,
+ // and inside `translateColumnDisplayName` we fallback to regular tc() call if no pattern is matched.
const newValue = shouldTranslate
- ? translateAggregationDisplayName(value as string, tc)
+ ? translateColumnDisplayName(value as string, tc)
: traverse(value as T);
return I.assoc(acc, key, newValue);
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.ts
index 03c4e345a20..8a3e0abbd27 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
@@ -12,7 +12,7 @@ import { createMockDatasetData } from "metabase-types/api/mocks";
import { leaveUntranslated } from "./use-translate-content";
import {
getTranslatedFilterDisplayName,
- translateAggregationDisplayName,
+ translateColumnDisplayName,
translateFieldValuesInSeries,
} from "./utils";
@@ -386,7 +386,7 @@ describe("getTranslatedFilterDisplayName", () => {
});
});
-describe("translateAggregationDisplayName", () => {
+describe("translateColumnDisplayName", () => {
const tcWithColumnTranslations: ContentTranslationFunction = (str) => {
const translations: Record<string, string> = {
Total: "Gesamtsumme",
@@ -398,7 +398,7 @@ describe("translateAggregationDisplayName", () => {
};
it("should return displayName unchanged when tc has no translations", () => {
- const result = translateAggregationDisplayName(
+ const result = translateColumnDisplayName(
"Sum of Total",
mockTranslateWithoutTranslations,
);
@@ -407,7 +407,7 @@ describe("translateAggregationDisplayName", () => {
});
it("should translate a simple column name without aggregation pattern", () => {
- const result = translateAggregationDisplayName(
+ const result = translateColumnDisplayName(
"Total",
tcWithColumnTranslations,
);
@@ -434,7 +434,7 @@ describe("translateAggregationDisplayName", () => {
])(
"should translate column name inside aggregation pattern: %s -> %s",
(input, expected) => {
- const result = translateAggregationDisplayName(
+ const result = translateColumnDisplayName(
input,
tcWithColumnTranslations,
);
@@ -446,15 +446,12 @@ describe("translateAggregationDisplayName", () => {
["Sum of Min of Total", "Sum of Min of Gesamtsumme"],
["Average of Sum of Min of Price", "Average of Sum of Min of Preis"],
])("should handle nested aggregations: %s -> %s", (input, expected) => {
- const result = translateAggregationDisplayName(
- input,
- tcWithColumnTranslations,
- );
+ const result = translateColumnDisplayName(input, tcWithColumnTranslations);
expect(result).toBe(expected);
});
it("should return original string when column name has no translation", () => {
- const result = translateAggregationDisplayName(
+ const result = translateColumnDisplayName(
"Sum of UnknownColumn",
tcWithColumnTranslations,
);
@@ -463,10 +460,7 @@ describe("translateAggregationDisplayName", () => {
});
it("should handle empty string", () => {
- const result = translateAggregationDisplayName(
- "",
- tcWithColumnTranslations,
- );
+ const result = translateColumnDisplayName("", tcWithColumnTranslations);
expect(result).toBe("");
});
@@ -481,7 +475,7 @@ describe("translateAggregationDisplayName", () => {
const wrappedPatterns = [(value: string) => `Somme de ${value} totale`];
it("should handle RTL patterns where value comes first", () => {
- const result = translateAggregationDisplayName(
+ const result = translateColumnDisplayName(
"Total של סכום",
tcWithColumnTranslations,
rtlPatterns,
@@ -491,7 +485,7 @@ describe("translateAggregationDisplayName", () => {
});
it("should handle wrapped patterns where value is in the middle", () => {
- const result = translateAggregationDisplayName(
+ const result = translateColumnDisplayName(
"Somme de Total totale",
tcWithColumnTranslations,
wrappedPatterns,
@@ -506,7 +500,7 @@ describe("translateAggregationDisplayName", () => {
(value: string) => `${value} של מינימום`,
];
- const result = translateAggregationDisplayName(
+ const result = translateColumnDisplayName(
"Total של מינימום של סכום",
tcWithColumnTranslations,
nestedRtlPatterns,
@@ -521,7 +515,7 @@ describe("translateAggregationDisplayName", () => {
(value: string) => `Minimum de ${value} local`,
];
- const result = translateAggregationDisplayName(
+ const result = translateColumnDisplayName(
"Somme de Minimum de Total local totale",
tcWithColumnTranslations,
nestedWrappedPatterns,
@@ -530,4 +524,227 @@ describe("translateAggregationDisplayName", () => {
expect(result).toBe("Somme de Minimum de Gesamtsumme local totale");
});
});
+
+ describe("binning patterns", () => {
+ it.each([
+ ["Total: Auto binned", "Gesamtsumme: Auto binned"],
+ // Dynamic binning patterns (handled by fallback)
+ ["Total: 10 bins", "Gesamtsumme: 10 bins"],
+ ["Total: 50 bins", "Gesamtsumme: 50 bins"],
+ ["Total: 100 bins", "Gesamtsumme: 100 bins"],
+ ["Price: 0.1°", "Preis: 0.1°"],
+ ["Price: 1°", "Preis: 1°"],
+ ["Price: 10°", "Preis: 10°"],
+ ])(
+ "should translate column name inside binning pattern: %s -> %s",
+ (input, expected) => {
+ const result = translateColumnDisplayName(
+ input,
+ tcWithColumnTranslations,
+ );
+ expect(result).toBe(expected);
+ },
+ );
+ });
+
+ describe("temporal bucket patterns", () => {
+ it.each([
+ ["Total: Day", "Gesamtsumme: Day"],
+ ["Total: Month", "Gesamtsumme: Month"],
+ ["Total: Year", "Gesamtsumme: Year"],
+ ["Total: Hour", "Gesamtsumme: Hour"],
+ ["Total: Week", "Gesamtsumme: Week"],
+ ["Total: Quarter", "Gesamtsumme: Quarter"],
+ ["Total: Hour of day", "Gesamtsumme: Hour of day"],
+ ["Total: Day of week", "Gesamtsumme: Day of week"],
+ ["Total: Day of month", "Gesamtsumme: Day of month"],
+ ["Total: Day of year", "Gesamtsumme: Day of year"],
+ ["Total: Week of year", "Gesamtsumme: Week of year"],
+ ["Total: Month of year", "Gesamtsumme: Month of year"],
+ ["Total: Quarter of year", "Gesamtsumme: Quarter of year"],
+ ["Total: Minute of hour", "Gesamtsumme: Minute of hour"],
+ ["Total: Minute", "Gesamtsumme: Minute"],
+ ])(
+ "should translate column name inside temporal bucket pattern: %s -> %s",
+ (input, expected) => {
+ const result = translateColumnDisplayName(
+ input,
+ tcWithColumnTranslations,
+ );
+ expect(result).toBe(expected);
+ },
+ );
+
+ it("should handle combined aggregation and temporal bucket patterns", () => {
+ const result = translateColumnDisplayName(
+ "Sum of Total: Month",
+ tcWithColumnTranslations,
+ );
+ expect(result).toBe("Sum of Gesamtsumme: Month");
+ });
+ });
+
+ describe("edge cases", () => {
+ it("should not incorrectly split column names that contain colon", () => {
+ // If a column is named "Note: Important" (with colon in name),
+ // it should be translated as a whole, not split
+ const tcWithColonColumn: ContentTranslationFunction = (str) => {
+ const translations: Record<string, string> = {
+ "Note: Important": "Notiz: Wichtig",
+ };
+
+ return typeof str === "string" ? (translations[str] ?? str) : str;
+ };
+
+ const result = translateColumnDisplayName(
+ "Note: Important",
+ tcWithColonColumn,
+ );
+ expect(result).toBe("Notiz: Wichtig");
+ });
+
+ it("should split on colon and translate column if column has a translation", () => {
+ // This handles backend-translated temporal bucket suffixes like "Monat", "Tag", etc.
+ // where the suffix is already translated by the backend
+ const result = translateColumnDisplayName(
+ "Total: SomeRandomSuffix",
+ tcWithColumnTranslations,
+ );
+ // "Total" has a translation, so it splits and translates the column part
+ expect(result).toBe("Gesamtsumme: SomeRandomSuffix");
+ });
+
+ it("should handle backend-translated temporal bucket suffixes", () => {
+ // The backend translates temporal unit names (e.g., "Month" -> "Monat" in German)
+ // before the FE receives them. This test verifies that we still translate the column part.
+ const result = translateColumnDisplayName(
+ "Total: Monat", // German for "Month" - already translated by backend
+ tcWithColumnTranslations,
+ );
+ expect(result).toBe("Gesamtsumme: Monat");
+ });
+ });
+
+ describe("joined table patterns", () => {
+ const tcWithJoinTranslations: ContentTranslationFunction = (str) => {
+ const translations: Record<string, string> = {
+ Total: "Gesamtsumme",
+ Price: "Preis",
+ Quantity: "Menge",
+ Products: "Produkte",
+ Orders: "Bestellungen",
+ "Created At": "Erstellt am",
+ };
+
+ return typeof str === "string" ? (translations[str] ?? str) : str;
+ };
+
+ it.each([
+ ["Products → Total", "Produkte → Gesamtsumme"],
+ ["Products → Created At", "Produkte → Erstellt am"],
+ ["Orders → Products → Total", "Bestellungen → Produkte → Gesamtsumme"],
+ ])(
+ "should translate joined table column names: %s -> %s",
+ (input, expected) => {
+ const result = translateColumnDisplayName(
+ input,
+ tcWithJoinTranslations,
+ );
+ expect(result).toBe(expected);
+ },
+ );
+
+ it("should translate joined table with temporal bucket", () => {
+ const result = translateColumnDisplayName(
+ "Products → Created At: Month",
+ tcWithJoinTranslations,
+ );
+ expect(result).toBe("Produkte → Erstellt am: Month");
+ });
+
+ it("should translate joined table with aggregation pattern", () => {
+ const result = translateColumnDisplayName(
+ "Distinct values of Products → Total",
+ tcWithJoinTranslations,
+ );
+ expect(result).toBe("Distinct values of Produkte → Gesamtsumme");
+ });
+
+ it("should translate complex nested pattern with join, aggregation, and temporal bucket", () => {
+ const result = translateColumnDisplayName(
+ "Distinct values of Products → Created At: Month",
+ tcWithJoinTranslations,
+ );
+ expect(result).toBe("Distinct values of Produkte → Erstellt am: Month");
+ });
+
+ it("should handle nested joins with temporal bucket", () => {
+ const result = translateColumnDisplayName(
+ "Orders → Products → Created At: Month",
+ tcWithJoinTranslations,
+ );
+ expect(result).toBe("Bestellungen → Produkte → Erstellt am: Month");
+ });
+
+ describe("implicit join patterns (dash separator)", () => {
+ // Add translations for implicit join patterns
+ const tcWithImplicitJoinTranslations: ContentTranslationFunction = (
+ str,
+ ) => {
+ const translations: Record<string, string> = {
+ Total: "Gesamtsumme",
+ Products: "Produkte",
+ Product: "Produkt", // Singular form used in FK names
+ Orders: "Bestellungen",
+ People: "Personen",
+ "Created At": "Erstellt am",
+ };
+
+ return typeof str === "string" ? (translations[str] ?? str) : str;
+ };
+
+ it("should translate implicit join alias with dash separator", () => {
+ // "People - Product → Created At" has implicit join alias "People - Product"
+ const result = translateColumnDisplayName(
+ "People - Product → Created At",
+ tcWithImplicitJoinTranslations,
+ );
+ expect(result).toBe("Personen - Produkt → Erstellt am");
+ });
+
+ it("should translate implicit join with temporal bucket", () => {
+ const result = translateColumnDisplayName(
+ "People - Product → Created At: Month",
+ tcWithImplicitJoinTranslations,
+ );
+ expect(result).toBe("Personen - Produkt → Erstellt am: Month");
+ });
+
+ it("should translate aggregation with implicit join and temporal bucket", () => {
+ const result = translateColumnDisplayName(
+ "Distinct values of People - Product → Created At: Month",
+ tcWithImplicitJoinTranslations,
+ );
+ expect(result).toBe(
+ "Distinct values of Personen - Produkt → Erstellt am: Month",
+ );
+ });
+
+ it("should NOT split on dash when there is no arrow separator", () => {
+ // "My Question - Part 2" should be translated as a whole, not split on dash
+ const tcWithQuestionName: ContentTranslationFunction = (str) => {
+ const translations: Record<string, string> = {
+ "My Question - Part 2": "Meine Frage - Teil 2",
+ };
+ return typeof str === "string" ? (translations[str] ?? str) : str;
+ };
+
+ const result = translateColumnDisplayName(
+ "My Question - Part 2",
+ tcWithQuestionName,
+ );
+ expect(result).toBe("Meine Frage - Teil 2");
+ });
+ });
+ });
});
diff --git a/frontend/src/embedding-sdk-bundle/components/private/QuestionTitle.tsx b/frontend/src/embedding-sdk-bundle/components/private/QuestionTitle.tsx
index 62b3a1e9954..99204cb56e3 100644
--- a/frontend/src/embedding-sdk-bundle/components/private/QuestionTitle.tsx
+++ b/frontend/src/embedding-sdk-bundle/components/private/QuestionTitle.tsx
@@ -1,56 +1,21 @@
import cx from "classnames";
+import { getQuestionTitle } from "embedding-sdk-bundle/lib/sdk-question/get-question-title";
import type { CommonStylingProps } from "embedding-sdk-bundle/types/props";
import CS from "metabase/css/core/index.css";
import { useTranslateContent } from "metabase/i18n/hooks";
-import {
- getAdHocQuestionDescription,
- shouldRenderAdhocDescription,
-} from "metabase/query_builder/components/view/ViewHeader/components/AdHocQuestionDescription/AdHocQuestionDescription";
-import * as Lib from "metabase-lib";
-import type Question from "metabase-lib/v1/Question";
-type GetQuestionTitleProps = {
- question?: Question;
-};
-
-export const getQuestionTitle = ({
- question,
-}: GetQuestionTitleProps): string | null => {
- if (!question) {
- return null;
- }
-
- const isSaved = question.isSaved();
- const displayName = question.displayName();
-
- if (isSaved && displayName) {
- return displayName ?? null;
- }
-
- const query = question.query();
- const { isNative } = Lib.queryDisplayInfo(query);
- const adhocDescription = getAdHocQuestionDescription({ question });
- if (
- !isNative &&
- shouldRenderAdhocDescription({ question }) &&
- adhocDescription
- ) {
- return adhocDescription;
- }
-
- return null;
-};
-
-type QuestionTitleProps = GetQuestionTitleProps & CommonStylingProps;
+type QuestionTitleProps = {
+ question?: Parameters<typeof getQuestionTitle>[0];
+} & CommonStylingProps;
export const QuestionTitle = ({
question,
className,
style,
}: QuestionTitleProps) => {
- const questionTitle = getQuestionTitle({ question });
const tc = useTranslateContent();
+ const questionTitle = getQuestionTitle(question, tc);
if (questionTitle === null) {
return null;
@@ -58,7 +23,7 @@ export const QuestionTitle = ({
return (
<h2 className={cx(CS.h2, CS.textWrap, className)} style={style}>
- {tc(questionTitle)}
+ {questionTitle}
</h2>
);
};
diff --git a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/Breakout/BreakoutBadgeList.tsx b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/Breakout/BreakoutBadgeList.tsx
index e1c8b4cab0f..dd1b5c4b8f7 100644
--- a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/Breakout/BreakoutBadgeList.tsx
+++ b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/Breakout/BreakoutBadgeList.tsx
@@ -6,6 +6,7 @@ import {
} from "embedding-sdk-bundle/components/private/SdkQuestion/components/Breakout/use-breakout-data";
import { useSdkQuestionContext } from "embedding-sdk-bundle/components/private/SdkQuestion/context";
import { useTranslateContent } from "metabase/i18n/hooks";
+import { PLUGIN_CONTENT_TRANSLATION } from "metabase/plugins";
import { BadgeList } from "../util/BadgeList";
@@ -25,7 +26,10 @@ export const BreakoutBadgeListInner = ({
<BadgeList
items={breakoutItems.map((item) => ({
item,
- name: tc(item.longDisplayName),
+ name: PLUGIN_CONTENT_TRANSLATION.translateColumnDisplayName(
+ item.longDisplayName,
+ tc,
+ ),
}))}
addButtonLabel={t`Add another grouping`}
onSelectItem={onSelectItem}
diff --git a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/Summarize/use-summarize-data.ts b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/Summarize/use-summarize-data.ts
index fa01c6cbb4f..dfb89ad576e 100644
--- a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/Summarize/use-summarize-data.ts
+++ b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/Summarize/use-summarize-data.ts
@@ -59,7 +59,7 @@ export const useSummarizeData = () => {
return {
...aggregationItem,
displayName:
- PLUGIN_CONTENT_TRANSLATION.translateAggregationDisplayName(
+ PLUGIN_CONTENT_TRANSLATION.translateColumnDisplayName(
aggregationItem.displayName,
tc,
),
diff --git a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestionDefaultView/DefaultViewTitle.tsx b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestionDefaultView/DefaultViewTitle.tsx
index 9698bde317c..309c7d44d8c 100644
--- a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestionDefaultView/DefaultViewTitle.tsx
+++ b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestionDefaultView/DefaultViewTitle.tsx
@@ -1,9 +1,9 @@
import { c, t } from "ttag";
+import { getQuestionTitle } from "embedding-sdk-bundle/lib/sdk-question/get-question-title";
import { useTranslateContent } from "metabase/i18n/hooks";
import { Anchor, Stack, Text } from "metabase/ui";
-import { getQuestionTitle } from "../QuestionTitle";
import { useSdkQuestionContext } from "../SdkQuestion/context";
import type { SdkQuestionDefaultViewProps } from "./SdkQuestionDefaultView";
@@ -60,7 +60,7 @@ export const DefaultViewTitle = ({
if (title === undefined || title === true) {
const originalName = tc(originalQuestion?.displayName());
- const titleText = tc(getQuestionTitle({ question }));
+ const titleText = getQuestionTitle(question, tc);
return (
<DefaultViewTitleText
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.ts
new file mode 100644
index 00000000000..10b90ba2fd5
--- /dev/null
+++ b/frontend/src/embedding-sdk-bundle/lib/sdk-question/get-question-title.ts
@@ -0,0 +1,44 @@
+import type { ContentTranslationFunction } from "metabase/i18n/types";
+import { PLUGIN_CONTENT_TRANSLATION } from "metabase/plugins";
+import {
+ getAdHocQuestionDescription,
+ shouldRenderAdhocDescription,
+} from "metabase/query_builder/components/view/ViewHeader/components/AdHocQuestionDescription/AdHocQuestionDescription";
+import * as Lib from "metabase-lib";
+import type Question from "metabase-lib/v1/Question";
+
+export const getQuestionTitle = (
+ question: Question | undefined,
+ tc?: ContentTranslationFunction,
+): string | null => {
+ if (!question) {
+ return null;
+ }
+
+ const isSaved = question.isSaved();
+ const displayName = question.displayName();
+
+ if (isSaved && displayName) {
+ return tc ? tc(displayName) : displayName;
+ }
+
+ const query = question.query();
+ const { isNative } = Lib.queryDisplayInfo(query);
+ const adhocDescription = getAdHocQuestionDescription({
+ question,
+ translateDisplayName: tc
+ ? (name: string) =>
+ PLUGIN_CONTENT_TRANSLATION.translateColumnDisplayName(name, tc)
+ : undefined,
+ });
+
+ if (
+ !isNative &&
+ shouldRenderAdhocDescription({ question }) &&
+ adhocDescription
+ ) {
+ return adhocDescription;
+ }
+
+ return null;
+};
diff --git a/frontend/src/metabase/plugins/oss/content-translation.ts b/frontend/src/metabase/plugins/oss/content-translation.ts
index 4a275d587ef..1cdebdd7d2d 100644
--- a/frontend/src/metabase/plugins/oss/content-translation.ts
+++ b/frontend/src/metabase/plugins/oss/content-translation.ts
@@ -21,7 +21,7 @@ const getDefaultPluginContentTranslation = () => ({
obj: T,
_tc: ContentTranslationFunction,
) => obj,
- translateAggregationDisplayName: (
+ translateColumnDisplayName: (
displayName: string,
_tc: ContentTranslationFunction,
): string => displayName,
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.tsx
index e34f9cd60d2..aaa815e0370 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,6 +11,8 @@ type AdHocQuestionDescriptionProps = {
type GetAdhocQuestionDescriptionProps = {
question: Question;
+ /** Optional function to translate longDisplayName values */
+ translateDisplayName?: (displayName: string) => string;
};
export const shouldRenderAdhocDescription = ({
@@ -26,6 +28,7 @@ export const shouldRenderAdhocDescription = ({
export const getAdHocQuestionDescription = ({
question,
+ translateDisplayName = (name: string) => name,
}: GetAdhocQuestionDescriptionProps) => {
const query = question.query();
const stageIndex = getInfoStageIndex(query);
@@ -41,9 +44,10 @@ export const getAdHocQuestionDescription = ({
aggregations.length,
)
: aggregations
- .map(
- (aggregation) =>
+ .map((aggregation) =>
+ translateDisplayName(
Lib.displayInfo(query, stageIndex, aggregation).longDisplayName,
+ ),
)
.join(t` and `);
const breakoutDescription =
@@ -56,9 +60,10 @@ export const getAdHocQuestionDescription = ({
breakouts.length,
)
: breakouts
- .map(
- (breakout) =>
+ .map((breakout) =>
+ translateDisplayName(
Lib.displayInfo(query, stageIndex, breakout).longDisplayName,
+ ),
)
.join(t` and `);
diff --git a/frontend/src/metabase/querying/notebook/components/AggregateStep/AggregateStep.tsx b/frontend/src/metabase/querying/notebook/components/AggregateStep/AggregateStep.tsx
index 0d03ada4ebc..b7e38627abd 100644
--- a/frontend/src/metabase/querying/notebook/components/AggregateStep/AggregateStep.tsx
+++ b/frontend/src/metabase/querying/notebook/components/AggregateStep/AggregateStep.tsx
@@ -3,6 +3,7 @@ import { t } from "ttag";
import { AggregationPicker } from "metabase/common/components/AggregationPicker";
import { useTranslateContent } from "metabase/i18n/hooks";
+import { PLUGIN_CONTENT_TRANSLATION } from "metabase/plugins";
import * as Lib from "metabase-lib";
import type { NotebookStepProps } from "../../types";
@@ -46,7 +47,10 @@ export function AggregateStep({
};
const renderAggregationName = (aggregation: Lib.AggregationClause) =>
- tc(Lib.displayInfo(query, stageIndex, aggregation).longDisplayName);
+ PLUGIN_CONTENT_TRANSLATION.translateColumnDisplayName(
+ Lib.displayInfo(query, stageIndex, aggregation).longDisplayName,
+ tc,
+ );
return (
<ClauseStep
diff --git a/frontend/src/metabase/querying/notebook/components/BreakoutStep/BreakoutStep.tsx b/frontend/src/metabase/querying/notebook/components/BreakoutStep/BreakoutStep.tsx
index 3ab17b9dfcc..93248c80bda 100644
--- a/frontend/src/metabase/querying/notebook/components/BreakoutStep/BreakoutStep.tsx
+++ b/frontend/src/metabase/querying/notebook/components/BreakoutStep/BreakoutStep.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 * as Lib from "metabase-lib";
import type { NotebookStepProps } from "../../types";
@@ -35,7 +36,10 @@ export function BreakoutStep({
const isAddButtonDisabled = isMetric && metricColumns.length === 0;
const renderBreakoutName = (clause: Lib.BreakoutClause) =>
- tc(Lib.displayInfo(query, stageIndex, clause).longDisplayName);
+ PLUGIN_CONTENT_TRANSLATION.translateColumnDisplayName(
+ Lib.displayInfo(query, stageIndex, clause).longDisplayName,
+ tc,
+ );
const handleAddBreakout = (column: Lib.ColumnMetadata) => {
const nextQuery = Lib.breakout(query, stageIndex, column);