This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-10
Channels
- # beginners (191)
- # boot (3)
- # cljs-dev (2)
- # clojure (46)
- # clojure-austin (1)
- # clojure-spec (4)
- # clojure-uk (32)
- # clojurescript (10)
- # clojurewerkz (3)
- # cursive (14)
- # datomic (88)
- # defnpodcast (1)
- # editors (2)
- # fulcro (2)
- # hoplon (3)
- # jobs (4)
- # jobs-discuss (1)
- # luminus (5)
- # lumo (6)
- # off-topic (13)
- # random (1)
- # re-frame (50)
- # reagent (245)
- # remote-jobs (1)
- # spacemacs (3)
- # specter (16)
- # uncomplicate (4)
I am trying to go recursively through a hiccup data structure
something like this
(def nested
[:div {:id "hello"}
[:a {:href ""} :welcome]])
and simply replace automaticaly (using the tongue library) every known symbol with its translation
so given this dictionary
(def dicts
"List of all the words/sentences that need localization"
{:en {:welcome "Welcome"}
:it {:welcome "Benvenuto"}})
I just tried this first
(s/transform
[s/ALL]
#(do
(print %)
(if (contains? dicts %)
(translate :en %)
%))
nested)
but it doesn't actually check :welcome, I also tried to follow the recursive example in the docs
(s/transform
(s/subselect TreeValues)
#(do
(print %)
(if (contains? dicts %)
(translate :en %)
%))
nested)
but it looks like it's the same thing
is it actually possible to do this somehow?
@andrea.crotti yes, that's easy
where can the target keywords reside? only map values or also in arbitrary vector values or map keys?
I think only in nested vectors
Since it's html text really
(def TreeValues
(recursive-path [] p
(if-path vector?
[ALL p]
STAY
)))
(def nested
[:div {:id "hello"}
[:a {:href ""} :welcome]])
(def dicts
{:en {:welcome "Welcome"}
:it {:welcome "Benvenuto"}})
(let [dict (:en dicts)]
(transform [TreeValues #(contains? dict %)] dict nested))
that's one way to do it
you can make it more precise by making a recursive path that doesn't go to the first 2 elements of vectors, so that you don't inadvertently translate the node type if something like :div
is used in the dictionary
Ah nice thanks I'll try it out