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
Create pseudo locale to reduce E2E reliance on literal translated strings (#72328)
Andersonc36d20da5108
diff --git a/.gitignore b/.gitignoreindex 0f2ab705ec7..688fb9afc89 100644--- a/.gitignore+++ b/.gitignore@@ -56,6 +56,8 @@ cypress.env.json/lein-plugins/*/target/local/locales/metabase-*.pot+# Pseudo-locale generated at build time+/locales/en-ZZ.po/logs/modules/drivers/*/resources/namespaces.edn/modules/drivers/*/targetdiff --git a/bin/athena.bb b/bin/athena.bbindex af155f512e8..baf3ca73501 100755--- a/bin/athena.bb+++ b/bin/athena.bb@@ -2,12 +2,12 @@(ns athena(:require- [babashka.cli :as cli]- [babashka.process :as p]- [clojure.data.xml :as x]- [clojure.java.io :as io]- [clojure.string :as str]- [clojure.zip :as z]))+ [babashka.cli :as cli]+ [babashka.process :as p]+ [clojure.data.xml :as x]+ [clojure.java.io :as io]+ [clojure.string :as str]+ [clojure.zip :as z]));; Since amazon is still not putting their athena jdbc on to maven, the easiest thing for us to do is setup a maven-y s3 repo and copy their jar into it.;;diff --git a/bin/build/src/i18n/create_artifacts.clj b/bin/build/src/i18n/create_artifacts.cljindex 8d5a4014c16..a5970a235b4 100644--- a/bin/build/src/i18n/create_artifacts.clj+++ b/bin/build/src/i18n/create_artifacts.clj@@ -4,8 +4,11 @@[i18n.common :as i18n][i18n.create-artifacts.backend :as backend][i18n.create-artifacts.frontend :as frontend]+ [i18n.pseudo-locale :as pseudo-locale][metabuild-common.core :as u]))+(set! *warn-on-reflection* true)+(defn- locales-dot-edn []{:locales (conj (i18n/locales) "en"):packages ["metabase"]@@ -41,6 +44,8 @@([_options](u/step "Create i18n artifacts"+ ;; Generate the `en-ZZ` pseudo-locale .po file+ (pseudo-locale/generate-pseudo-locale-po!)(generate-locales-dot-edn!)(create-artifacts-for-all-locales!)(u/announce "Translation resources built successfully."))))diff --git a/bin/build/src/i18n/pseudo_locale.clj b/bin/build/src/i18n/pseudo_locale.cljnew file mode 100644index 00000000000..eeb6d47678e--- /dev/null+++ b/bin/build/src/i18n/pseudo_locale.clj@@ -0,0 +1,107 @@+(ns i18n.pseudo-locale+ "Generates the `en-ZZ` pseudo-locale `.po` file used by E2E tests.++ This file is the build-time companion to the pseudo-locale strategy described in UXW-3460. Every English source+ string from `locales/metabase.po` is transformed into `[zz] {English}`, and the resulting `locales/en-ZZ.po` is+ picked up by the normal i18n build pipeline (same as every other real locale).++ E2E tests can then switch the UI to `en-ZZ` and assert on the predictable `[zz] ...` prefix, without depending on+ fragile real-language strings that Crowdin may update at any time.++ The file is `.gitignore`d — it is regenerated on every build from the current `locales/metabase.po`, so it never+ drifts. Crowdin does not know about `en-ZZ` (it's not in `locales/crowdin.yml`) so the translation-update workflow+ leaves it alone.++ See `src/metabase/util/i18n/impl.clj:available-locale?` for the backend allowlist that makes `en_ZZ` a valid+ settable locale, and `src/metabase/util/i18n.clj:available-locales-with-names` for the dev/test-only visibility+ filter that hides it from production language pickers."+ (:require+ [clojure.java.io :as io]+ [metabuild-common.core :as u])+ (:import+ (org.fedorahosted.tennera.jgettext Catalog Message PoParser PoWriter)))++(set! *warn-on-reflection* true)++(def pseudo-locale-code+ "The on-disk filename stem for the pseudo-locale. Hyphen form to match the existing convention+ (`pt-BR.po`, `zh-CN.po`, ...)."+ "en-ZZ")++(def ^:private msgstr-prefix "[zz] ")++(def ^:private pseudo-header-msgstr+ (str+ "Content-Type: text/plain; charset=UTF-8\n"+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"+ "Language: en-ZZ\n"+ "Language-Team: E2E Testing Pseudo-Locale\n"+ "X-Metabase-Pseudo-Locale: true\n"))++(defn- prefix [s]+ (str msgstr-prefix s))++(defn- build-pseudo-header ^Message []+ (let [header (Message.)]+ (.setMsgid header "")+ (.setMsgstr header pseudo-header-msgstr)+ (.addComment header " Pseudo-locale auto-generated by bin/build/src/i18n/pseudo_locale.clj. DO NOT EDIT.")+ (.addComment header " See UXW-3460 and the namespace docstring for details.")+ header))++(defn- build-pseudo-message+ "Given a `Message` from `metabase.po`, return a new `Message` whose `msgstr` (and plural `msgstr`s) are the original+ `msgid` prefixed with `[zz] `. All other fields (msgctxt, source references, comments, formats) are copied as-is."+ ^Message [^Message src]+ (let [dst (Message.)]+ (when-let [domain (.getDomain src)]+ (.setDomain dst domain))+ (when-let [msgctxt (.getMsgctxt src)]+ (.setMsgctxt dst msgctxt))+ (.setMsgid dst (.getMsgid src))+ (if (.isPlural src)+ (let [msgid-plural (.getMsgidPlural src)+ plurals (.getMsgstrPlural src)]+ (.setMsgidPlural dst msgid-plural)+ ;; Index 0 corresponds to the singular form, indices >= 1 to the plural form(s).+ ;; We don't model language-specific plural rules beyond Metabase's default `nplurals=2`.+ (dotimes [i (max 2 (count plurals))]+ (.addMsgstrPlural dst+ (if (zero? i)+ (prefix (.getMsgid src))+ (prefix msgid-plural))+ i)))+ (.setMsgstr dst (prefix (.getMsgid src))))+ (doseq [ref (.getSourceReferences src)]+ (.addSourceReference dst ref))+ (doseq [fmt (.getFormats src)]+ (.addFormat dst fmt))+ (doseq [comment (.getExtractedComments src)]+ (.addExtractedComment dst comment))+ dst))++(defn- source-catalog ^Catalog []+ (let [parser (PoParser.)+ source-file (io/file (u/filename u/project-root-directory "locales" "metabase.po"))]+ (.parseCatalog parser source-file)))++(defn- target-file ^java.io.File []+ (io/file (u/filename u/project-root-directory "locales" (str pseudo-locale-code ".po"))))++(defn generate-pseudo-locale-po!+ "Read `locales/metabase.po` and write `locales/en-ZZ.po` with every msgstr prefixed with `[zz] `. Idempotent: running+ this repeatedly produces the same output (modulo jgettext's internal ordering)."+ []+ (u/step (format "Generate pseudo-locale %s.po" pseudo-locale-code)+ (let [src (source-catalog)+ dst (Catalog.)+ target (target-file)+ msg-count (volatile! 0)]+ (.addMessage dst (build-pseudo-header))+ (doseq [^Message msg (iterator-seq (.iterator src))+ :when (not (.isHeader msg))]+ (.addMessage dst (build-pseudo-message msg))+ (vswap! msg-count inc))+ (u/delete-file-if-exists! (.getAbsolutePath target))+ (.write (PoWriter.) dst target)+ (u/announce "Wrote %d pseudo-locale messages to %s." @msg-count (.getAbsolutePath target)))))diff --git a/docs/developers-guide/e2e-tests.md b/docs/developers-guide/e2e-tests.mdindex 5024714fc15..2ed83b48ca4 100644--- a/docs/developers-guide/e2e-tests.md+++ b/docs/developers-guide/e2e-tests.md@@ -178,6 +178,12 @@ docker run -d -p 1080:1080 -p 1025:1025 maildev/maildev:latestSome of the tests are checking content translation functionality. These tests require to run `./bin/i18n/build-translation-resources` command before running the tests to precompile JSON files with translations.+### Pseudo locale for E2E tests++We provide a pseudo locale (`en_ZZ`) that prefixes all translated strings with `[zz]` (e.g., `"My text"` becomes `"[zz] My text"`). This is handy when writing E2E tests that assert translations are working correctly without relying on actual translated strings that may change over time.++The pseudo locale PO file is generated at build time; to make it available in the UI, start the backend with `MB_ENABLE_TEST_LOCALES=true` and select "English (ZZ)" under Admin > Settings > Localization.+### Cypress comes with `Lodash` for freeWe don't need to have [Lodash](https://lodash.com/) in our direct dependencies to be able to [use it with Cypress](https://docs.cypress.io/api/utilities/_). It is aliased with an underscore and its methods can be accessed with `Cypress._.method()`. We can use `_.times` method to stress-test a certain test (or a set of tests) locally.diff --git a/e2e/runner/cypress-runner-backend.js b/e2e/runner/cypress-runner-backend.jsindex 61fce5528c4..9de6aad6627 100755--- a/e2e/runner/cypress-runner-backend.js+++ b/e2e/runner/cypress-runner-backend.js@@ -18,6 +18,9 @@ function getJvmOptsFromDepsEdn(alias = "e2e") {process.env.MB_DB_FILE = process.env.MB_DB_FILE || tempDbPath;process.env.MB_JETTY_PORT = process.env.MB_JETTY_PORT || 4000;+// Expose the `en-ZZ` pseudo-locale in the Cypress backend's language pickers and API validation.+process.env.MB_ENABLE_TEST_LOCALES = "true";+if (!process.env.CI) {// Use a temporary copy of the sample db so it won't use and lock the db used for local developmentprocess.env.MB_INTERNAL_DO_NOT_USE_SAMPLE_DB_DIR = path.resolve(diff --git a/e2e/support/helpers/e2e-dashboard-helpers.ts b/e2e/support/helpers/e2e-dashboard-helpers.tsindex 6a8dec0e63f..680ebdc9432 100644--- a/e2e/support/helpers/e2e-dashboard-helpers.ts+++ b/e2e/support/helpers/e2e-dashboard-helpers.ts@@ -82,11 +82,9 @@ export function editDashboard() {}export function saveDashboard({- buttonLabel = "Save",- editBarText = "You're editing this dashboard.",waitMs = 1,awaitRequest = true,-} = {}) {+}: { waitMs?: number; awaitRequest?: boolean } = {}) {cy.intercept("PUT", "/api/dashboard/*").as("saveDashboard-saveDashboardCards",);@@ -95,8 +93,8 @@ export function saveDashboard({"saveDashboard-getDashboardMetadata",);- cy.findByText(editBarText).should("be.visible");- cy.button(buttonLabel).click();+ cy.findByTestId("edit-bar").should("be.visible");+ cy.findByTestId("edit-bar").findByTestId("save-edit-button").click();if (awaitRequest) {cy.wait("@saveDashboard-saveDashboardCards");@@ -104,7 +102,7 @@ export function saveDashboard({cy.wait("@saveDashboard-getDashboardMetadata");}- cy.findByText(editBarText).should("not.exist");+ cy.findByTestId("edit-bar").should("not.exist");cy.wait(waitMs); // this is stupid but necessary to due to the dashboard resizing and detaching elements}diff --git a/e2e/test-component/scenarios/embedding-sdk/locale-on-provider.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/locale-on-provider.cy.spec.tsxindex eb53c87f24f..9809654af83 100644--- a/e2e/test-component/scenarios/embedding-sdk/locale-on-provider.cy.spec.tsx+++ b/e2e/test-component/scenarios/embedding-sdk/locale-on-provider.cy.spec.tsx@@ -49,34 +49,31 @@ describe("scenarios > embedding-sdk > locale set on MetabaseProvider", () => {});it("when no locale is set, it should use the instance locale", () => {- setup({ locale: undefined, instanceLocale: "de" });+ setup({ locale: undefined, instanceLocale: "en-ZZ" });- cy.request("/app/locales/de.json").then((response) => {+ cy.request("/app/locales/en_ZZ.json").then((response) => {expect(response.status).to.eq(200);});getSdkRoot().within(() => {- cy.findByText("Zusammenfassen").should("exist");+ cy.findByText("[zz] Summarize").should("exist");});});- it("when locale=de it should display german text", () => {- setup({ locale: "de" });+ it("when locale=en-ZZ it should display pseudo-locale text", () => {+ setup({ locale: "en-ZZ" });getSdkRoot().within(() => {- cy.findByText("Zusammenfassen").should("exist");+ cy.findByText("[zz] Summarize").should("exist");});});- it("when locale=de-CH it should fallback to `de.json`", () => {- setup({ locale: "de-CH" });-- cy.request("/app/locales/de.json").then((response) => {- expect(response.status).to.eq(200);- });+ it("when locale=en-XX it should fallback to en", () => {+ // en-XX is not an available locale, so LocaleProvider falls back to `en`+ setup({ locale: "en-XX" });getSdkRoot().within(() => {- cy.findByText("Zusammenfassen").should("exist");+ cy.findByText("Summarize").should("exist");});});@@ -92,7 +89,8 @@ describe("scenarios > embedding-sdk > locale set on MetabaseProvider", () => {});});- it("when locale=zh-TW it use it as it's available", () => {+ it("when locale=zh-TW, it should be used used since it's available", () => {+ // Very specific test case, so using en-ZZ isn't as usefulsetup({ locale: "zh-TW" });cy.request("/app/locales/zh_TW.json").then((response) => {diff --git a/e2e/test-component/scenarios/embedding-sdk/sdk-bundle.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/sdk-bundle.cy.spec.tsxindex 783e9b0ec65..35a8d5bfed0 100644--- a/e2e/test-component/scenarios/embedding-sdk/sdk-bundle.cy.spec.tsx+++ b/e2e/test-component/scenarios/embedding-sdk/sdk-bundle.cy.spec.tsx@@ -165,25 +165,25 @@ describe(rerender(<MetabaseProviderauthConfig={DEFAULT_SDK_AUTH_PROVIDER_CONFIG}- locale="es"+ locale="en-ZZ"><InteractiveQuestion questionId={ORDERS_QUESTION_ID} /></MetabaseProvider>,);getSdkRoot().within(() => {- cy.findByText("Filtro").should("exist");+ cy.findByText("[zz] Filter").should("exist");});- // Update props via the imperative API (via window)+ // Update props via the imperative API (via window).cy.window().then((win) => {win.METABASE_PROVIDER_PROPS_STORE.setProps({authConfig: DEFAULT_SDK_AUTH_PROVIDER_CONFIG,- locale: "fr",+ locale: "en",});getSdkRoot().within(() => {- cy.findByText("Filtre").should("exist");+ cy.findByText("Filter").should("exist");});});});diff --git a/e2e/test-host-app/shared/compatibility.cy.spec.js b/e2e/test-host-app/shared/compatibility.cy.spec.jsindex 936fa8b6850..df5510efa6c 100644--- a/e2e/test-host-app/shared/compatibility.cy.spec.js+++ b/e2e/test-host-app/shared/compatibility.cy.spec.js@@ -38,13 +38,13 @@ describe("Embedding SDK: shared Host Apps compatibility tests", () => {it("should load a metabase locale", () => {cy.visit({- url: `${CLIENT_HOST}/interactive-question?locale=es&questionId=1`,+ url: `${CLIENT_HOST}/interactive-question?locale=en-ZZ&questionId=1`,});cy.findByTestId("interactive-question-result-toolbar", {timeout: TIMEOUT_MS,}).within(() => {- expect(cy.findByText("Tabla").should("exist"));+ expect(cy.findByText("[zz] Table").should("exist"));});});@@ -59,18 +59,20 @@ describe("Embedding SDK: shared Host Apps compatibility tests", () => {cy.findByTestId("interactive-question-result-toolbar", {timeout: TIMEOUT_MS,}).within(() => {- cy.findByText("Filtro").click();+ cy.findByTestId("filter-dropdown-button").click();});cy.get('[data-element-id="mantine-popover"]').should("have.length.above", 0).last().within(() => {+ // "Started At" is the column display name from the database, stable across locales.cy.findByText("Started At").click();- cy.findByText(/Rango de fechas relativo…/).click();+ cy.findByTestId("date-picker-type-relative").click();});cy.findByTestId("date-filter-picker").within(() => {+ // Dayjs Spanish month abbreviation — this is the actual thing under test.cy.findByText(/^dic.*2024/).should("exist");});});@@ -86,17 +88,19 @@ describe("Embedding SDK: shared Host Apps compatibility tests", () => {cy.findByTestId("interactive-question-result-toolbar", {timeout: TIMEOUT_MS,}).within(() => {- cy.findByText("Filtro").click();+ cy.findByTestId("filter-dropdown-button").click();});cy.get('[data-element-id="mantine-popover"]').should("have.length.above", 0).last().within(() => {+ // "Started At" is the column display name from the database, stable across locales.cy.findByText("Started At").click();- cy.findByText(/Rango de fechas fijo…/).click();+ cy.findByTestId("date-picker-type-specific").click();});cy.findByTestId("date-filter-picker").within(() => {+ // Dayjs Spanish month name — this is the actual thing under test.cy.findByText("enero 2025").should("exist");});});diff --git a/e2e/test/scenarios/dashboard-filters/dashboard-filters-date.cy.spec.js b/e2e/test/scenarios/dashboard-filters/dashboard-filters-date.cy.spec.jsindex eca23fbc65a..adada298763 100644--- a/e2e/test/scenarios/dashboard-filters/dashboard-filters-date.cy.spec.js+++ b/e2e/test/scenarios/dashboard-filters/dashboard-filters-date.cy.spec.js@@ -156,7 +156,7 @@ describe("scenarios > dashboard > filters > date", () => {it("correctly serializes exclude filter on non-English locales (metabase#29122)", () => {cy.request("GET", "/api/user/current").then(({ body: { id: USER_ID } }) => {- cy.request("PUT", `/api/user/${USER_ID}`, { locale: "fr" });+ cy.request("PUT", `/api/user/${USER_ID}`, { locale: "en_ZZ" });});H.visitDashboard(ORDERS_DASHBOARD_ID);@@ -168,28 +168,19 @@ describe("scenarios > dashboard > filters > date", () => {H.popover().icon("calendar").click(); // "Time" -> "All Options"- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Sélectionner...").click(); // "Select…"- H.popover().contains("Created At").first().click();-- H.saveDashboard({- buttonLabel: "Sauvegarder",- editBarText: "Vous êtes en train d'éditer ce tableau de bord.",- });-- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Date").click(); // "Date" - it's the same word in English and in French- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Exclure...").click(); // "Exclude…"- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Mois de l'année...").click(); // "Months of the year…"- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("janvier").click(); // "January"+ H.getDashboardCard().findByText("[zz] Select…").click();+ H.popover().contains("Created At").first().click(); // 'Created At' is a column name, so it's not translated+ H.saveDashboard();- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Ajouter un filtre").click(); // "Add filter"+ cy.findByTestId("dashboard-parameters-and-cards")+ .findByText("[zz] Date")+ .click();+ H.popover().findByText("[zz] Exclude…").click();+ H.popover().findByText("[zz] Months of the year…").click();+ H.popover().findByText("January").click(); // Dayjs doesn't have en-ZZ locale, falls back to en+ H.popover().findByText("[zz] Add filter").click();- cy.url().should("match", /\/dashboard\/\d+\?date=exclude-months-Jan/);+ cy.url().should("match", /\/dashboard\/\d+\?.*date=exclude-months-Jan/);});});diff --git a/e2e/test/scenarios/dashboard/text-cards.cy.spec.js b/e2e/test/scenarios/dashboard/text-cards.cy.spec.jsindex dc79f2bd671..ef6c9c3fad3 100644--- a/e2e/test/scenarios/dashboard/text-cards.cy.spec.js+++ b/e2e/test/scenarios/dashboard/text-cards.cy.spec.js@@ -335,7 +335,7 @@ describe("scenarios > dashboard > parameters in text and heading cards", () => {cy.request("GET", "/api/user/current").then(({ body: { id: USER_ID } }) => {cy.request("PUT", `/api/user/${USER_ID}`, { locale: "en" });});- H.updateSetting("site-locale", "fr");+ H.updateSetting("site-locale", "en-ZZ");cy.reload();H.editDashboard();@@ -361,14 +361,21 @@ describe("scenarios > dashboard > parameters in text and heading cards", () => {cy.findByText("Today").click();});- H.getDashboardCard(0).findByText("Variable: Aujourd'hui").should("exist");- H.getDashboardCard(1).findByText("Variable: Aujourd'hui").should("exist");+ H.getDashboardCard(0)+ .findByText("Variable: [zz] Today")+ .should("be.visible");+ H.getDashboardCard(1)+ .findByText("Variable: [zz] Today")+ .should("be.visible");// Let's make sure the localization was reset back to the user locale by checking that specific text exists in// English on the homepage.cy.visit("/");- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Pick up where you left off").should("exist");++ cy.findByTestId("home-page").within(() => {+ cy.findByText("Pick up where you left off").should("be.visible");+ cy.findByText("[zz] Pick up where you left off").should("not.exist");+ });});it("should localize date parameters in the instance locale", () => {diff --git a/e2e/test/scenarios/filters-reproductions/dashboard-filters-reproductions-2.cy.spec.js b/e2e/test/scenarios/filters-reproductions/dashboard-filters-reproductions-2.cy.spec.jsindex 40f98d2167c..c91de3b5b5f 100644--- a/e2e/test/scenarios/filters-reproductions/dashboard-filters-reproductions-2.cy.spec.js+++ b/e2e/test/scenarios/filters-reproductions/dashboard-filters-reproductions-2.cy.spec.js@@ -1732,7 +1732,7 @@ describe("issue 48824", { tags: "@skip" }, () => {it("should correctly translate relative filters in dashboards (metabase#48824)", () => {cy.log("set locale");cy.request("GET", "/api/user/current").then(({ body: user }) => {- cy.request("PUT", `/api/user/${user.id}`, { locale: "de" });+ cy.request("PUT", `/api/user/${user.id}`, { locale: "en-ZZ" });});cy.log("add a date parameter with a relative default value to a dashboard");@@ -1761,12 +1761,12 @@ describe("issue 48824", { tags: "@skip" }, () => {});cy.log("Previous 30 days");- H.filterWidget().findByText("Vorheriger 30 Tage").should("be.visible");+ H.filterWidget().findByText("[zz] Previous 30 days").should("be.visible");H.filterWidget().icon("revert").click();cy.log("Previous 30 days, starting 7 days ago");H.filterWidget()- .findByText("Vorheriger 30 Tage, ab vor 7 tage")+ .findByText("[zz] Previous 30 days, [zz] starting 7 days ago").should("be.visible");});});diff --git a/e2e/test/scenarios/models/reproductions.cy.spec.js b/e2e/test/scenarios/models/reproductions.cy.spec.jsindex 475e62ed2d5..2c14623b673 100644--- a/e2e/test/scenarios/models/reproductions.cy.spec.js+++ b/e2e/test/scenarios/models/reproductions.cy.spec.js@@ -399,12 +399,12 @@ describe("issue 25537", () => {});it("should be able to pick a saved model when using a non-english locale (metabase#25537)", () => {- setLocale("de");+ setLocale("en-ZZ");H.createQuestion(questionDetails);H.startNewQuestion();H.miniPicker().within(() => {- cy.findByText("Unsere Analysen").click();+ cy.findByText("[zz] Our analytics").click();cy.findByText(questionDetails.name).should("exist");});});diff --git a/e2e/test/scenarios/onboarding/setup/setup.cy.spec.ts b/e2e/test/scenarios/onboarding/setup/setup.cy.spec.tsindex f145b26ceb8..61974fdc889 100644--- a/e2e/test/scenarios/onboarding/setup/setup.cy.spec.ts+++ b/e2e/test/scenarios/onboarding/setup/setup.cy.spec.ts@@ -12,6 +12,7 @@ describe("scenarios > setup", () => {beforeEach(() => {H.restore("blank");H.resetSnowplow();+ cy.intercept("GET", "/app/locales/*").as("getTranslations");});locales.forEach((locale) => {@@ -314,41 +315,35 @@ describe("scenarios > setup", () => {"/setup?first_name=John&last_name=Doe&[email protected]&site_name=Doe%20Unlimited&use_case=embedding",);- cy.log("English is the initial language");- cy.get("header")- .should("be.visible")- .findByLabelText("Select a language")- .should("have.value", "English")- .click();-- H.popover().findByText("Dutch").should("be.visible").click();+ cy.log("Change language to English (ZZ)");+ selectLanguage("English (ZZ)");cy.log("Changing a language should be applied immediately");cy.findByTestId("setup-forms").within(() => {const password = "12341234";cy.findByDisplayValue("John").should("exist");- cy.findByLabelText("Maak een wachtwoord").type(password);- cy.findByLabelText("Bevestig je wachtwoord").type(password);- cy.button("Volgende").click();+ cy.findByLabelText("[zz] Create a password").type(password);+ cy.findByLabelText("[zz] Confirm your password").type(password);+ cy.button("[zz] Next").click();});cy.findByTestId("setup-forms").within(() => {- cy.findByLabelText("Hallo, John. Leuk je te ontmoeten!").should(+ cy.findByLabelText("[zz] Hi, John. Nice to meet you!").should("be.visible",);if (IS_ENTERPRISE) {- cy.button("Ik activeer later").click();+ cy.button("[zz] I'll activate later").click();}- cy.findByText("Voltooi").click();- cy.findByText("Breng me naar Metabase").click();+ cy.findByText("[zz] Finish").click();+ cy.findByText("[zz] Take me to Metabase").click();});- cy.log("Locale is preserved upon succesful setup");+ cy.log("Locale is preserved upon successful setup");cy.location("pathname").should("eq", "/");H.main()- .findByText("Aan de slag met het opnemen van Metabase in uw app")+ .findByText("[zz] Get started with Embedding Metabase in your app").should("be.visible");});@@ -359,57 +354,46 @@ describe("scenarios > setup", () => {"/setup?first_name=John&last_name=Doe&[email protected]&site_name=Doe%20Unlimited&use_case=embedding",);- cy.log("Change language to Dutch before user creation");- cy.get("header")- .should("be.visible")- .findByLabelText("Select a language")- .should("have.value", "English")- .click();-- H.popover().findByText("Dutch").should("be.visible").click();-- cy.log("Verify site locale does not get updated before a user is created");+ cy.log("Switching language before user creation should not update setting");+ selectLanguage("Dutch");+ cy.get("@updateSiteLocale.all").should("have.length", 0);+ selectLanguage("English (ZZ)");cy.get("@updateSiteLocale.all").should("have.length", 0);cy.findByTestId("setup-forms").within(() => {const password = "12341234";cy.findByDisplayValue("John").should("exist");- cy.findByLabelText("Maak een wachtwoord").type(password);- cy.findByLabelText("Bevestig je wachtwoord").type(password);- cy.button("Volgende").click();+ cy.findByLabelText("[zz] Create a password").type(password);+ cy.findByLabelText("[zz] Confirm your password").type(password);+ cy.button("[zz] Next").click();- cy.findByLabelText("Hallo, John. Leuk je te ontmoeten!").should(- "be.visible",- );+ cy.findByLabelText("[zz] Hi, John. Nice to meet you!")+ .scrollIntoView()+ .should("be.visible");});- cy.log("After user creation, change language to German");- cy.get("header")- .should("be.visible")- .findByLabelText("Selecteer een taal")- .should("have.value", "Dutch")- .click();-- H.popover()- .findByText("German")- .scrollIntoView()- .should("be.visible")- .click();+ cy.log(+ "After user creation, switching the language should update the setting",+ );+ selectLanguage("English");+ cy.get("@updateSiteLocale.all").should("have.length", 1);+ selectLanguage("English (ZZ)");+ cy.get("@updateSiteLocale.all").should("have.length", 2);cy.findByTestId("setup-forms").within(() => {- cy.findByText("Ich aktiviere später").click();- cy.findByText("Beenden").click();- cy.findByText("Führe mich zu Metabase").click();+ if (IS_ENTERPRISE) {+ cy.findByText("[zz] I'll activate later").click();+ }+ cy.findByText("[zz] Finish").click();+ cy.findByText("[zz] Take me to Metabase").click();});cy.location("pathname").should("eq", "/");- cy.log("Verify final language (German) is preserved");+ cy.log("Verify the final language English (ZZ) is preserved");H.main()- .findByText(- "Erste Schritte mit der Einbettung der Metabase in Ihre Anwendung",- )+ .findByText("[zz] Get started with Embedding Metabase in your app").should("be.visible");});@@ -793,3 +777,18 @@ const navigateToDatabaseStep = () => {cy.log("We are now on the database step");};++const selectLanguage = (targetLanguage: string) => {+ cy.findByTestId("language-selector").click();++ cy.log("Select language from dropdown");+ H.popover()+ .findByText(targetLanguage)+ .scrollIntoView()+ .should("be.visible")+ .click();++ if (targetLanguage !== "English") {+ cy.wait("@getTranslations");+ }+};diff --git a/e2e/test/scenarios/question/notebook.cy.spec.js b/e2e/test/scenarios/question/notebook.cy.spec.jsindex 9961d61bf27..cabae85ab65 100644--- a/e2e/test/scenarios/question/notebook.cy.spec.js+++ b/e2e/test/scenarios/question/notebook.cy.spec.js@@ -1069,7 +1069,7 @@ describe("scenarios > question > notebook", { tags: "@slow" }, () => {it("Correctly translates aggregations", () => {cy.request("PUT", `/api/user/${ADMIN_USER_ID}`, {- locale: "de",+ locale: "en-ZZ",});H.openTable({@@ -1077,13 +1077,13 @@ describe("scenarios > question > notebook", { tags: "@slow" }, () => {mode: "notebook",});- cy.findByRole("button", { name: "Zusammenfassen" }).click();+ cy.findByRole("button", { name: "[zz] Summarize" }).click();H.popover().within(() => {- cy.findByText("Durchschnitt von...").click();+ cy.findByText("[zz] Average of ...").click();cy.findByText("Subtotal").click();});- cy.findAllByText("Durchschnitt von Subtotal").should("exist");+ cy.findAllByText("[zz] Average of Subtotal").should("exist");cy.findAllByText("Average of Subtotal").should("not.exist");cy.request("PUT", `/api/user/${ADMIN_USER_ID}`, {diff --git a/e2e/test/scenarios/visualizations-tabular/drillthroughs/column_extract_drill.cy.spec.js b/e2e/test/scenarios/visualizations-tabular/drillthroughs/column_extract_drill.cy.spec.jsindex ca07021648c..89a991320b5 100644--- a/e2e/test/scenarios/visualizations-tabular/drillthroughs/column_extract_drill.cy.spec.js+++ b/e2e/test/scenarios/visualizations-tabular/drillthroughs/column_extract_drill.cy.spec.js@@ -237,14 +237,15 @@ describe("extract action", { viewportWidth: 1600 }, () => {it("should use current user locale for string expressions", () => {cy.request("GET", "/api/user/current").then(({ body: user }) => {- cy.request("PUT", `/api/user/${user.id}`, { locale: "de" });+ cy.request("PUT", `/api/user/${user.id}`, { locale: "en-ZZ" });});H.openOrdersTable({ limit: 1 });extractColumnAndCheck({column: "Created At",- option: "Wochentag",- value: "Freitag",- extraction: "Auszug Tag, Monat…",+ option: "[zz] Day of week",+ // dayjs has no en-ZZ locale, so it falls back to English day names+ value: "Friday",+ extraction: "[zz] Extract day, month…",});});});diff --git a/e2e/test/scenarios/visualizations-tabular/visualizations-tabular-reproductions.cy.spec.js b/e2e/test/scenarios/visualizations-tabular/visualizations-tabular-reproductions.cy.spec.jsindex e4e561247d4..eb73012157a 100644--- a/e2e/test/scenarios/visualizations-tabular/visualizations-tabular-reproductions.cy.spec.js+++ b/e2e/test/scenarios/visualizations-tabular/visualizations-tabular-reproductions.cy.spec.js@@ -406,18 +406,18 @@ describe("issue 23076", () => {cy.signInAsAdmin();cy.request("PUT", `/api/user/${ADMIN_USER_ID}`, {- locale: "de",+ locale: "en-ZZ",});H.createQuestion(questionDetails, { visitQuestion: true });});it("should correctly translate dates (metabase#23076)", () => {- cy.findAllByText(/^Summen für/, { timeout: 10000 })+ cy.findAllByText(/^\[zz\] Totals for/).should("be.visible").eq(1).invoke("text")- .should("eq", "Summen für Mai 2026");+ .should("eq", "[zz] Totals for May 2026");});});diff --git a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/Filter/FilterDropdown/FilterDropdown.tsx b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/Filter/FilterDropdown/FilterDropdown.tsxindex c29b698018b..ce6b073a7b6 100644--- a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/Filter/FilterDropdown/FilterDropdown.tsx+++ b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/Filter/FilterDropdown/FilterDropdown.tsx@@ -79,6 +79,7 @@ const FilterDropdownInner = ({step === null ? (filters.length === 0 ? "picker" : "list") : null,)}+ data-testid="filter-dropdown-button"/></MultiStepPopover.Target>diff --git a/frontend/src/metabase/dashboard/components/DashboardHeader/buttons/SaveEditButton.tsx b/frontend/src/metabase/dashboard/components/DashboardHeader/buttons/SaveEditButton.tsxindex 2ab3212ec5a..83492e686bc 100644--- a/frontend/src/metabase/dashboard/components/DashboardHeader/buttons/SaveEditButton.tsx+++ b/frontend/src/metabase/dashboard/components/DashboardHeader/buttons/SaveEditButton.tsx@@ -62,6 +62,7 @@ export const SaveEditButton = () => {failedText={t`Save failed`}successText={t`Saved`}disabled={isSaveDisabled}+ data-testid="save-edit-button"/></span></Tooltip>diff --git a/frontend/src/metabase/public/LocaleProvider.tsx b/frontend/src/metabase/public/LocaleProvider.tsxindex 367d0cd1d4e..1ac8eae104e 100644--- a/frontend/src/metabase/public/LocaleProvider.tsx+++ b/frontend/src/metabase/public/LocaleProvider.tsx@@ -88,7 +88,7 @@ export const getLocaleToUse = (if (!locale) {return "en";}- const [language, country] = locale.split("-");+ const [language, country] = locale.split(/[-_]/);const normalizedLanguage = language.toLowerCase();const normalizedCountry = country?.toUpperCase();diff --git a/frontend/src/metabase/querying/common/components/DatePicker/DateShortcutPicker/DateShortcutPicker.tsx b/frontend/src/metabase/querying/common/components/DatePicker/DateShortcutPicker/DateShortcutPicker.tsxindex 8dbcd6adde3..23397108e07 100644--- a/frontend/src/metabase/querying/common/components/DatePicker/DateShortcutPicker/DateShortcutPicker.tsx+++ b/frontend/src/metabase/querying/common/components/DatePicker/DateShortcutPicker/DateShortcutPicker.tsx@@ -72,6 +72,7 @@ export function DateShortcutPicker({display="block"variant="subtle"onClick={() => onSelectType(option.type)}+ data-testid={`date-picker-type-${option.type}`}>{option.label}</Button>diff --git a/frontend/src/metabase/setup/components/LanguageSelector/LanguageSelector.tsx b/frontend/src/metabase/setup/components/LanguageSelector/LanguageSelector.tsxindex 9599ce4bc39..dc6ea9b3b53 100644--- a/frontend/src/metabase/setup/components/LanguageSelector/LanguageSelector.tsx+++ b/frontend/src/metabase/setup/components/LanguageSelector/LanguageSelector.tsx@@ -2,11 +2,11 @@ import { useMemo } from "react";import { t } from "ttag";import { findWhere } from "underscore";-import { useUpdateSettingsMutation } from "metabase/api";+import { useUpdateSettingMutation } from "metabase/api";import {getAvailableLocales,+ getIsStepCompleted,getLocale,- getUser,} from "metabase/setup/selectors";import { Select } from "metabase/ui";import { useDispatch, useSelector } from "metabase/utils/redux";@@ -18,8 +18,10 @@ export const LanguageSelector = () => {const dispatch = useDispatch();const locale = useSelector(getLocale);const localeData = useSelector(getAvailableLocales);- const user = useSelector(getUser);- const [updateSettings] = useUpdateSettingsMutation();+ const [updateSetting] = useUpdateSettingMutation();+ const isUserInfoStepCompleted = useSelector((state) =>+ getIsStepCompleted(state, "user_info"),+ );const locales = useMemo(() => getLocales(localeData), [localeData]);const languages = useMemo(() => locales.map(({ name }) => name), [locales]);@@ -32,8 +34,8 @@ export const LanguageSelector = () => {// Only update site-locale setting if the user has been created.// This prevents the API request from failing before the user creation step.- if (user) {- await updateSettings({ "site-locale": locale.code });+ if (isUserInfoStepCompleted) {+ await updateSetting({ key: "site-locale", value: locale.code });}}};@@ -45,10 +47,11 @@ export const LanguageSelector = () => {return (<Selectaria-label={t`Select a language`}+ comboboxProps={{ width: "12.5rem", position: "bottom-end" }}+ data-testid="language-selector"data={languages}- value={locale?.name || "English"}onChange={handleLocaleChange}- comboboxProps={{ width: "12.5rem", position: "bottom-end" }}+ value={locale?.name || "English"}/>);};diff --git a/src/metabase/util/i18n.clj b/src/metabase/util/i18n.cljindex daa470e0041..34fdadb6c55 100644--- a/src/metabase/util/i18n.clj+++ b/src/metabase/util/i18n.clj@@ -62,13 +62,36 @@^Locale [](locale (user-locale-string)))+(def ^:private test-only-locales+ "Locales that are hidden from language pickers unless `MB_ENABLE_TEST_LOCALES=true`.+ Currently just the `en_ZZ` pseudo-locale. See UXW-3460."+ #{"en_ZZ"})++(def ^:private locale-display-name-overrides+ "Custom display names for locales whose JVM default is confusing. The JVM renders `en_ZZ` as+ \"English (Unknown Region)\" because it has no CLDR data for the user-assigned region code `ZZ`. We override it to+ \"English (ZZ)\" which is clearer for developers choosing it in the language picker."+ {"en_ZZ" "English (ZZ)"})++(defn- show-test-locales?+ "Whether test-only pseudo-locales like `en_ZZ` should appear in language pickers.+ True when the `MB_ENABLE_TEST_LOCALES` env var is explicitly set to `\"true\"`+ (e.g. by the Cypress runner or local dev environment)."+ []+ (= "true" (System/getenv "MB_ENABLE_TEST_LOCALES")))+(defn available-locales-with-names"Returns all locale abbreviations and their full names"[]- (for [locale-name (i18n.impl/available-locale-names)]- ;; Abbreviation must be normalized or the language picker will show incorrect saved value- ;; because the locale is normalized before saving (metabase#15657, metabase#16654)- [(normalized-locale-string locale-name) (.getDisplayName (locale locale-name))]))+ ;; Test-only pseudo-locales (e.g. `en_ZZ`) are hidden unless `MB_ENABLE_TEST_LOCALES=true`.+ (let [show-test? (show-test-locales?)]+ (for [locale-name (i18n.impl/available-locale-names)+ ;; Abbreviation must be normalized or the language picker will show incorrect saved value+ ;; because the locale is normalized before saving (metabase#15657, metabase#16654)+ :let [normalized (normalized-locale-string locale-name)]+ :when (or show-test?+ (not (contains? test-only-locales normalized)))]+ [normalized (get locale-display-name-overrides normalized (.getDisplayName (locale locale-name)))])))(def ^:private included-locales(delay (set (map normalized-locale-string (i18n.impl/available-locale-names)))))diff --git a/src/metabase/util/i18n/impl.clj b/src/metabase/util/i18n/impl.cljindex 9b7b0743d28..eda0ea300a0 100644--- a/src/metabase/util/i18n/impl.clj+++ b/src/metabase/util/i18n/impl.clj@@ -55,13 +55,21 @@(str namespce \_ (name this))(name this)))))+(def ^:private extra-available-locales+ "Locales that aren't recognized by the JVM's CLDR data but which Metabase accepts for test purposes. Currently just+ the `en_ZZ` pseudo-locale used by E2E tests: every English string becomes `[zz] English`, so tests can verify the+ translation mechanism loaded correctly without depending on fragile real-language strings that change whenever+ Crowdin updates come in. See UXW-3460."+ #{"en_ZZ"})+(defn available-locale?"True if `locale` (a string, keyword, or `Locale`) is a valid locale available on this system. Normalizes args- automatically."+ automatically. Also accepts Metabase's internal custom locales (e.g., `en_ZZ` which is used for testing)."[locale-or-name](boolean- (when-let [locale (locale locale-or-name)]- (LocaleUtils/isAvailableLocale locale))))+ (when-let [loc (locale locale-or-name)]+ (or (LocaleUtils/isAvailableLocale loc)+ (contains? extra-available-locales (normalized-locale-string (str loc)))))))(defn- available-locale-names*[]diff --git a/test/metabase/util/i18n/impl_test.clj b/test/metabase/util/i18n/impl_test.cljindex 617c8c6954e..2a55abf9912 100644--- a/test/metabase/util/i18n/impl_test.clj+++ b/test/metabase/util/i18n/impl_test.clj@@ -64,6 +64,20 @@(is (= expected(i18n.impl/available-locale? locale))))))+(deftest ^:parallel available-locale?-accepts-pseudo-locale-test+ (testing "The `en_ZZ` pseudo-locale is accepted"+ (doseq [[locale expected] {"en_ZZ" true+ "en-ZZ" true+ "en-zz" true+ "EN-ZZ" true+ ;; Unrelated unknown locales are still rejected+ "zz" false+ "xx_YY" false+ "en_XX" false}]+ (testing (pr-str (list 'available-locale? locale))+ (is (= expected+ (i18n.impl/available-locale? locale)))))))+(deftest ^:parallel fallback-locale-test(doseq [[locale expected] {nil nil:es nil