Skip to content

Commit

Permalink
Release 2.33.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kipcole9 committed Apr 20, 2024
2 parents 2dbb8a4 + 7fb32cd commit facdf51
Show file tree
Hide file tree
Showing 19 changed files with 232 additions and 106 deletions.
20 changes: 19 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
# Changelog

## Cldr Numbers v2.33.0

This is the changelog for Cldr v2.33.0 released on April 21st, 2024. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr_numbers/tags)

### Enhancements

* Update to [CLDR 45.0](https://cldr.unicode.org/index/downloads/cldr-45) data.

* Support currency formatting when the given currency in a given locale uses a specific symbol that replaces the decimal separator. The only known example is the [Cape Verde escudo](https://en.wikipedia.org/wiki/Cape_Verdean_escudo). A formatted example formatting 20 CVE is `20$00`.

## Cldr Numbers v2.32.4

This is the changelog for Cldr v2.32.4 released on January 18th, 2023. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr_numbers/tags)

### Bug Fixes

<<<<<<< HEAD
* Fix formatting a number when a currency is specified but the format has no currency symbol. Closes [ex_money 162](https://github.com/kipcole9/money/issues/162).

## Cldr Numbers v2.32.3

This is the changelog for Cldr v2.32.3 released on November 2nd, 2023. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr_numbers/tags)
=======
* Fix formatting a number when a currency is specified but the format has no currency symbol. Closes [ex_money 162](https://github.com/kipcole9/money/issues/162).

## Cldr Numbers v2.32.3

This is the changelog for Cldr v2.32.0 released on November 2nd, 2023. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr_numbers/tags)
>>>>>>> cldr45
### Bug Fixes

Expand Down Expand Up @@ -48,7 +66,7 @@ This is the changelog for Cldr v2.32.0 released on September 4th, 2023. For old

### Deprecations

* `Cldr.Number.System.systems_with_digits/0` is deprecated in favour of `Cldr.Number.System.numeric_systems/0`.
* `Cldr.Number.System.systems_with_digits/0` is deprecated in favour of `Cldr.Number.System.numeric_systems/0`.

### Enhancements

Expand Down
35 changes: 21 additions & 14 deletions lib/cldr/number/backend/format.ex
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ defmodule Cldr.Number.Backend.Format do
* `{:error, {exception, message}}`
"""
@spec all_formats_for(LanguageTag.t() | Cldr.Locale.locale_name()) ::
{:ok, map()} | {:error, {module(), String.t()}}
@spec all_formats_for(Cldr.Locale.locale_reference()) ::
{:ok, %{System.system_name() => map()}} | {:error, {module(), String.t()}}

def all_formats_for(locale \\ unquote(backend).get_locale())

Expand All @@ -182,7 +182,7 @@ defmodule Cldr.Number.Backend.Format do
{:ok, 1}
"""
@spec minimum_grouping_digits_for(LanguageTag.t() | Cldr.Locale.locale_name()) ::
@spec minimum_grouping_digits_for(Cldr.Locale.locale_reference()) ::
{:ok, non_neg_integer} | {:error, {module(), String.t()}}

def minimum_grouping_digits_for(locale \\ unquote(backend).get_locale())
Expand Down Expand Up @@ -210,7 +210,7 @@ defmodule Cldr.Number.Backend.Format do
{:ok, %{fraction: %{first: 0, rest: 0}, integer: %{first: 3, rest: 3}}}
"""
@spec default_grouping_for(LanguageTag.t() | Cldr.Locale.locale_name()) ::
@spec default_grouping_for(Cldr.Locale.locale_reference()) ::
{:ok, map()} | {:error, {module(), String.t()}}

def default_grouping_for(locale \\ unquote(backend).get_locale())
Expand Down Expand Up @@ -244,7 +244,9 @@ defmodule Cldr.Number.Backend.Format do
locale_data
|> get_in([:number_systems, :default])

standard_format = number_formats[default_number_system].standard || @default_standard_format
standard_format =
number_formats[default_number_system].standard || @default_standard_format

{:ok, meta} = Cldr.Number.Format.Compiler.format_to_metadata(standard_format)

def default_grouping_for(%LanguageTag{cldr_locale_name: unquote(locale_name)}) do
Expand Down Expand Up @@ -286,16 +288,17 @@ defmodule Cldr.Number.Backend.Format do
* `minumum_digits` or
* raises an exception
* raises an exception.
## Examples
iex> #{inspect(__MODULE__)}.minimum_grouping_digits_for!("en")
1
"""
@spec minimum_grouping_digits_for!(LanguageTag.t() | Cldr.Locale.locale_name()) ::
non_neg_integer | no_return()
@dialyzer {:no_underspecs, minimum_grouping_digits_for!: 1}
@spec minimum_grouping_digits_for!(Cldr.Locale.locale_reference()) ::
non_neg_integer() | no_return()

def minimum_grouping_digits_for!(locale) do
case minimum_grouping_digits_for(locale) do
Expand All @@ -320,16 +323,20 @@ defmodule Cldr.Number.Backend.Format do
* `grouping` as a map or
* raises an exception
* raises an exception.
## Examples
iex> #{inspect(__MODULE__)}.default_grouping_for!(:en)
%{fraction: %{first: 0, rest: 0}, integer: %{first: 3, rest: 3}}
"""
@spec default_grouping_for!(LanguageTag.t() | Cldr.Locale.locale_name()) ::
map() | no_return()
@spec default_grouping_for!(Cldr.Locale.locale_reference()) ::
%{
fraction: %{first: non_neg_integer(), rest: non_neg_integer()},
integer: %{first: non_neg_integer(), rest: non_neg_integer()}
}
| no_return()

def default_grouping_for!(locale) do
case default_grouping_for(locale) do
Expand Down Expand Up @@ -370,13 +377,13 @@ defmodule Cldr.Number.Backend.Format do
* `{:ok, map}` where map is a map of decimal formats
keyed by number system or
* raises an exception
* raises an exception.
See `#{inspect(__MODULE__)}.Number.Format.all_formats_for/1` for further information.
"""
@spec all_formats_for!(LanguageTag.t() | Cldr.Locale.locale_name()) ::
map() | no_return()
@spec all_formats_for(Cldr.Locale.locale_reference()) ::
%{System.system_name() => map()} | no_return()

def all_formats_for!(locale \\ unquote(backend).get_locale()) do
case all_formats_for(locale) do
Expand Down
2 changes: 1 addition & 1 deletion lib/cldr/number/backend/number.ex
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ defmodule Cldr.Number.Backend.Number do
number | Decimal.t() | String.t(),
Keyword.t() | map()
) ::
String.t() | no_return()
String.t() | no_return()
def to_string!(number, options \\ default_options()) do
Cldr.Number.to_string!(number, unquote(backend), options)
end
Expand Down
6 changes: 3 additions & 3 deletions lib/cldr/number/backend/system.ex
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ defmodule Cldr.Number.Backend.System do
"""
@spec system_name_from(
Cldr.Number.System.system_name(),
Cldr.Locale.locale_name() | LanguageTag.t()
) :: {:ok, atom} | {:error, {module(), String.t()}}
Cldr.Locale.locale_reference()
) :: {:ok, Cldr.Number.System.system_name()} | {:error, {module(), String.t()}}

def system_name_from(system_name, locale) do
Cldr.Number.System.system_name_from(system_name, locale, unquote(backend))
Expand All @@ -362,7 +362,7 @@ defmodule Cldr.Number.Backend.System do
Cldr.Locale.locale_reference(),
Cldr.Number.System.system_name()
) ::
{:ok, list()} | {:error, tuple}
{:ok, list()} | {:error, {module(), String.t()}}

def number_systems_like(locale, number_system) do
Cldr.Number.System.number_systems_like(locale, number_system, unquote(backend))
Expand Down
2 changes: 1 addition & 1 deletion lib/cldr/number/format/compiler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ defmodule Cldr.Number.Format.Compiler do
defp currency_location(parts) do
location =
Enum.reduce_while(parts, 0, fn
{:currency, count}, offset -> {:halt, %{location: offset, symbol_count: count}}
{:currency, count}, offset -> {:halt, %{location: offset, symbol_count: count}}
_other, offset -> {:cont, offset + 1}
end)

Expand Down
24 changes: 21 additions & 3 deletions lib/cldr/number/format/meta.ex
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,30 @@ defmodule Cldr.Number.Format.Meta do
currency: nil,
format: [
positive: [format: "#"],
negative: [minus: '-', format: :same_as_positive]
negative: [minus: ~c"-", format: :same_as_positive]
],
number: 0

@typedoc "Metadata type that drives how to format a number"
@type t :: %__MODULE__{}
@type t :: %__MODULE__{
:currency => nil | Cldr.Currency.t(),
:exponent_digits => non_neg_integer(),
:exponent_sign => boolean(),
:format => [{:negative, [any(), ...]} | {:positive, [any(), ...]}, ...],
:fractional_digits => %{:max => non_neg_integer(), :min => non_neg_integer()},
:grouping => %{
:fraction => %{:first => non_neg_integer(), :rest => non_neg_integer()},
:integer => %{:first => non_neg_integer(), :rest => non_neg_integer()}
},
:integer_digits => %{:max => non_neg_integer(), :min => non_neg_integer()},
:multiplier => non_neg_integer(),
:number => non_neg_integer(),
:padding_char => String.t(),
:padding_length => non_neg_integer(),
:round_nearest => non_neg_integer(),
:scientific_rounding => non_neg_integer(),
:significant_digits => %{:max => non_neg_integer(), :min => non_neg_integer()}
}

@doc """
Returns a new number formatting metadata
Expand Down Expand Up @@ -333,6 +351,6 @@ defmodule Cldr.Number.Format.Meta do

@spec put_format(t(), Keyword.t()) :: t()
def put_format(%__MODULE__{} = meta, positive_format) do
put_format(meta, positive_format, minus: '-', format: :same_as_positive)
put_format(meta, positive_format, minus: ~c"-", format: :same_as_positive)
end
end
45 changes: 31 additions & 14 deletions lib/cldr/number/format/options.ex
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ defmodule Cldr.Number.Format.Options do
:symbol
]

@type fixed_formats :: :standard | :currency | :accounting | :short | :long
@type format :: binary() | fixed_formats()
@type fixed_format :: :standard | :currency | :accounting | :short | :long
@type format :: binary() | fixed_format()
@type currency_symbol :: :standard | :iso
@type short_format_styles ::
@type short_format_style ::
:currency_short
| :currency_long
| :currency_long_with_symbol
Expand Down Expand Up @@ -173,7 +173,8 @@ defmodule Cldr.Number.Format.Options do
# :narrow, the format to :currency

@doc false
defp maybe_adjust_currency_format(options, currency, :narrow, backend) when not is_nil(currency) do
defp maybe_adjust_currency_format(options, currency, :narrow, backend)
when not is_nil(currency) do
currency_format = derive_currency_format(options)

options
Expand All @@ -197,34 +198,43 @@ defmodule Cldr.Number.Format.Options do
options
end

defp set_default_fractional_digits(%{fractional_digits: nil, currency_digits: :accounting} = options, backend) do
defp set_default_fractional_digits(
%{fractional_digits: nil, currency_digits: :accounting} = options,
backend
) do
case Cldr.Currency.currency_for_code(options.currency, backend, locale: options.locale) do
{:ok, currency} ->
Map.put(options, :fractional_digits, currency.digits)

_other ->
options
end
end
end

defp set_default_fractional_digits(%{fractional_digits: nil, currency_digits: :cash} = options, backend) do
defp set_default_fractional_digits(
%{fractional_digits: nil, currency_digits: :cash} = options,
backend
) do
case Cldr.Currency.currency_for_code(options.currency, backend, locale: options.locale) do
{:ok, currency} ->
Map.put(options, :fractional_digits, currency.cash_digits)

_other ->
options
end
end
end

defp set_default_fractional_digits(%{fractional_digits: nil, currency_digits: :iso} = options, backend) do
defp set_default_fractional_digits(
%{fractional_digits: nil, currency_digits: :iso} = options,
backend
) do
case Cldr.Currency.currency_for_code(options.currency, backend, locale: options.locale) do
{:ok, currency} ->
Map.put(options, :fractional_digits, currency.iso_digits)

_other ->
options
end
end
end

defp set_default_fractional_digits(options, _backend) do
Expand All @@ -247,7 +257,8 @@ defmodule Cldr.Number.Format.Options do
%{locale: locale, number_system: number_system} = options

with {:ok, formats} <- Format.formats_for(locale, number_system, backend),
{:ok, resolved_format} <- standard_format(formats, format, locale, number_system, backend) do
{:ok, resolved_format} <-
standard_format(formats, format, locale, number_system, backend) do
Map.put(options, :format, resolved_format)
end
end
Expand Down Expand Up @@ -538,7 +549,6 @@ defmodule Cldr.Number.Format.Options do
end
end


defp validate_option(:format, _options, _backend, format) do
{:ok, format}
end
Expand Down Expand Up @@ -727,7 +737,7 @@ defmodule Cldr.Number.Format.Options do
end

@doc false
@spec short_format_styles() :: list(atom())
@spec short_format_styles() :: [short_format_style(), ...]
def short_format_styles do
@short_formats
end
Expand Down Expand Up @@ -771,7 +781,14 @@ defmodule Cldr.Number.Format.Options do
case metadata.currency do
%{symbol_count: symbol_count} ->
symbol =
currency_symbol(currency, options.currency_symbol, number, symbol_count, options.locale, backend)
currency_symbol(
currency,
options.currency_symbol,
number,
symbol_count,
options.locale,
backend
)

Map.put(options, :currency_symbol, symbol)

Expand Down
Loading

0 comments on commit facdf51

Please sign in to comment.