Skip to content

Commit

Permalink
Merge pull request #9 from elixir-cldr/master
Browse files Browse the repository at this point in the history
Update to ex_cldr 2.14+, fix tests, docs
  • Loading branch information
Schultzer committed Jun 7, 2020
2 parents f04b3d5 + c26f0b3 commit 11524d2
Show file tree
Hide file tree
Showing 9 changed files with 305 additions and 162 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Changelog

## Cldr Territories v2.1.0 June 8th, 2020

### Enhancements

* Requires `ex_cldr` version `2.14` or later to use CLDR data version 37. As with all CLDR releases, underlying data can change and tests are updated to reflect those changes.

* Updated readme to reflect changes in EU composition and the updated data returned territories

* CLDR 37 also reflects that the UK is no longer part of the EU.

* Minimum version of Elixir required is 1.8 to align with the baseline `ex_cldr` library

* Fix typespec leading to dialyzer errors

* Update dependencies in development

## Cldr Territories v2.0.1 May 1st, 2019

### Enhancements
Expand Down
47 changes: 34 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,55 @@ iex> MyCldr.Territory.translate_territory("Reino Unido", "pt", "en")
{:ok, "UK"}

iex> MyCldr.Territory.contains?(:EU, :GB)
false

iex> MyCldr.Territory.contains?(:EU, :DE)
true

iex> MyCldr.Territory.parent(:GB)
{:ok, [:"154", :EU, :UN]}
{:ok, [:"154", :UN]}

iex> MyCldr.Territory.children(:EU)
{:ok,
[:AT, :BE, :CY, :CZ, :DE, :DK, :EE, :ES, :FI, :FR, :GB, :GR, :HR, :HU, :IE,
[:AT, :BE, :CY, :CZ, :DE, :DK, :EE, :ES, :FI, :FR, :GR, :HR, :HU, :IE,
:IT, :LT, :LU, :LV, :MT, :NL, :PL, :PT, :SE, :SI, :SK, :BG, :RO]}

iex> MyCldr.Territory.info(:GB)
{:ok,
%{currency: [GBP: %{from: ~D[1694-07-27]}], gdp: 2788000000000,
language_population: %{"bn" => %{population_percent: 0.67},
%{
currency: [GBP: %{from: ~D[1694-07-27]}],
gdp: 2925000000000,
language_population: %{
"bn" => %{population_percent: 0.67},
"cy" => %{official_status: "official_regional", population_percent: 0.77},
"de" => %{population_percent: 6}, "el" => %{population_percent: 0.34},
"de" => %{population_percent: 6},
"el" => %{population_percent: 0.33},
"en" => %{official_status: "official", population_percent: 99},
"fr" => %{population_percent: 19},
"ga" => %{official_status: "official_regional", population_percent: 0.026},
"gd" => %{official_status: "official_regional", population_percent: 0.099,
writing_percent: 5}, "it" => %{population_percent: 0.34},
"ks" => %{population_percent: 0.19}, "kw" => %{population_percent: 0.0031},
"ml" => %{population_percent: 0.035}, "pa" => %{population_percent: 0.79},
"gd" => %{
official_status: "official_regional",
population_percent: 0.099,
writing_percent: 5
},
"it" => %{population_percent: 0.33},
"ks" => %{population_percent: 0.19},
"kw" => %{population_percent: 0.0031},
"ml" => %{population_percent: 0.035},
"pa" => %{population_percent: 0.79},
"sco" => %{population_percent: 2.7, writing_percent: 5},
"syl" => %{population_percent: 0.51}, "yi" => %{population_percent: 0.049},
"zh-Hant" => %{population_percent: 0.54}}, literacy_percent: 99,
measurement_system: "UK", paper_size: "A4", population: 64769500,
telephone_country_code: 44, temperature_measurement: "metric"}}
"syl" => %{population_percent: 0.51},
"yi" => %{population_percent: 0.049},
"zh-Hant" => %{population_percent: 0.54}
},
literacy_percent: 99,
measurement_system: %{
default: :uksystem,
paper_size: :a4,
temperature: :uksystem
},
population: 65105200
}}

iex> MyCldr.Territory.to_unicode_flag(:US)
{:ok, "🇺🇸"}
Expand Down
3 changes: 3 additions & 0 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ use Mix.Config
config :ex_unit,
case_load_timeout: 220_000,
timeout: 120_000

config :ex_cldr,
default_backend: TestBackend.Cldr
144 changes: 96 additions & 48 deletions lib/cldr/backend.ex

Large diffs are not rendered by default.

131 changes: 80 additions & 51 deletions lib/cldr/territory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ defmodule Cldr.Territory do
@type atom_binary_tag :: atom() | binary() | LanguageTag.t()
@type atom_tag :: atom() | LanguageTag.t()
@type binary_tag :: binary() | LanguageTag.t()
@type error :: {Exception.t(), binary()}
@type error :: {module, binary()}
@type styles :: :short | :standard | :variant
@type tag :: LanguageTag.t()
@type options :: [{:locale, binary_tag()} | {:style, styles()}]

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

@doc """
Returns a list of available styles.
Expand Down Expand Up @@ -299,13 +299,14 @@ defmodule Cldr.Territory do
## Example
iex> Cldr.Territory.parent(:GB)
{:ok, [:"154", :EU, :UN]}
{:ok, [:"154", :UN]}
iex> Cldr.Territory.parent(:ZZZ)
{:error, {Cldr.UnknownTerritoryError, "The territory :ZZZ is unknown"}}
iex> Cldr.Territory.parent(Cldr.get_locale())
{:error, {Cldr.UnknownChildrenError, "The territory :\\"001\\" has no parent(s)"}}
"""
@spec parent(atom_binary_tag(), as_options()) :: {:ok, atom_binary_charlist()} | {:error, error()}
def parent(territory_code, opts \\ [as: :atom])
Expand Down Expand Up @@ -355,7 +356,7 @@ defmodule Cldr.Territory do
## Example
iex> Cldr.Territory.parent!(:GB)
[:"154", :EU, :UN]
[:"154", :UN]
"""
@spec parent!(atom_binary_tag(), as_options()) :: [atom_binary_charlist()] | no_return()
Expand Down Expand Up @@ -394,14 +395,15 @@ defmodule Cldr.Territory do
iex> Cldr.Territory.children(:EU)
{:ok,
[:AT, :BE, :CY, :CZ, :DE, :DK, :EE, :ES, :FI, :FR, :GB, :GR, :HR, :HU, :IE,
[:AT, :BE, :CY, :CZ, :DE, :DK, :EE, :ES, :FI, :FR, :GR, :HR, :HU, :IE,
:IT, :LT, :LU, :LV, :MT, :NL, :PL, :PT, :SE, :SI, :SK, :BG, :RO]}
iex> Cldr.Territory.children(:ZZZ)
{:error, {Cldr.UnknownTerritoryError, "The territory :ZZZ is unknown"}}
iex> Cldr.Territory.children(:GB)
{:error, {Cldr.UnknownParentError, "The territory :GB has no children"}}
"""
@spec children(atom_binary_tag(), as_options()) :: {:ok, atom_binary_charlist()} | {:error, error()}
def children(territory_code, opts \\ [as: :atom])
Expand Down Expand Up @@ -443,8 +445,9 @@ defmodule Cldr.Territory do
## Example
iex> Cldr.Territory.children!(:EU)
[:AT, :BE, :CY, :CZ, :DE, :DK, :EE, :ES, :FI, :FR, :GB, :GR, :HR, :HU, :IE, :IT,
[:AT, :BE, :CY, :CZ, :DE, :DK, :EE, :ES, :FI, :FR, :GR, :HR, :HU, :IE, :IT,
:LT, :LU, :LV, :MT, :NL, :PL, :PT, :SE, :SI, :SK, :BG, :RO]
"""
@spec children!(atom_binary_tag(), as_options()) :: [atom_binary_charlist()] | no_return()
def children!(territory_code, opts \\ [as: :atom])
Expand Down Expand Up @@ -499,28 +502,42 @@ defmodule Cldr.Territory do
## Example
iex> Cldr.Territory.info(:GB)
{:ok, %{currency: [GBP: %{from: ~D[1694-07-27]}], gdp: 2788000000000,
language_population: %{"bn" => %{population_percent: 0.67},
"cy" => %{official_status: "official_regional",
population_percent: 0.77}, "de" => %{population_percent: 6},
"el" => %{population_percent: 0.34},
"en" => %{official_status: "official", population_percent: 99},
"fr" => %{population_percent: 19},
"ga" => %{official_status: "official_regional",
population_percent: 0.026},
"gd" => %{official_status: "official_regional",
population_percent: 0.099, writing_percent: 5},
"it" => %{population_percent: 0.34},
"ks" => %{population_percent: 0.19},
"kw" => %{population_percent: 0.0031},
"ml" => %{population_percent: 0.035},
"pa" => %{population_percent: 0.79},
"sco" => %{population_percent: 2.7, writing_percent: 5},
"syl" => %{population_percent: 0.51},
"yi" => %{population_percent: 0.049},
"zh-Hant" => %{population_percent: 0.54}}, literacy_percent: 99,
measurement_system: "UK", paper_size: "A4", population: 64769500,
telephone_country_code: 44, temperature_measurement: "metric"}}
{:ok,
%{
currency: [GBP: %{from: ~D[1694-07-27]}],
gdp: 2925000000000,
language_population: %{
"bn" => %{population_percent: 0.67},
"cy" => %{official_status: "official_regional", population_percent: 0.77},
"de" => %{population_percent: 6},
"el" => %{population_percent: 0.33},
"en" => %{official_status: "official", population_percent: 99},
"fr" => %{population_percent: 19},
"ga" => %{official_status: "official_regional", population_percent: 0.026},
"gd" => %{
official_status: "official_regional",
population_percent: 0.099,
writing_percent: 5
},
"it" => %{population_percent: 0.33},
"ks" => %{population_percent: 0.19},
"kw" => %{population_percent: 0.0031},
"ml" => %{population_percent: 0.035},
"pa" => %{population_percent: 0.79},
"sco" => %{population_percent: 2.7, writing_percent: 5},
"syl" => %{population_percent: 0.51},
"yi" => %{population_percent: 0.049},
"zh-Hant" => %{population_percent: 0.54}
},
literacy_percent: 99,
measurement_system: %{
default: :uksystem,
paper_size: :a4,
temperature: :uksystem
},
population: 65105200
}}
"""
@spec info(atom_tag()) :: {:ok, map()} | {:error, error()}
def info(%LanguageTag{territory: territory_code}), do: info(territory_code)
Expand All @@ -540,28 +557,40 @@ defmodule Cldr.Territory do
## Example
iex> Cldr.Territory.info!(:GB)
%{currency: [GBP: %{from: ~D[1694-07-27]}], gdp: 2788000000000,
language_population: %{"bn" => %{population_percent: 0.67},
"cy" => %{official_status: "official_regional",
population_percent: 0.77}, "de" => %{population_percent: 6},
"el" => %{population_percent: 0.34},
"en" => %{official_status: "official", population_percent: 99},
"fr" => %{population_percent: 19},
"ga" => %{official_status: "official_regional",
population_percent: 0.026},
"gd" => %{official_status: "official_regional",
population_percent: 0.099, writing_percent: 5},
"it" => %{population_percent: 0.34},
"ks" => %{population_percent: 0.19},
"kw" => %{population_percent: 0.0031},
"ml" => %{population_percent: 0.035},
"pa" => %{population_percent: 0.79},
"sco" => %{population_percent: 2.7, writing_percent: 5},
"syl" => %{population_percent: 0.51},
"yi" => %{population_percent: 0.049},
"zh-Hant" => %{population_percent: 0.54}}, literacy_percent: 99,
measurement_system: "UK", paper_size: "A4", population: 64769500,
telephone_country_code: 44, temperature_measurement: "metric"}
%{
currency: [GBP: %{from: ~D[1694-07-27]}],
gdp: 2925000000000,
language_population: %{
"bn" => %{population_percent: 0.67},
"cy" => %{official_status: "official_regional", population_percent: 0.77},
"de" => %{population_percent: 6},
"el" => %{population_percent: 0.33},
"en" => %{official_status: "official", population_percent: 99},
"fr" => %{population_percent: 19},
"ga" => %{official_status: "official_regional", population_percent: 0.026},
"gd" => %{
official_status: "official_regional",
population_percent: 0.099,
writing_percent: 5
},
"it" => %{population_percent: 0.33},
"ks" => %{population_percent: 0.19},
"kw" => %{population_percent: 0.0031},
"ml" => %{population_percent: 0.035},
"pa" => %{population_percent: 0.79},
"sco" => %{population_percent: 2.7, writing_percent: 5},
"syl" => %{population_percent: 0.51},
"yi" => %{population_percent: 0.049},
"zh-Hant" => %{population_percent: 0.54}
},
literacy_percent: 99,
measurement_system: %{
default: :uksystem,
paper_size: :a4,
temperature: :uksystem
},
population: 65105200
}
"""
@spec info!(atom_tag()) :: map() | no_return()
def info!(%LanguageTag{territory: territory_code}), do: info!(territory_code)
Expand Down
9 changes: 5 additions & 4 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
defmodule CldrTerritories.Mixfile do
use Mix.Project

@version "2.0.1"
@version "2.1.0"

def project do
[
app: :ex_cldr_territories,
version: @version,
elixir: "~> 1.5",
elixir: "~> 1.8",
name: "Cldr Territories",
source_url: "https://github.com/schultzer/cldr_territories",
description: description(),
Expand Down Expand Up @@ -36,9 +36,10 @@ defmodule CldrTerritories.Mixfile do

defp deps do
[
{:ex_cldr, "~> 2.0"},
{:ex_cldr, "~> 2.14"},
{:ex_doc, "~> 0.18", only: [:release, :dev]},
{:jason, "~> 1.0", optional: true}
{:jason, "~> 1.0", optional: true},
{:dialyxir, "~> 1.0", only: [:dev], runtime: false, optional: true},
]
end

Expand Down
20 changes: 11 additions & 9 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
%{
"abnf2": {:hex, :abnf2, "0.1.2", "6f8792b8ac3288dba5fc889c2bceae9fe78f74e1a7b36bea9726ffaa9d7bef95", [:mix], [], "hexpm"},
"cldr_utils": {:hex, :cldr_utils, "2.0.2", "3ddb0c1047fa3281cac3fa203cb7422781755307d228a26aad001de07cff42ce", [:mix], [{:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm"},
"decimal": {:hex, :decimal, "1.6.0", "bfd84d90ff966e1f5d4370bdd3943432d8f65f07d3bab48001aebd7030590dcc", [:mix], [], "hexpm"},
"earmark": {:hex, :earmark, "1.2.6", "b6da42b3831458d3ecc57314dff3051b080b9b2be88c2e5aa41cd642a5b044ed", [:mix], [], "hexpm"},
"ex_cldr": {:hex, :ex_cldr, "2.0.3", "3512175064cf683837bad9b08c19f3fb7de45859b7b12fdc79b1ee2e41b2e925", [:mix], [{:cldr_utils, "~> 2.0", [hex: :cldr_utils, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:gettext, "~> 0.13", [hex: :gettext, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:nimble_parsec, "~> 0.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}, {:plug, "~> 1.4", [hex: :plug, repo: "hexpm", optional: true]}, {:sweet_xml, "~> 0.6", [hex: :sweet_xml, repo: "hexpm", optional: true]}], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.19.1", "519bb9c19526ca51d326c060cb1778d4a9056b190086a8c6c115828eaccea6cf", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.7", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"},
"jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
"makeup": {:hex, :makeup, "0.5.5", "9e08dfc45280c5684d771ad58159f718a7b5788596099bdfb0284597d368a882", [:mix], [{:nimble_parsec, "~> 0.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"},
"makeup_elixir": {:hex, :makeup_elixir, "0.10.0", "0f09c2ddf352887a956d84f8f7e702111122ca32fbbc84c2f0569b8b65cbf7fa", [:mix], [{:makeup, "~> 0.5.5", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"},
"nimble_parsec": {:hex, :nimble_parsec, "0.4.0", "ee261bb53214943679422be70f1658fff573c5d0b0a1ecd0f18738944f818efe", [:mix], [], "hexpm"},
"cldr_utils": {:hex, :cldr_utils, "2.9.1", "be714403abe1a7abed5ee4f7dd3823a9067f96ab4b0613a454177b51ca204236", [:mix], [{:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "6cba0a485f57feb773291ca1816469ddd887e22d73d9b12a1b207d82a67a4e71"},
"decimal": {:hex, :decimal, "1.8.1", "a4ef3f5f3428bdbc0d35374029ffcf4ede8533536fa79896dd450168d9acdf3c", [:mix], [], "hexpm", "3cb154b00225ac687f6cbd4acc4b7960027c757a5152b369923ead9ddbca7aec"},
"dialyxir": {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "aeb06588145fac14ca08d8061a142d52753dbc2cf7f0d00fc1013f53f8654654"},
"earmark": {:hex, :earmark, "1.4.5", "62ffd3bd7722fb7a7b1ecd2419ea0b458c356e7168c1f5d65caf09b4fbdd13c8", [:mix], [], "hexpm", "b7d0e6263d83dc27141a523467799a685965bf8b13b6743413f19a7079843f4f"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_cldr": {:hex, :ex_cldr, "2.16.1", "905b03c38b5fb51668a347f2e6b586bcb2c0816cd98f7d913104872c43cbc61f", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.5", [hex: :certifi, repo: "hexpm", optional: true]}, {:cldr_utils, "~> 2.9", [hex: :cldr_utils, repo: "hexpm", optional: false]}, {:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:gettext, "~> 0.13", [hex: :gettext, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "006e500769982e57e6f3e32cbc4664345f78b014bb5ff48ddc394d67c86c1a8d"},
"ex_doc": {:hex, :ex_doc, "0.22.1", "9bb6d51508778193a4ea90fa16eac47f8b67934f33f8271d5e1edec2dc0eee4c", [:mix], [{:earmark, "~> 1.4.0", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "d957de1b75cb9f78d3ee17820733dc4460114d8b1e11f7ee4fd6546e69b1db60"},
"jason": {:hex, :jason, "1.2.1", "12b22825e22f468c02eb3e4b9985f3d0cb8dc40b9bd704730efa11abd2708c44", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "b659b8571deedf60f79c5a608e15414085fa141344e2716fbd6988a084b5f993"},
"makeup": {:hex, :makeup, "1.0.3", "e339e2f766d12e7260e6672dd4047405963c5ec99661abdc432e6ec67d29ef95", [:mix], [{:nimble_parsec, "~> 0.5", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "2e9b4996d11832947731f7608fed7ad2f9443011b3b479ae288011265cdd3dad"},
"makeup_elixir": {:hex, :makeup_elixir, "0.14.1", "4f0e96847c63c17841d42c08107405a005a2680eb9c7ccadfd757bd31dabccfb", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f2438b1a80eaec9ede832b5c41cd4f373b38fd7aa33e3b22d9db79e640cbde11"},
"nimble_parsec": {:hex, :nimble_parsec, "0.6.0", "32111b3bf39137144abd7ba1cce0914533b2d16ef35e8abc5ec8be6122944263", [:mix], [], "hexpm", "27eac315a94909d4dc68bc07a4a83e06c8379237c5ea528a9acff4ca1c873c52"},
"poison": {:hex, :poison, "4.0.1", "bcb755a16fac91cad79bfe9fc3585bb07b9331e50cfe3420a24bcc2d735709ae", [:mix], [], "hexpm"},
}
5 changes: 4 additions & 1 deletion mix/test_backend.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
require Cldr.Territory.Backend

defmodule TestBackend.Cldr do
use Cldr,
default_locale: "en-001",
locales: ["root", "fr", "zh", "en", "bs", "pl", "ru", "th", "he", "pt", "en-001"]
locales: ["root", "fr", "zh", "en", "bs", "pl", "ru", "th", "he", "pt", "en-001"],
providers: [Cldr.Territory]
end
Loading

0 comments on commit 11524d2

Please sign in to comment.