Skip to content

Commit

Permalink
Fix doc references to Cldr.known_locale_names/0 in backend (#18)
Browse files Browse the repository at this point in the history
* Fix doc references to Cldr.known_locale_names/0 in backend

* Fix tests to work with ex_cldr 2.24 (CLDR 40)

* Fix @SPEC for <backend>.available_subdivisions/1
  • Loading branch information
kipcole9 committed Oct 19, 2021
1 parent 3a06300 commit 4b448d3
Show file tree
Hide file tree
Showing 7 changed files with 574 additions and 619 deletions.
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
# Changelog

## Cldr Territories v2.3.0-rc.0 October 19th, 2021

### Enhancements

* Updates to `ex_cldr` version `2.24` which uses [CLDR 40](https://cldr.unicode.org/index/downloads/cldr-40) data

* Both territories and territory subdivisions are now represented as atoms in the canonical form rather than the previous binary representation.

## Cldr Territories v2.2.2 May 11th, 2021

### Enhancements

* Fix bug in `translate_territory!/4` [#16](https://github.com/Schultzer/cldr_territories/pull/16), thanks to @leandrocp.

* Fix bug in `translate_subdivision!/4`.

## Cldr Territories v2.2.1 May 10th, 2021
Expand All @@ -21,7 +29,7 @@
* Requires `ex_cldr` version `2.20` or later to use CLDR data version 39. As with all CLDR releases, underlying data can change and tests are updated to reflect those changes.

* Added `known_subdivisions/1`, `known_territory_subdivisions/2`, `from_subdivision_code/3` and `translate_subdivision/4` to support subdivison, thansk to @mskv.

* Improved proformance for `from_territory_code/2`, `from_subdivision_code/2`, `translate_territory/4` and `translate_subdivision/4`, thanks to @kipcole9.

## Cldr Territories v2.1.0 June 8th, 2020
Expand Down
33 changes: 15 additions & 18 deletions lib/cldr/backend.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule Cldr.Territory.Backend do
@doc """
Returns the available territories for a given locale.
* `locale` is any configured locale. See `#{inspect __MODULE__}.known_locale_names/0`.
* `locale` is any configured locale. See `#{inspect backend}.known_locale_names/0`.
The default is `Cldr.get_locale/0`
## Example
Expand All @@ -47,13 +47,13 @@ defmodule Cldr.Territory.Backend do
@doc """
Returns the available territory subdivisions for a given locale.
* `locale` is any configured locale. See `#{inspect __MODULE__}.known_locale_names/0`.
* `locale` is any configured locale. See `#{inspect backend}.known_locale_names/0`.
The default is `Cldr.get_locale/0`
## Example
=> #{inspect __MODULE__}.available_subdivisions("en")
["ad02", "ad03", "ad04", "ad05", "ad06", "ad07", "ad08", ...]
[:ad02, :ad03, :ad04, :ad05, :ad06, :ad07, :ad08, ...]
iex> #{inspect __MODULE__}.available_subdivisions()
[]
Expand All @@ -62,7 +62,7 @@ defmodule Cldr.Territory.Backend do
{:error, {Cldr.UnknownLocaleError, "The locale \\"zzz\\" is not known."}}
"""
@spec available_subdivisions(Cldr.Territory.binary_tag()) :: [String.t()] | {:error, Cldr.Territory.error()}
@spec available_subdivisions(Cldr.Territory.binary_tag()) :: [atom()] | {:error, Cldr.Territory.error()}
def available_subdivisions(locale \\ unquote(backend).get_locale())
def available_subdivisions(%LanguageTag{cldr_locale_name: cldr_locale_name}) do
available_subdivisions(cldr_locale_name)
Expand All @@ -71,7 +71,7 @@ defmodule Cldr.Territory.Backend do
@doc """
Returns a map of all known territories in a given locale.
* `locale` is any configured locale. See `#{inspect __MODULE__}.known_locale_names/0`.
* `locale` is any configured locale. See `#{inspect backend}.known_locale_names/0`.
The default is `Cldr.get_locale/0`
## Example
Expand Down Expand Up @@ -117,7 +117,7 @@ defmodule Cldr.Territory.Backend do
@doc """
Returns a map of all known territory subdivisions in a given locale.
* `locale` is any configured locale. See `#{inspect __MODULE__}.known_locale_names/0`.
* `locale` is any configured locale. See `#{inspect backend}.known_locale_names/0`.
The default is `Cldr.get_locale/0`
## Example
Expand Down Expand Up @@ -178,7 +178,7 @@ defmodule Cldr.Territory.Backend do
Returns `{:ok, String.t}` if successful, otherwise `{:error, reason}`.
* `options` are:
* `locale` is any configured locale. See `#{inspect __MODULE__}.known_locale_names/0`.
* `locale` is any configured locale. See `#{inspect backend}.known_locale_names/0`.
The default is `Cldr.get_locale/0`
* `style` is one of those returned by `#{inspect __MODULE__}.available_styles/0`.
Expand Down Expand Up @@ -206,7 +206,7 @@ defmodule Cldr.Territory.Backend do
{:error, {Cldr.UnknownLocaleError, "The locale :zzz is not known."}}
iex> #{inspect __MODULE__}.from_territory_code(:GB, [locale: "zzz"])
{:error, {Cldr.UnknownLocaleError, "The locale \\"zzz\\" is not known."}}
{:error, {Cldr.InvalidLanguageError, "The language \\"zzz\\" is invalid"}}
"""
@spec from_territory_code(Cldr.Territory.atom_binary_tag(), Cldr.Territory.options()) :: {:ok, binary()} | {:error, Cldr.Territory.error()}
Expand Down Expand Up @@ -239,7 +239,7 @@ defmodule Cldr.Territory.Backend do
Returns `{:ok, String.t}` if successful, otherwise `{:error, reason}`.
* `options` are:
* `locale` is any configured locale. See `#{inspect __MODULE__}.known_locale_names/0`.
* `locale` is any configured locale. See `#{inspect backend}.known_locale_names/0`.
The default is `Cldr.get_locale/0`
## Example
Expand All @@ -251,7 +251,7 @@ defmodule Cldr.Territory.Backend do
{:ok, "Kumbria"}
iex> #{inspect __MODULE__}.from_subdivision_code("gbcma", locale: "bs")
{:error, {Cldr.UnknownSubdivisionError, "The locale \\"bs\\" has no translation for \\"gbcma\\"."}}
{:error, {Cldr.UnknownSubdivisionError, "The locale \\"bs\\" has no translation for :gbcma."}}
iex> #{inspect __MODULE__}.from_subdivision_code("invalid", locale: "en")
{:error, {Cldr.UnknownTerritoryError, "The territory \\"invalid\\" is unknown"}}
Expand All @@ -260,7 +260,7 @@ defmodule Cldr.Territory.Backend do
{:error, {Cldr.UnknownLocaleError, "The locale :zzz is not known."}}
iex> #{inspect __MODULE__}.from_subdivision_code("gbcma", [locale: "zzz"])
{:error, {Cldr.UnknownLocaleError, "The locale \\"zzz\\" is not known."}}
{:error, {Cldr.InvalidLanguageError, "The language \\"zzz\\" is invalid"}}
"""
@spec from_subdivision_code(binary(), [locale: Cldr.Territory.binary_tag()]) :: {:ok, binary()} | {:error, Cldr.Territory.error()}
Expand Down Expand Up @@ -310,7 +310,6 @@ defmodule Cldr.Territory.Backend do
def from_territory_code!(territory_code, options) do
case from_territory_code(territory_code, options) do
{:error, {exception, msg}} -> raise exception, msg

{:ok, result} -> result
end
end
Expand Down Expand Up @@ -390,7 +389,7 @@ defmodule Cldr.Territory.Backend do
Translate a localized string from one locale to another.
Returns `{:ok, result}` if successful, otherwise `{:error, reason}`.
* `to_locale` is any configured locale. See `#{inspect __MODULE__}.known_locale_names/0`.
* `to_locale` is any configured locale. See `#{inspect backend}.known_locale_names/0`.
The default is `Cldr.get_locale/0`
## Example
Expand Down Expand Up @@ -431,7 +430,7 @@ defmodule Cldr.Territory.Backend do
Translate a localized string from one locale to another.
Returns `{:ok, result}` if successful, otherwise `{:error, reason}`.
* `to_locale` is any configured locale. See `#{inspect __MODULE__}.known_locale_names/0`.
* `to_locale` is any configured locale. See `#{inspect backend}.known_locale_names/0`.
The default is `Cldr.get_locale/0`
## Example
Expand All @@ -440,7 +439,7 @@ defmodule Cldr.Territory.Backend do
{:ok, "Kumbria"}
iex> #{inspect __MODULE__}.translate_subdivision("Cumbria", "en", "bs")
{:error, {Cldr.UnknownSubdivisionError, "The locale \\"bs\\" has no translation for \\"gbcma\\"."}}
{:error, {Cldr.UnknownSubdivisionError, "The locale \\"bs\\" has no translation for :gbcma."}}
iex> #{inspect __MODULE__}.translate_subdivision("Cumbria", :zzz)
{:error, {Cldr.UnknownLocaleError, "The locale :zzz is not known."}}
Expand Down Expand Up @@ -529,7 +528,7 @@ defmodule Cldr.Territory.Backend do
Returns `{:ok, result}` if successful, otherwise `{:error, reason}`.
* `options` are:
* `locale` is any configured locale. See `#{inspect __MODULE__}.known_locale_names/0`.
* `locale` is any configured locale. See `#{inspect backend}.known_locale_names/0`.
The default is `Cldr.get_locale/0`
* `style` is one of those returned by `#{inspect __MODULE__}.available_styles/0`.
Expand Down Expand Up @@ -925,12 +924,10 @@ defmodule Cldr.Territory.Backend do
|> Cldr.validate_locale(unquote(backend))
|> case do
{:error, error} -> {:error, error}

{:ok, %LanguageTag{cldr_locale_name: locale_name}} -> {:ok, code, locale_name}
end
end


@doc """
Unicode flag for the given territory code.
Returns `{:ok, flag}` if successful, otherwise `{:error, reason}`.
Expand Down
8 changes: 4 additions & 4 deletions lib/cldr/territory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ defmodule Cldr.Territory do
{:error, {Cldr.UnknownLocaleError, "The locale :zzz is not known."}}
iex> Cldr.Territory.from_territory_code(:GB, TestBackend.Cldr, [locale: "zzz"])
{:error, {Cldr.UnknownLocaleError, "The locale \\"zzz\\" is not known."}}
{:error, {Cldr.InvalidLanguageError, "The language \\"zzz\\" is invalid"}}
"""
@spec from_territory_code(atom_binary_tag(), Cldr.backend(), options()) :: {:ok, binary()} | {:error, error()}
Expand All @@ -215,7 +215,7 @@ defmodule Cldr.Territory do
{:ok, "Kumbria"}
iex> #{inspect __MODULE__}.from_subdivision_code("gbcma", TestBackend.Cldr, locale: "bs")
{:error, {Cldr.UnknownSubdivisionError, "The locale \\"bs\\" has no translation for \\"gbcma\\"."}}
{:error, {Cldr.UnknownSubdivisionError, "The locale \\"bs\\" has no translation for :gbcma."}}
iex> #{inspect __MODULE__}.from_subdivision_code("invalid", TestBackend.Cldr, locale: "en")
{:error, {Cldr.UnknownTerritoryError, "The territory \\"invalid\\" is unknown"}}
Expand All @@ -224,7 +224,7 @@ defmodule Cldr.Territory do
{:error, {Cldr.UnknownLocaleError, "The locale :zzz is not known."}}
iex> #{inspect __MODULE__}.from_subdivision_code("gbcma", TestBackend.Cldr, [locale: "zzz"])
{:error, {Cldr.UnknownLocaleError, "The locale \\"zzz\\" is not known."}}
{:error, {Cldr.InvalidLanguageError, "The language \\"zzz\\" is invalid"}}
"""
@spec from_subdivision_code(binary(), Cldr.backend(), [locale: binary_tag()]) ::
Expand Down Expand Up @@ -381,7 +381,7 @@ defmodule Cldr.Territory do
{:ok, "Kumbria"}
iex> #{inspect __MODULE__}.translate_subdivision("Cumbria", "en", TestBackend.Cldr, "bs")
{:error, {Cldr.UnknownSubdivisionError, "The locale \\"bs\\" has no translation for \\"gbcma\\"."}}
{:error, {Cldr.UnknownSubdivisionError, "The locale \\"bs\\" has no translation for :gbcma."}}
iex> #{inspect __MODULE__}.translate_subdivision("Cumbria", :zzz, TestBackend.Cldr)
{:error, {Cldr.UnknownLocaleError, "The locale :zzz is not known."}}
Expand Down
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule CldrTerritories.Mixfile do
use Mix.Project

@version "2.2.2"
@version "2.3.0-rc.0"

def project do
[
Expand Down Expand Up @@ -39,7 +39,7 @@ defmodule CldrTerritories.Mixfile do

defp deps do
[
{:ex_cldr, "~> 2.20"},
{:ex_cldr, "~> 2.24-rc"},
{:ex_doc, "~> 0.18", only: [:release, :dev]},
{:jason, "~> 1.0", optional: true},
{:dialyxir, "~> 1.0", only: [:dev], runtime: false, optional: true},
Expand Down
14 changes: 8 additions & 6 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
%{
"abnf2": {:hex, :abnf2, "0.1.2", "6f8792b8ac3288dba5fc889c2bceae9fe78f74e1a7b36bea9726ffaa9d7bef95", [:mix], [], "hexpm"},
"cldr_utils": {:hex, :cldr_utils, "2.15.1", "1136987437ac4821f3ec7d46ff150f1c020a1f79730ff1252bfa7681ed577f31", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.5", [hex: :certifi, repo: "hexpm", optional: true]}, {:decimal, "~> 1.9 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "ca3c8da0aab18b4d944541392e9548422e30854e3a9d7768dc629c8123f8efb8"},
"cldr_utils": {:hex, :cldr_utils, "2.17.0-rc.0", "3356664647cfd47e47af22dfeb1a66f50309623588d50908bb775c1c1431f7cd", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.5", [hex: :certifi, repo: "hexpm", optional: true]}, {:decimal, "~> 1.9 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "ccff70d78c53019c4f980a39d5fec77bdd0f25895021834bc7a476a2741d523d"},
"decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"},
"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"},
"earmark_parser": {:hex, :earmark_parser, "1.4.15", "b29e8e729f4aa4a00436580dcc2c9c5c51890613457c193cc8525c388ccb2f06", [:mix], [], "hexpm", "044523d6438ea19c1b8ec877ec221b008661d3c27e3b848f4c879f500421ca5c"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_cldr": {:hex, :ex_cldr, "2.20.0", "571a4b490c333809be59cc984a21be2deaab1db9e2418e323d5935aec8b1394a", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.5", [hex: :certifi, repo: "hexpm", optional: true]}, {:cldr_utils, "~> 2.15", [hex: :cldr_utils, repo: "hexpm", optional: false]}, {:decimal, "~> 1.6 or ~> 2.0", [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.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "06147e4a27be62e6fe92db14cf5048c645927bfc530aa1cc6af8c92d65e32427"},
"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"},
"ex_cldr": {:hex, :ex_cldr, "2.24.0-rc.3", "a6245a639a08bb67f4e5aa2645ad5c0b3c09f7e40fa88324986a3a0c15e83cca", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.5", [hex: :certifi, repo: "hexpm", optional: true]}, {:cldr_utils, "~> 2.17-rc", [hex: :cldr_utils, repo: "hexpm", optional: false]}, {:decimal, "~> 1.6 or ~> 2.0", [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.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "51ff4129e0716fb706886bc8985418347ee7e7ebdfc1cce00cc4786ee7eff5fb"},
"ex_doc": {:hex, :ex_doc, "0.25.1", "4b736fa38dc76488a937e5ef2944f5474f3eff921de771b25371345a8dc810bc", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "3200b0a69ddb2028365281fbef3753ea9e728683863d8cdaa96580925c891f67"},
"jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},
"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"},
"makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"},
"makeup_elixir": {:hex, :makeup_elixir, "0.15.1", "b5888c880d17d1cc3e598f05cdb5b5a91b7b17ac4eaf5f297cb697663a1094dd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "db68c173234b07ab2a07f645a5acdc117b9f99d69ebf521821d89690ae6c6ec8"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
"nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"},
"poison": {:hex, :poison, "4.0.1", "bcb755a16fac91cad79bfe9fc3585bb07b9331e50cfe3420a24bcc2d735709ae", [:mix], [], "hexpm"},
}
2 changes: 1 addition & 1 deletion mix/test_backend.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ 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: ["fr", "zh", "en", "bs", "pl", "ru", "th", "he", "pt", "en-001"],
providers: [Cldr.Territory]
end
Loading

0 comments on commit 4b448d3

Please sign in to comment.