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
c215eac3
Commit
c215eac3
authored
7 months ago
by
Nicolò Pretto
Browse files
Options
Downloads
Patches
Plain Diff
wip locale header middleware
parent
688b9ad9
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/handler.clj
+12
-0
12 additions, 0 deletions
src/metabase/server/handler.clj
src/metabase/util/i18n.clj
+7
-1
7 additions, 1 deletion
src/metabase/util/i18n.clj
with
19 additions
and
1 deletion
src/metabase/server/handler.clj
+
12
−
0
View file @
c215eac3
...
...
@@ -15,6 +15,7 @@
[
metabase.server.middleware.session
:as
mw.session
]
[
metabase.server.middleware.ssl
:as
mw.ssl
]
[
metabase.server.routes
:as
routes
]
[
metabase.util.i18n
:as
i18n
]
[
metabase.util.log
:as
log
]
[
ring.core.protocols
:as
ring.protocols
]
[
ring.middleware.cookies
:refer
[
wrap-cookies
]]
...
...
@@ -42,11 +43,22 @@
(
name
kkey
))
response
output-stream
)))
(
defn
wrap-locale-binding
"Sets *header-locale* with the value from X-Metabase-Locale"
[
handler
]
(
fn
[{
{
:strs
[
x-metabase-locale
]}
:headers,
:as
request
}
respond
raise
]
(
binding
[
i18n/*header-locale*
(
or
x-metabase-locale
nil
)]
(
handler
request
respond
raise
))))
(
def
^
:private
middleware
;; ▼▼▼ POST-PROCESSING ▼▼▼ happens from TOP-TO-BOTTOM
[
#
'mw.exceptions/catch-uncaught-exceptions
; catch any Exceptions that weren't passed to `raise`
#
'mw.exceptions/catch-api-exceptions
; catch exceptions and return them in our expected format
#
'mw.log/log-api-call
#
'wrap-locale-binding
#
'mw.browser-cookie/ensure-browser-id-cookie
; add cookie to identify browser; add `:browser-id` to the request
#
'mw.security/add-security-headers
; Add HTTP headers to API responses to prevent them from being cached
#
(
ring.json/wrap-json-body
%
{
:keywords?
true
})
; extracts json POST body and makes it available on request
...
...
This diff is collapsed.
Click to expand it.
src/metabase/util/i18n.clj
+
7
−
1
View file @
c215eac3
...
...
@@ -22,6 +22,10 @@
normalized-locale-string
translate
])
(
def
^
:dynamic
*header-locale*
"This will contain the value for the locale coming from `X-Metabase-Locale`"
nil
)
(
def
^
:dynamic
*user-locale*
"Bind this to a string, keyword, or `Locale` to set the locale for the current User. To get the locale we should
*use*, use the `user-locale` function instead."
...
...
@@ -44,7 +48,9 @@
"Locale string we should *use* for the current User (e.g. `tru` messages) -- `*user-locale*` if bound, otherwise the
system locale as a string."
[]
(
or
*user-locale*
(
or
*header-locale*
*user-locale*
(
site-locale-string
)))
(
defn
site-locale
...
...
This diff is collapsed.
Click to expand it.
Nicholas Bentley
@nbentley
mentioned in commit
70a8ab70
·
6 months ago
mentioned in commit
70a8ab70
mentioned in commit 70a8ab70a8b58ac52dc89108c24f4d098a00810f
Toggle commit list
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