Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates for ex_cldr 2.38.0 + bug fix #41

Merged
merged 3 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/cldr/exception.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,15 @@ defmodule Cldr.UnknownSubdivisionError do
%__MODULE__{message: message}
end
end

defmodule Cldr.UnknownInformationError do
@moduledoc """
Exception raised when there is a missing information.
"""

defexception [:message]

def exception(message) do
%__MODULE__{message: message}
end
end
17 changes: 16 additions & 1 deletion lib/cldr/territory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ defmodule Cldr.Territory do

@styles [:short, :standard, :variant]
@territory_containment Cldr.Config.territory_containers()

# FIXME The mapping is here until until the next bug fix
# of ex_cldr which needs to sort the currency info
# Tracking issue: https://github.com/elixir-cldr/cldr/issues/227
@territory_info Cldr.Config.territories()
|> Enum.map(fn {territory, info} ->
info = Map.put(info, :currency, Enum.sort(info.currency))
{territory, info}
end)

@subdivision_aliases Map.new(Map.fetch!(Cldr.Config.aliases(), :subdivision), fn
{k, v} when is_list(v) -> {:"#{k}", Enum.map(v, &:"#{&1}")}
{k, v} -> {:"#{k}", :"#{v}"}
Expand Down Expand Up @@ -663,6 +672,10 @@ defmodule Cldr.Territory do
population: 65761100
}}

iex> Cldr.Territory.info(:"155")
{:error,
{Cldr.UnknownInformationError, "No information available for :\\"155\\""}}

"""
@doc since: "1.0.0"
@spec info(atom() | String.t() | LanguageTag.t()) :: {:ok, map()} | {:error, {module(), String.t()}}
Expand All @@ -671,7 +684,9 @@ defmodule Cldr.Territory do
case Cldr.validate_territory(territory_code) do
{:error, reason} -> {:error, reason}

{:ok, code} -> {:ok, @territory_info[code]}
{:ok, code} ->
info = @territory_info[code]
if info, do: {:ok, info}, else: {:error, {Cldr.UnknownInformationError, "No information available for #{inspect code}"}}
end
end

Expand Down