Skip to content

Commit

Permalink
Fix Cldr.Currency.currency_from_locale
Browse files Browse the repository at this point in the history
  • Loading branch information
kipcole9 committed Jun 8, 2022
1 parent e5935c4 commit 8742ec9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## Cldr_Currencies v2.14.1

This is the changelog for Cldr_Currencies v2.14.1 released on June 8th, 2022. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr_currencies/tags)

### Bug Fixes

* Fix `Cldr.Currency.currency_from_locale/2` when the first argument is a `t:Cldr.LanguageTag.t/0`

## Cldr_Currencies v2.14.0

This is the changelog for Cldr_Currencies v2.14.0 released on June 4th, 2022. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr_currencies/tags)
Expand Down
11 changes: 9 additions & 2 deletions lib/cldr/currency.ex
Original file line number Diff line number Diff line change
Expand Up @@ -567,12 +567,19 @@ defmodule Cldr.Currency do
:INR
"""
def currency_from_locale(locale, backend \\ default_backend()) when is_binary(locale) do
with {:ok, locale} <- Cldr.validate_locale(locale, backend) do
def currency_from_locale(locale, backend \\ nil)

def currency_from_locale(locale, backend) when is_binary(locale) do
with {locale, backend} <- Cldr.locale_and_backend_from(locale, backend),
{:ok, locale} <- Cldr.validate_locale(locale, backend) do
currency_from_locale(locale)
end
end

def currency_from_locale(%LanguageTag{} = locale, _backend) do
currency_from_locale(locale)
end

@doc """
Returns the effective currency format for a given locale
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Cldr.Currencies.MixProject do
use Mix.Project

@version "2.14.0"
@version "2.14.1"

def project do
[
Expand Down
9 changes: 9 additions & 0 deletions test/cldr_currencies_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,13 @@ defmodule Cldr.Currency.Test do
{:ok, currency} = Cldr.Currency.currency_for_code(:AUD, MyApp.Cldr)
assert to_string(currency) == "Australian Dollar"
end

test "Currency from locale" do
{:ok, locale} = Cldr.validate_locale("fr", MyApp.Cldr)
assert _currency = Cldr.Currency.currency_from_locale(locale, MyApp.Cldr)
end

test "Currency from binary locale" do
assert _currency = Cldr.Currency.currency_from_locale("fr")
end
end
File renamed without changes.

0 comments on commit 8742ec9

Please sign in to comment.