📎 Webclip
Elixir currency and localized number format
The post explains how to add ISO localization support in an Elixir app using ex_cldr, ex_cldr_numbers, jason, and gettext. It then shows a Cldr module configured with en as the default locale and en and zh enabled.
Reading notes#
- Add
ex_cldr,ex_cldr_numbers,jason, andgettexttomix.deps - Run
mix deps.get && mix deps.compile - Define
Bazaar.Cldrwithdefault_locale: "en",locales: ["en", "zh"],gettext: Bazaar.Gettext, andproviders: [Cldr.Number] - Add
/priv/cldr/to.gitignorebecause the localization files are downloaded during compilation - Start IEx with
iex -S mix - Call
Bazaar.Cldr.Number.to_string 1231231, locale: "zh", currency: "USD" - The example returns
{:ok, "US$1,231,231.00"}
