Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
305a91d5
Unverified
Commit
305a91d5
authored
2 years ago
by
metamben
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Select locale based on query param (#22600)
See
https://github.com/metabase/metabase/issues/22561
for context.
parent
095e0d91
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/server/routes/index.clj
+9
-7
9 additions, 7 deletions
src/metabase/server/routes/index.clj
test/metabase/server/routes/index_test.clj
+30
-3
30 additions, 3 deletions
test/metabase/server/routes/index_test.clj
with
39 additions
and
10 deletions
src/metabase/server/routes/index.clj
+
9
−
7
View file @
305a91d5
...
...
@@ -52,9 +52,11 @@
(
log/warn
(
.getMessage
e
))))))
(
fallback-localization
locale-string
)))
(
def
^
:private
^
{
:arglists
'
([])}
load-localization
"Load a JSON-encoded map of localized strings for the current user's Locale."
(
comp
(
memoize
load-localization*
)
#
(
i18n/user-locale-string
)))
(
let
[
load-fn
(
memoize
load-localization*
)]
(
defn-
load-localization
"Load a JSON-encoded map of localized strings for the current user's Locale."
[
locale-override
]
(
load-fn
(
or
locale-override
(
i18n/user-locale-string
)))))
(
defn-
load-inline-js*
[
resource-name
]
(
slurp
(
io/resource
(
format
"frontend_client/inline_js/%s.js"
resource-name
))))
...
...
@@ -69,14 +71,14 @@
(
log/error
e
message
)
(
throw
(
Exception.
message
e
))))))
(
defn-
load-entrypoint-template
[
entrypoint-name
embeddable?
uri
]
(
defn-
load-entrypoint-template
[
entrypoint-name
embeddable?
{
:keys
[
uri
params
]}
]
(
load-template
(
str
"frontend_client/"
entrypoint-name
".html"
)
(
let
[{
:keys
[
anon-tracking-enabled
google-auth-client-id
]
,
:as
public-settings
}
(
setting/user-readable-values-map
:public
)]
{
:bootstrapJS
(
load-inline-js
"index_bootstrap"
)
:googleAnalyticsJS
(
load-inline-js
"index_ganalytics"
)
:bootstrapJSON
(
escape-script
(
json/generate-string
public-settings
))
:localizationJSON
(
escape-script
(
load-localization
))
:localizationJSON
(
escape-script
(
load-localization
(
:locale
params
)
))
:language
(
hiccup.util/escape-html
(
public-settings/site-locale
))
:favicon
(
hiccup.util/escape-html
(
public-settings/application-favicon-url
))
:applicationName
(
hiccup.util/escape-html
(
public-settings/application-name
))
...
...
@@ -93,10 +95,10 @@
(
defn-
entrypoint
"Response that serves up an entrypoint into the Metabase application, e.g. `index.html`."
[
entrypoint-name
embeddable?
{
:keys
[
uri
]}
respond
_raise
]
[
entrypoint-name
embeddable?
request
respond
_raise
]
(
respond
(
->
(
response/response
(
if
(
init-status/complete?
)
(
load-entrypoint-template
entrypoint-name
embeddable?
uri
)
(
load-entrypoint-template
entrypoint-name
embeddable?
request
)
(
load-init-template
)))
(
response/content-type
"text/html; charset=utf-8"
))))
...
...
This diff is collapsed.
Click to expand it.
test/metabase/server/routes/index_test.clj
+
30
−
3
View file @
305a91d5
...
...
@@ -24,7 +24,7 @@
"translations"
{
""
{
"Your database has been added!"
{
"msgstr"
[
"¡Tu base de datos ha sido añadida!"
]}}}}
(
some->
(
binding
[
i18n/*user-locale*
"es"
]
(
#
'index/load-localization
))
(
#
'index/load-localization
nil
))
json/parse-string
(
update
"translations"
select-keys
[
""
])
(
update-in
[
"translations"
""
]
select-keys
[
"Your database has been added!"
]))))))
...
...
@@ -36,7 +36,7 @@
(
mt/suppress-output
(
some->
(
binding
[
i18n/*user-locale*
"xx"
]
(
#
'index/load-localization
))
(
#
'index/load-localization
nil
))
json/parse-string
))))))
(
deftest
english-test
...
...
@@ -45,5 +45,32 @@
"translations"
{
""
{
"Metabase"
{
"msgid"
"Metabase"
,
"msgstr"
[
"Metabase"
]}}}}
(
some->
(
binding
[
i18n/*user-locale*
"en"
]
(
#
'index/load-localization
))
(
#
'index/load-localization
nil
))
json/parse-string
)))))
(
deftest
override-localization-test
(
testing
"a valid override is honored no matter what the user locale is"
(
is
(
=
{
"charset"
"utf-8"
"headers"
{
"mime-version"
"1.0"
"content-type"
"text/plain; charset=UTF-8"
"content-transfer-encoding"
"8bit"
"x-generator"
"POEditor.com"
"project-id-version"
"Metabase"
"language"
"es"
"plural-forms"
"nplurals=2; plural=(n != 1);"
}
"translations"
{
""
{
"Your database has been added!"
{
"msgstr"
[
"¡Tu base de datos ha sido añadida!"
]}}}}
(
some->
(
binding
[
i18n/*user-locale*
"xx"
]
(
#
'index/load-localization
"es"
))
json/parse-string
(
update
"translations"
select-keys
[
""
])
(
update-in
[
"translations"
""
]
select-keys
[
"Your database has been added!"
])))))
(
testing
"an invalid override causes a fallback to English"
(
is
(
=
{
"headers"
{
"language"
"yy"
,
"plural-forms"
"nplurals=2; plural=(n != 1);"
}
"translations"
{
""
{
"Metabase"
{
"msgid"
"Metabase"
,
"msgstr"
[
"Metabase"
]}}}}
(
mt/suppress-output
(
some->
(
binding
[
i18n/*user-locale*
"xx"
]
(
#
'index/load-localization
"yy"
))
json/parse-string
))))))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment