tonsky / tongue

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

Feature/add substitution way fo map #22

Closed katsuyasu-murata closed 5 years ago

katsuyasu-murata commented 5 years ago

Issues

21 Add a substitution way for map

Fixes

tonsky commented 5 years ago

I’m happy to accept this, but:

Apart from that code looks good and the idea is great as well. I think it will make a good addition. Thanks!

katsuyasu-murata commented 5 years ago

@tonsky Thank you for reviewing my PR!

I would prefer if it uses same {xxx} syntax. The idea of Tongue was that everything is formatted using same expression so you don’t have to remember anything else

-> I hope Tongue allow us to use %{xxx} syntax, because we want to use same dictionaries as other programming servers without changes. (For example, Rails and Clojure)

Map keys should be keywords, not strings. This is simply more idiomatic in Clojure

-> Thank you! I've fix it so that map's key use keyword.

tonsky commented 5 years ago

same dictionaries as other programming servers

Can you point me at exact name of libraries that use that syntax?

Also: you want to share dictionaries between different systems? Or what is your use-case?

katsuyasu-murata commented 5 years ago

@tonsky

Can you point me at exact name of libraries that use that syntax?

The syntax is used in Ruby on Rails. We use the gem below url. https://github.com/svenfuchs/rails-i18n. Example↓

en:
  activerecord:
    errors:
      messages:
        record_invalid: 'Validation failed: %{errors}'

Also: you want to share dictionaries between different systems? Or what is your use-case?

I want to share dictionaries between different systems. We consider that a Clojure server receives message from a Rails server and the Clojure server send push notifications. In case of this, we want to share dictionaries in the same service. For example, we want to use a same sentence between a confirm message in the Rails server view and a push notification message in the Clojure server.

tonsky commented 5 years ago

That’s a complete different syntax. Clojure uses EDN, while this is something indentation-based? That tells me that you’ll need to convert between dictionary formats anyway. So why not convert %{} to {} during the same step.

katsuyasu-murata commented 5 years ago

@tonsky Thank you for pointing out the %{} syntax. I gradually feel that it is not good to handle the %{} syntax in the tongue. I removed the %{} syntax handling, but I want to leave the map handling so it is useful.

tonsky commented 5 years ago

Ok thanks, I’ll take a look later

tonsky commented 5 years ago

Thanks! Pushed as 0.2.7