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
95775665
Commit
95775665
authored
7 years ago
by
Simon Belak
Browse files
Options
Downloads
Patches
Plain Diff
Extract translatable strings from rules and dump them into a pot
parent
f3de84c6
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
project.clj
+2
-2
2 additions, 2 deletions
project.clj
src/metabase/automagic_dashboards/rules.clj
+55
-21
55 additions, 21 deletions
src/metabase/automagic_dashboards/rules.clj
with
57 additions
and
23 deletions
project.clj
+
2
−
2
View file @
95775665
...
...
@@ -11,7 +11,7 @@
"generate-sample-dataset"
[
"with-profile"
"+generate-sample-dataset"
"run"
]
"profile"
[
"with-profile"
"+profile"
"run"
"profile"
]
"h2"
[
"with-profile"
"+h2-shell"
"run"
"-url"
"jdbc:h2:./metabase.db"
"-user"
""
"-password"
""
"-driver"
"org.h2.Driver"
]
"
valid
ate-automagic-dashboards"
[
"with-profile"
"+
valid
ate-automagic-dashboards"
"run"
]}
"
gener
ate-automagic-dashboards
-pot
"
[
"with-profile"
"+
gener
ate-automagic-dashboards
-pot
"
"run"
]}
:dependencies
[[
org.clojure/clojure
"1.8.0"
]
[
org.clojure/core.async
"0.3.442"
]
[
org.clojure/core.match
"0.3.0-alpha4"
]
; optimized pattern matching library for Clojure
...
...
@@ -195,4 +195,4 @@
"-XX:+PrintGC"
]}
; print a message when garbage collection takes place
;; get the H2 shell with 'lein h2'
:h2-shell
{
:main
org.h2.tools.Shell
}
:
valid
ate-automagic-dashboards
{
:main
metabase.automagic-dashboards.rules
}})
:
gener
ate-automagic-dashboards
-pot
{
:main
metabase.automagic-dashboards.rules
}})
This diff is collapsed.
Click to expand it.
src/metabase/automagic_dashboards/rules.clj
+
55
−
21
View file @
95775665
...
...
@@ -4,20 +4,27 @@
[
clojure.string
:as
str
]
[
clojure.tools.logging
:as
log
]
[
metabase.automagic-dashboards.populate
:as
populate
]
[
metabase.query-processor.util
:as
qp.util
]
[
metabase.types
]
[
metabase.util
:as
u
]
[
metabase.util.schema
:as
su
]
[
puppetlabs.i18n.core
:as
i18n
:refer
[
tru
]]
[
schema
[
coerce
:as
sc
]
[
core
:as
s
]]
[
schema.spec.core
:as
spec
]
[
yaml.core
:as
yaml
])
(
:import
java.nio.file.Path
java.nio.file.FileSystems
java.nio.file.FileSystem
java.nio.file.Files
))
java.nio.file.Files
))
(
def
^
Long
^
:const
max-score
"Maximal (and default) value for heuristics scores."
100
)
(
s/defschema
TranslatableStr
"String marked for translation."
(
s/pred
string?
))
(
def
^
:private
Score
(
s/constrained
s/Int
#
(
<=
0
%
max-score
)
(
str
"0 <= score <= "
max-score
)))
...
...
@@ -27,7 +34,7 @@
(
def
^
:private
Metric
{
Identifier
{(
s/required-key
:metric
)
MBQL
(
s/required-key
:score
)
Score
(
s/optional-key
:name
)
s/
Str
}})
(
s/optional-key
:name
)
Translatable
Str
}})
(
def
^
:private
Filter
{
Identifier
{(
s/required-key
:filter
)
MBQL
(
s/required-key
:score
)
Score
}})
...
...
@@ -87,27 +94,27 @@
(
def
^
:private
CardDimension
{
Identifier
{(
s/optional-key
:aggregation
)
s/Str
}})
(
def
^
:private
Card
{
Identifier
{(
s/required-key
:title
)
s/
Str
{
Identifier
{(
s/required-key
:title
)
Translatable
Str
(
s/required-key
:score
)
Score
(
s/optional-key
:visualization
)
Visualization
(
s/optional-key
:text
)
s/
Str
(
s/optional-key
:text
)
Translatable
Str
(
s/optional-key
:dimensions
)
[
CardDimension
]
(
s/optional-key
:filters
)
[
s/Str
]
(
s/optional-key
:metrics
)
[
s/Str
]
(
s/optional-key
:limit
)
su/IntGreaterThanZero
(
s/optional-key
:order_by
)
[
OrderByPair
]
(
s/optional-key
:description
)
s/
Str
(
s/optional-key
:description
)
Translatable
Str
(
s/optional-key
:query
)
s/Str
(
s/optional-key
:width
)
Width
(
s/optional-key
:height
)
Height
(
s/optional-key
:group
)
s/Str
(
s/optional-key
:y_label
)
s/
Str
(
s/optional-key
:x_label
)
s/
Str
(
s/optional-key
:series_labels
)
[
s/
Str
]}})
(
s/optional-key
:y_label
)
Translatable
Str
(
s/optional-key
:x_label
)
Translatable
Str
(
s/optional-key
:series_labels
)
[
Translatable
Str
]}})
(
def
^
:private
Groups
{
Identifier
{(
s/required-key
:title
)
s/
Str
(
s/optional-key
:description
)
s/
Str
}})
{
Identifier
{(
s/required-key
:title
)
Translatable
Str
(
s/optional-key
:description
)
Translatable
Str
}})
(
def
^
{
:arglists
'
([
definition
])}
identifier
"Return `key` in `{key {}}`."
...
...
@@ -122,7 +129,7 @@
(
def
^
:private
DimensionForm
[(
s/one
(
s/constrained
(
s/cond-pre
s/Str
s/Keyword
)
(
comp
#
{
"
dimension
"
}
str/lower-case
name
))
(
comp
#
{
:
dimension
}
qp.util/normalize-token
))
"dimension"
)
(
s/one
s/Str
"identifier"
)
su/Map
])
...
...
@@ -141,8 +148,7 @@
(
dimension-form?
subform
)
[(
second
subform
)]
(
string?
subform
)
(
->>
subform
(
re-seq
#
"\[\[(\w+)\]\]"
)
(
map
second
))
:else
nil
)))
(
map
second
)))))
distinct
))
(
defn-
valid-metrics-references?
...
...
@@ -188,13 +194,13 @@
(
def
^
:private
Rules
(
constrained-all
{(
s/required-key
:title
)
s/
Str
{(
s/required-key
:title
)
Translatable
Str
(
s/required-key
:dimensions
)
[
Dimension
]
(
s/required-key
:cards
)
[
Card
]
(
s/required-key
:rule
)
s/Str
(
s/optional-key
:applies_to
)
AppliesTo
(
s/optional-key
:transient_title
)
s/
Str
(
s/optional-key
:description
)
s/
Str
(
s/optional-key
:transient_title
)
Translatable
Str
(
s/optional-key
:description
)
Translatable
Str
(
s/optional-key
:metrics
)
[
Metric
]
(
s/optional-key
:filters
)
[
Filter
]
(
s/optional-key
:groups
)
Groups
...
...
@@ -271,7 +277,8 @@
[(
->entity
table-type
)
(
->type
field-type
)]
[(
if
(
->
table-type
->entity
table-type?
)
(
->entity
table-type
)
(
->type
table-type
))])))}))
(
->type
table-type
))])))
TranslatableStr
#
(
tru
%
)}))
(
def
^
:private
rules-dir
"automagic_dashboards/"
)
...
...
@@ -344,10 +351,37 @@
(
keep
(
partial
load-rule
fs
))
doall
)))))
(
defn-
extract-i18n-strings
[
rule
]
(
let
[
strings
(
atom
[])]
((
spec/run-checker
(
fn
[
s
params
]
(
let
[
walk
(
spec/checker
(
s/spec
s
)
params
)]
(
fn
[
x
]
(
when
(
=
TranslatableStr
s
)
(
swap!
strings
conj
x
))
(
walk
x
))))
false
Rules
)
rule
)
@
strings
))
(
defn-
make-pot
[
strings
]
(
->>
strings
(
map
(
partial
format
"msgid \"%s\"\nmsgstr \"\"\n"
))
(
str/join
"\n"
)))
(
defn
-main
"Entry point for lein task `
valid
ate-automagic-dashboards`"
"Entry point for lein task `
gener
ate-automagic-dashboards
-pot
`"
[
&
_
]
(
dorun
(
load-rules
"tables"
))
(
dorun
(
load-rules
"metrics"
))
(
dorun
(
load-rules
"fields"
))
(
->>
(
concat
(
load-rules
"table"
)
(
load-rules
"metric"
)
(
load-rules
"field"
))
(
mapcat
(
fn
[
rule
]
(
conj
(
:indepth
rule
)
rule
)))
(
mapcat
(
comp
extract-i18n-strings
#
(
dissoc
%
:indepth
)))
distinct
make-pot
(
spit
"locales/automagic_dashboards.pot"
))
(
System/exit
0
))
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