taoensso / tower

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

translate not working for locales fallback #37

Closed nixn closed 10 years ago

nixn commented 10 years ago

I wanted to use your library, but it's severly broken for tower/t(ranslate). As you describe in the README, (translate :en-US :example/foo) searches in :en-US, in :en and then in the fallback-locale (by default :en). But in reality that is not the case. It is really only searched in :en-US and in the fallback locale. When testing with another locale (:de-DE) that error hit me:

(tower/t :de-DE {:fallback-locale :en :dictionary {:en {:example {:today "today"} }, :de {:example {:today "heute"} } } :example/today)

gives "today" instead of "heute". Giving a :log-missing-translation-fn prints that :example/today was not found (missing).

Examining the code I was confirmed. tower.clj:426 (in 2.0.1) searches only for exact locale matches, because 'loc' is not handled. The comment (Try loc & parents) is unclear or misleading, because this line only tries the different given keys from k-or-ks, but not the 'parent' locale (:de for :de-DE, or :de-DE and :de for :de-DE-somevariant). The code afterwards (the second form of the 'or') handles only the missing case (fallback value or fallback locale), but again wrong (line 436) with the same type of error but the same comment (above).

ptaoussanis commented 10 years ago

Hi nixn, thanks for the report. Should be fixed as of v2.0.2.