tonsky / tongue

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

[feature request]: Translation key as vector (similar to how get-in works) #27

Open kirillsalykin opened 3 years ago

kirillsalykin commented 3 years ago

In some scenarios accessing translation by namespaced key overcomplicates things, just vector with path can work.

Consider this scenario: You want to show a document title per type.

i18n.clj

...
        :documents {:type1 {:title "type1"
                                           :filename "f1"}
                              :type2 {:title "type2"
                                           :filename "f2"}
                              :type1 {:title "type3"
                                           :filename "f3"}
(for [t [:type1 :type2 :type3]
  (translate :en (keyword (str "documents." (name t)) "filename" )))

This adds keyword manipulation.

Compare with

(for [t [:type1 :type2 :type3]
  (translate :en [:documents t :filename])))

This feels way simpler and cleaner.

What do you think?

tonsky commented 3 years ago

Yes, looks good. Want to make a PR?

kirillsalykin commented 3 years ago

Will try to make one, may take a while tho.