taoensso / tower

i18n & L10n library for Clojure/Script
https://www.taoensso.com/tower
Eclipse Public License 1.0
277 stars 24 forks source link

Invalid locale exception when passing arguments to translation in sw locale #62

Closed okal closed 9 years ago

okal commented 9 years ago

This only seems to be affecting :sw locale and nothing else. This bug doesn't occur for missing locales, which I found interesting, but it still occurs for the :sw locale even when it's missing.

I created a repo to demonstrate the bug https://github.com/okal/tower-invalid-locale

ptaoussanis commented 9 years ago

Hi Okal, you've identified a small bug, thanks for contacting me about this.

The problem is that :sw is not a valid JVM locale. This shouldn't matter for translations, but currently does because the default make-t :fmt-fn is tower/fmt-str (which requires a valid JVM locale).

So this will only show up under the following conditions:

  1. The locale isn't a valid JVM locale.
  2. You're using the default string formatter.
  3. You're providing arguments for formatting.
  4. Your dictionary contains at least one entry for the [invalid] locale.

The fix will be to change the default :fmt-fn option for make-t, I'll try get to that in the next few days. In the meantime you can work around this by using only valid JVM locales, or by switching the make-t :fmt-fn option to:

(fn [_locale fmt & args] (apply taoensso.encore/format fmt args))

Hope that helps! Cheers :-)

okal commented 9 years ago

Thank you :-)

ptaoussanis commented 9 years ago

[com.taoensso/tower "3.1.0-beta3"] is now up on Clojars which should address this (please confirm?)

okal commented 9 years ago

Works beautifully, thank you.

okal commented 9 years ago

(Hope you don't mind that I closed it. Not very well-versed on GitHub issue etiquette.)

ptaoussanis commented 9 years ago

(Hope you don't mind that I closed it. Not very well-versed on GitHub issue etiquette.)

That's perfect, thank you :-) And thanks again for the detailed bug report. Cheers!