↓ Ir para o conteúdo principal

← todas as notas

📎 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, and gettext to mix.deps
  • Run mix deps.get && mix deps.compile
  • Define Bazaar.Cldr with default_locale: "en", locales: ["en", "zh"], gettext: Bazaar.Gettext, and providers: [Cldr.Number]
  • Add /priv/cldr/ to .gitignore because 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"}