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
9464e002
Unverified
Commit
9464e002
authored
6 years ago
by
Ryan Senior
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #8570 from metabase/fail-safe-i18n-translate
Make a fail-safe i18n translate function
parents
ac2210e9
d7396dd3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/metabase/util/i18n.clj
+17
-2
17 additions, 2 deletions
src/metabase/util/i18n.clj
with
17 additions
and
2 deletions
src/metabase/util/i18n.clj
+
17
−
2
View file @
9464e002
(
ns
metabase.util.i18n
(
:refer-clojure
:exclude
[
ex-info
])
(
:require
[
cheshire.generate
:as
json-gen
]
[
clojure.tools.logging
:as
log
]
[
clojure.walk
:as
walk
]
[
puppetlabs.i18n.core
:as
i18n
:refer
[
available-locales
]]
[
schema.core
:as
s
])
...
...
@@ -16,10 +17,24 @@
[
locale
]
(
Locale/setDefault
(
Locale/forLanguageTag
locale
)))
(
defn-
translate
"A failsafe version of `i18n/translate`. Will attempt to translate `msg` but if for some reason we're not able
to (such as a typo in the translated version of the string), log the failure but return the original (untranslated)
string. This is a workaround for translations that, due to a typo, will fail to parse using Java's message
formatter."
[
ns-str
msg
args
]
(
try
(
apply
i18n/translate
ns-str
(
i18n/user-locale
)
msg
args
)
(
catch
IllegalArgumentException
e
;; Not translating this string to prevent an unfortunate stack overflow. If this string happened to be the one
;; that had the typo, we'd just recur endlessly without logging an error.
(
log/errorf
e
"Unable to translate string '%s'"
msg
)
msg
)))
(
defrecord
UserLocalizedString
[
ns-str
msg
args
]
java.lang.Object
(
toString
[
_
]
(
apply
i18n/
translate
ns-str
(
i18n/user-locale
)
msg
args
))
(
translate
ns-str
msg
args
))
schema.core.Schema
(
explain
[
this
]
(
str
this
)))
...
...
@@ -27,7 +42,7 @@
(
defrecord
SystemLocalizedString
[
ns-str
msg
args
]
java.lang.Object
(
toString
[
_
]
(
apply
i18n/
translate
ns-str
(
i18n/system-locale
)
msg
args
))
(
translate
ns-str
msg
args
))
s/Schema
(
explain
[
this
]
(
str
this
)))
...
...
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