Support localization in static embeds (#49441)
* Correct embedding hash options type semantically * Pass `X-Metabase-Locale` to embed downloads * wip locale header middleware * Allow smart scalar text to be translated * Stop using global variable * Add more details to embedding types * Extend the E2E util type and correct some properties types * Add e2e test * Fix dashboard name * Add a test for static embed question * Make a type name follows a convention Co-authored-by:Denis Berezin <denis.berezin@metabase.com> * Fix failed E2E tests due to missing default values * Fix public embed not working with `?locale` anymore * Revert "wip locale header middleware" This reverts commit 83d8d135. * Preserve locale when in the `as-admin` macro is used Motivating issue: ```shell ❯ http get 'http://localhost:3000/api/embed/dashboard/eyJhbGciOiJIUzI1NiJ9.eyJyZXNvdXJjZSI6eyJkYXNoYm9hcmQiOjEyfSwicGFyYW1zIjp7fX0.QZ-tEWpgJeSMUuaPfuH6_VQwM2yXNMcuureWCtHsszU/dashcard/162/card/124' x-metabase-locale:fr -pb | jq '.data|.cols|map(.display_name)' [ "State", "Count" ] ``` I'm running a query that has aggregated columns and it is returning the untranslated. Note that these are computed and dynamically given a display name. ```clojure (case tag :count (i18n/tru "Count") :cum-count (i18n/tru "Cumulative count")) ``` The problem is that we run embedding things as admin. And that gets the current user, which in embed and public spaces is nil, and so binds a nil to user-locale, which defaults to english when translating. After: ``` ❯ http get 'http://localhost:3000/api/embed/dashboard/eyJhbGciOiJIUzI1NiJ9.eyJyZXNvdXJjZSI6eyJkYXNoYm9hcmQiOjEyfSwicGFyYW1zIjp7fX0.QZ-tEWpgJeSMUuaPfuH6_VQwM2yXNMcuureWCtHsszU/dashcard/162/card/124' x-metabase-locale:fr -pb | jq '.data|.cols|map(.display_name)' [ "State", "Nombre de lignes" ] ❯ http get 'http://localhost:3000/api/embed/dashboard/eyJhbGciOiJIUzI1NiJ9.eyJyZXNvdXJjZSI6eyJkYXNoYm9hcmQiOjEyfSwicGFyYW1zIjp7fX0.QZ-tEWpgJeSMUuaPfuH6_VQwM2yXNMcuureWCtHsszU/dashcard/162/card/124' x-metabase-locale:zh -pb | jq '.data|.cols|map(.display_name)' [ "State", "行数" ] ❯ http get 'http://localhost:3000/api/embed/dashboard/eyJhbGciOiJIUzI1NiJ9.eyJyZXNvdXJjZSI6eyJkYXNoYm9hcmQiOjEyfSwicGFyYW1zIjp7fX0.QZ-tEWpgJeSMUuaPfuH6_VQwM2yXNMcuureWCtHsszU/dashcard/162/card/124 ' x-metabase-locale:es -pb | jq '.data|.cols|map(.display_name)' [ "State", "Contar" ] ``` This is fetching a dashboard's card which is a query of orders grouped by created at month, sum of total. --------- Co-authored-by:
Nicolò Pretto <info@npretto.com> Co-authored-by:
Denis Berezin <denis.berezin@metabase.com> Co-authored-by:
dan sutton <dan@dpsutton.com>
Showing
- e2e/support/helpers/e2e-embedding-helpers.js 24 additions, 9 deletionse2e/support/helpers/e2e-embedding-helpers.js
- e2e/test/scenarios/embedding/embedding-linked-filters.cy.spec.js 6 additions, 2 deletions...t/scenarios/embedding/embedding-linked-filters.cy.spec.js
- e2e/test/scenarios/embedding/embedding-native.cy.spec.js 3 additions, 1 deletione2e/test/scenarios/embedding/embedding-native.cy.spec.js
- e2e/test/scenarios/embedding/embedding-reproductions.cy.spec.js 98 additions, 0 deletions...st/scenarios/embedding/embedding-reproductions.cy.spec.js
- enterprise/frontend/src/embedding-sdk/components/public/MetabaseProvider.tsx 1 addition, 1 deletion.../src/embedding-sdk/components/public/MetabaseProvider.tsx
- frontend/src/metabase/dashboard/hooks/use-dashboard-url-params.ts 9 additions, 2 deletions.../src/metabase/dashboard/hooks/use-dashboard-url-params.ts
- frontend/src/metabase/dashboard/types/hash-options.ts 10 additions, 3 deletionsfrontend/src/metabase/dashboard/types/hash-options.ts
- frontend/src/metabase/lib/i18n.js 14 additions, 0 deletionsfrontend/src/metabase/lib/i18n.js
- frontend/src/metabase/public/LocaleProvider.tsx 6 additions, 3 deletionsfrontend/src/metabase/public/LocaleProvider.tsx
- frontend/src/metabase/public/containers/PublicOrEmbeddedDashboard/PublicOrEmbeddedDashboard.tsx 34 additions, 28 deletions...s/PublicOrEmbeddedDashboard/PublicOrEmbeddedDashboard.tsx
- frontend/src/metabase/public/containers/PublicOrEmbeddedDashboard/PublicOrEmbeddedDashboardPage.tsx 2 additions, 0 deletions...blicOrEmbeddedDashboard/PublicOrEmbeddedDashboardPage.tsx
- frontend/src/metabase/public/containers/PublicOrEmbeddedQuestion/PublicOrEmbeddedQuestion.tsx 22 additions, 19 deletions...ers/PublicOrEmbeddedQuestion/PublicOrEmbeddedQuestion.tsx
- frontend/src/metabase/public/hooks/use-embed-frame-options.ts 4 additions, 2 deletions...tend/src/metabase/public/hooks/use-embed-frame-options.ts
- frontend/src/metabase/public/lib/types.ts 16 additions, 0 deletionsfrontend/src/metabase/public/lib/types.ts
- src/metabase/server/middleware/session.clj 2 additions, 1 deletionsrc/metabase/server/middleware/session.clj
- test/metabase/server/middleware/session_test.clj 7 additions, 1 deletiontest/metabase/server/middleware/session_test.clj
Loading
Please register or sign in to comment