tonsky / tongue

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

Return nil when translation key is missing #32

Closed AndyCorlin closed 2 years ago

AndyCorlin commented 2 years ago

Hello, thanks for this very useful library!

When a key cannot be found, tounge returns: (str "{Missing key " key "}")

We want to have our own handling for this, and are thus parsing the result for "Missing key". In that case it would be more convenient if the function just returned nil.

Can you think of a way to achieve that?

I guess it's not just a trivial change to remove it, since others might depend on the current return value. But would it be possible to make it optional with an extra argument or something?

tonsky commented 2 years ago

I’ll take a look soon, promise! I agree this is a worthy goal

tonsky commented 2 years ago

You can now add :tongue/missing-key to the dictionary, which needs to be a 1-positional string or nil. Hope it solves your problem? Let me know. Pushed 0.4.3.

AndyCorlin commented 2 years ago

Wow, that was fast!!

Looks very good!!!

Thank you Nikita 🙏🙏🙏

AndyCorlin commented 2 years ago

For the nil case it would have been convenient to have it on the top level, just like :tongue/fallback, but the advantage with having it for each language is that the string then can be localized, so I guess that's the most generic implementation.