Skip to content

Commit

Permalink
BREAKING (rarely) - [#56] FIX strange JVM handling for locales #{:he …
Browse files Browse the repository at this point in the history
…:yi :id} (@juhani-hietikko)

The JVM's Locale constructor has some unexpected odd behaviour for
these locales:

> Locale's constructor has always converted three language codes to their
> earlier, obsoleted forms: he maps to iw, yi maps to ji, and id maps to in.
> This continues to be the case, in order to not break backwards
> compatibility.
- From http://docs.oracle.com/javase/8/docs/api/java/util/Locale.html

Before this fix:
  (kw-locale :he) => :iw,
  (kw-locale :iw) => :iw

  (kw-locale :yi) => :ji
  (kw-locale :ji) => :ji

  (kw-locale :id) => :in
  (kw-locale :in) => :in

After this fix:
  (kw-locale :he) => :he
  (kw-locale :iw) => :he

  (kw-locale :yi) => :yi
  (kw-locale :ji) => :yi

  (kw-locale :id) => :id
  (kw-locale :in) => :id

This will clearly be BREAKING for anyone with dictionaries using any of
the obsolete #{:iw :ji :in} locale keys.

MIGRATION INSTRUCTIONS
----------------------
Update any locale keys in your dictionaries by substituting
{:iw :he, :ji :yi, :in :id}
  • Loading branch information
ptaoussanis committed Feb 28, 2015
1 parent 27e589f commit 2f29516
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/taoensso/tower.cljx
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,24 @@
(let [loc-name
#+cljs (name (or ?loc :nil))
#+clj (if-let [jvm-loc (try-jvm-locale ?loc lang-only?)]
(str jvm-loc)
;; (str jvm-loc) ; No! See [1] in comments below
(.toLanguageTag ^Locale jvm-loc)
(name (or ?loc :nil)))
loc-name (str/replace loc-name "_" "-")
loc-name (if-not lang-only? loc-name
(first (str/split loc-name #"-")))]
(keyword loc-name)))))

(comment
;; [1] Ref. https://github.com/ptaoussanis/tower/issues/56 re: weird JVM
;; locale handling for certain locales:
[(str (Locale. "id")) (Locale. "id") (.toLanguageTag (Locale. "id"))
(kw-locale :id)]

(map #(kw-locale %) [nil :whatever-foo :en (jvm-locale :en) "en-GB" :jvm-default])
(map #(kw-locale % :lang-only) [nil :whatever-foo :en (jvm-locale :en) "en-GB" :jvm-default]))
(map #(kw-locale % :lang-only) [nil :whatever-foo :en (jvm-locale :en) "en-GB" :jvm-default])

)

;;;; Localization
;; The Java date API is a mess, but we (thankfully!) don't need much of it for
Expand Down

0 comments on commit 2f29516

Please sign in to comment.