Skip to content

Commit

Permalink
Conform to atom keys in ex_cldr 2.26
Browse files Browse the repository at this point in the history
  • Loading branch information
kipcole9 committed Mar 2, 2022
1 parent a116483 commit 6df4256
Show file tree
Hide file tree
Showing 17 changed files with 269 additions and 250 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
# Changelog

## Cldr_HTML v1.2.0

This is the changelog for Cldr HTML v1.2.0 released on March 2nd, 2022. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr_html/tags)

### Enhancements

* Updates to [ex_cldr version 2.26.0](https://hex.pm/packages/ex_cldr/2.26.0) which uses atoms for locale names and rbnf locale names. This is consistent with out elements of `t:Cldr.LanguageTag` where atoms are used where the cardinality of the data is fixed and relatively small and strings where the data is free format.

## Cldr_HTML v1.1.0

This is the changelog for Cldr HTML v1.1.0 released on September 25th, 2021. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr_html/tags)

### Bug Fixes

* Support `phoenix_html` version 3.0 in additional to earlier releases.
* Support `phoenix_html` version 3.0 in addition to earlier releases.

## Cldr_HTML v1.0.1

Expand Down
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
use Mix.Config
import Config

import_config "#{Mix.env()}.exs"
2 changes: 1 addition & 1 deletion config/dev.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

config :ex_cldr,
default_locale: "en-001",
Expand Down
1 change: 1 addition & 0 deletions config/release.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

config :ex_cldr,
default_locale: "en-001",
Expand Down
1 change: 0 additions & 1 deletion lib/cldr_html.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ defmodule Cldr.HTML do
if Cldr.Code.ensure_compiled?(Cldr.LocaleDisplay) do
defdelegate locale_select(form, field, options), to: Cldr.HTML.Locale, as: :select
end

end
2 changes: 1 addition & 1 deletion lib/cldr_html_currencies.ex
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ if Cldr.Code.ensure_compiled?(Cldr.Currency) do
select_options =
options
|> Map.drop(@omit_from_select_options)
|> Map.to_list
|> Map.to_list()

options =
options
Expand Down
30 changes: 17 additions & 13 deletions lib/cldr_html_locale.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ if Cldr.Code.ensure_compiled?(Cldr.LocaleDisplay) do
]

@type locale :: %{
locale: String.t(),
display_name: String.t(),
language_tag: Cldr.LanguageTag.t()
}
locale: String.t(),
display_name: String.t(),
language_tag: Cldr.LanguageTag.t()
}

@type mapper :: (locale() -> String.t())

Expand Down Expand Up @@ -124,15 +124,21 @@ if Cldr.Code.ensure_compiled?(Cldr.LocaleDisplay) do

# Selected currency
@omit_from_select_options [
:locales, :locale, :mapper, :collator, :backend,
:add_likely_subtags, :prefer, :compound_locale
:locales,
:locale,
:mapper,
:collator,
:backend,
:add_likely_subtags,
:prefer,
:compound_locale
]

defp select(form, field, options, _selected) do
select_options =
options
|> Map.drop(@omit_from_select_options)
|> Map.to_list
|> Map.to_list()

options =
options
Expand Down Expand Up @@ -187,8 +193,7 @@ if Cldr.Code.ensure_compiled?(Cldr.LocaleDisplay) do
|> Map.take([:add_likely_subtags])
|> Map.to_list()

backend =
options[:backend]
backend = options[:backend]

with {:ok, locale} <- Locale.canonical_language_tag(selected, backend, list_options) do
{:ok, Map.put(options, :selected, locale)}
Expand All @@ -207,11 +212,10 @@ if Cldr.Code.ensure_compiled?(Cldr.LocaleDisplay) do
|> Map.take([:add_likely_subtags])
|> Map.to_list()

backend =
options[:backend]
backend = options[:backend]

Enum.reduce_while(locales, [], fn locale, acc ->
case Locale.canonical_language_tag(locale, backend, list_options) do
case Locale.canonical_language_tag(to_string(locale), backend, list_options) do
{:ok, locale} -> {:cont, [locale | acc]}
{:error, reason} -> {:halt, {:error, reason}}
end
Expand Down Expand Up @@ -242,6 +246,7 @@ if Cldr.Code.ensure_compiled?(Cldr.LocaleDisplay) do

defp validate_locale(locale, options) do
{locale, backend} = Cldr.locale_and_backend_from(locale, options.backend)

with {:ok, locale} <- Cldr.validate_locale(locale, backend) do
options
|> Map.put(:locale, locale)
Expand Down Expand Up @@ -301,4 +306,3 @@ if Cldr.Code.ensure_compiled?(Cldr.LocaleDisplay) do
end
end
end

14 changes: 8 additions & 6 deletions lib/cldr_html_territories.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ if Cldr.Code.ensure_compiled?(Cldr.Territory) do
"""
@type territory :: %{
territory: atom(),
name: String.t(),
flag: String.t()
}
territory: atom(),
name: String.t(),
flag: String.t()
}

@doc """
Generate an HTML select tag for a territory list
Expand Down Expand Up @@ -119,7 +119,7 @@ if Cldr.Code.ensure_compiled?(Cldr.Territory) do
select_options =
options
|> Map.drop(@omit_from_select_options)
|> Map.to_list
|> Map.to_list()

options =
options
Expand Down Expand Up @@ -201,7 +201,9 @@ if Cldr.Code.ensure_compiled?(Cldr.Territory) do
options
end

defp maybe_include_selected_territory(%{territories: territories, selected: selected} = options) do
defp maybe_include_selected_territory(
%{territories: territories, selected: selected} = options
) do
if Enum.any?(territories, &(&1 == selected)) do
options
else
Expand Down
5 changes: 2 additions & 3 deletions lib/cldr_html_units.ex
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ if Cldr.Code.ensure_compiled?(Cldr.Unit) do
select_options =
options
|> Map.drop(@omit_from_select_options)
|> Map.to_list
|> Map.to_list()

options =
options
Expand All @@ -124,7 +124,7 @@ if Cldr.Code.ensure_compiled?(Cldr.Unit) do
backend: nil,
locale: Cldr.get_locale(),
collator: &default_collator/1,
mapper: &(&1),
mapper: & &1,
style: :long,
selected: nil
)
Expand Down Expand Up @@ -225,6 +225,5 @@ if Cldr.Code.ensure_compiled?(Cldr.Unit) do
defp default_unit_list() do
Cldr.Unit.known_units()
end

end
end
21 changes: 10 additions & 11 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Cldr.Html.MixProject do
use Mix.Project

@version "1.1.0"
@version "1.2.0"

def project do
[
Expand All @@ -21,8 +21,9 @@ defmodule Cldr.Html.MixProject do
package: package(),
dialyzer: [
ignore_warnings: ".dialyzer_ignore_warnings",
plt_add_apps: ~w(ex_money ex_cldr_units ex_cldr_territories ex_cldr_locale_display ratio ex_cldr_numbers ex_cldr_currencies)a
],
plt_add_apps:
~w(ex_money ex_cldr_units ex_cldr_territories ex_cldr_locale_display ratio ex_cldr_numbers ex_cldr_currencies)a
]
]
end

Expand All @@ -33,7 +34,6 @@ defmodule Cldr.Html.MixProject do
"""
end

# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
Expand Down Expand Up @@ -74,16 +74,15 @@ defmodule Cldr.Html.MixProject do
}
end

# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:ex_cldr, "~> 2.23"},
{:ex_cldr_currencies, "~> 2.11", optional: true},
{:ex_cldr_units, "~> 3.7", optional: true},
{:ex_cldr_locale_display, "~> 1.0", optional: true},
{:ex_cldr_territories, "~> 2.2", optional: true},
{:ex_cldr, "~> 2.26"},
{:ex_cldr_currencies, "~> 2.13", optional: true},
{:ex_cldr_units, "~> 3.12", optional: true},
{:ex_cldr_locale_display, "~> 1.3", optional: true},
{:ex_cldr_collation, "~> 0.5", optional: true},
{:ex_money, "~> 5.0", optional: true},
{:ex_money, "~> 5.9", optional: true},

{:phoenix_html, "~> 1.2 or ~> 2.0 or ~> 3.0"},
{:jason, "~> 1.0", optional: true},
{:poison, "~> 2.1 or ~> 3.0 or ~> 4.0", optional: true},
Expand Down
Loading

0 comments on commit 6df4256

Please sign in to comment.