tonsky / tongue

Do-it-yourself i18n library for Clojure/Script
Eclipse Public License 1.0
311 stars 20 forks source link

translation fns with arguments that return hiccup vectors fail #37

Open logseq-cldwalker opened 1 year ago

logseq-cldwalker commented 1 year ago

Hi @tonsky. With 0.4.4, I've started using arbitrary functions for translations recently and they work great for returning hiccup vectors with no arguments. However, when I pass arguments to these functions, I get a failure with trying to return a hiccup vector e.g.:

;; Invocation
(t :settings-permission/grant-permission "some-value-from-an-app-fn")
;; Dictionary entry
:settings-permission/grant-permission (fn [dir] [:p "Grant native filesystem permission for directory: " [:b dir]])

;; Results in
Error: No protocol method IInterpolate.interpolate-positional defined for type cljs.core/PersistentVector: [:p "Grant native filesystem permission for directory: " [:b "trash-notes"]]
    at Object.cljs$core$missing_protocol [as missing_protocol] (./js/cljs-runtime/cljs.core.js:314:9)
    at tongue$core$IInterpolate$interpolate_positional$dyn_234987 (./js/cljs-runtime/tongue.core.js:159:17)
    at Object.tongue$core$interpolate_positional [as interpolate_positional] (./js/cljs-runtime/tongue.core.js:170:8)

The reason I'm returning hiccup for some cases is because I need to support formatting in a phrase while allowing a language to choose word order e.g. this 3 word Turkish example. Happy to submit a PR for this if you're willing. Any code pointers appreciated. Thanks again for the handy library!

tonsky commented 1 year ago

Sounds good!