Closed Stroemgren closed 4 days ago
Thanks, ~looks like we need to handle the case of territories with no currencies in this case statement https://github.com/elixir-cldr/cldr_territories/blob/f1639c38cba9905d55789052502f606c66c5f95f/lib/cldr/territory.ex#L822.~
if you are up for it then a PR is welcomed 🙏
The country code is the Island of Sark which is under the UK, there might be and subdivision alias we can use to resolve the proper currency code.
I'm up for giving it a go, but I will probably need some direction. At least it depends on the direction.
So either we should return a proper error for this case or we resolve the currency through subdivisions. Sark Island doesn't have any subdivisions though :)
https://github.com/elixir-cldr/cldr_territories/pull/48
This will return {:ok, nil}
and nil
for the bang version.
Let me know if you'd rather solve it differently.
I'm up for giving it a go, but I will probably need some direction. At least it depends on the direction.
So either we should return a proper error for this case or we resolve the currency through subdivisions. Sark Island doesn't have any subdivisions though :)
I believe that Sark Island would be under UK, so it might be possible to resolve it by looking up the parent, or maybe the UK subdivision aliases can resolve CQ.
We’re getting the currencies from the info function on https://github.com/elixir-cldr/cldr_territories/blob/f1639c38cba9905d55789052502f606c66c5f95f/lib/cldr/territory.ex#L886
I believe that is where we want to place the logic.
I have not looked at the data available for CQ or the UK so I can’t give you exact instructions.
Regardless, since these things are political and changes over time, then I’m still not sure if we want to error or resolve. @kipcole9 what do you think.
For what is worth, Wikipedia list their currency as GBP https://en.m.wikipedia.org/wiki/Sark
Not all territories have a known currency. Antartica would be one case. CLDR returns a currency XXX in that case:
iex> Cldr.Currency.territory_currencies(:AQ)
{:ok, %{XXX: %{tender: false}}}
XXX
or similar is used in various places in CLDR to denote "Unknown".
In other cases, CLDR doesn't have a currency definition as you observed. In this case ex_cldr_currencies
returns an error:
iex> Cldr.Currency.territory_currencies(:CQ)
{:error, {Cldr.UnknownCurrencyError, "No currencies for :CQ were found"}}
I think for consistency purposes, this would be the appropriate thing to do in ex_cldr_territories
.
BTW, according to Sark's website the currency is the Guernsey Pound - albeit thats a local issue of the GBP.
And I should probably also return {:error, {Cldr.UnknownCurrencyError, "No currencies for :__ were found"}}
when CLDR would return XXX
too, like for the :AQ
example.
Updated the PR.
I needed a list of all currency codes and wasn't at the time aware of the
ex_cldr_currencies
package, so I took the approach of just getting all known country codes and mapping overto_currency_code/1
. This led to an error where the map would run for most of the country codes and then break on :CQ, specifically.It's reproducible with:
Stacktrace:
I just ran it in isolation on a Livebook with the following deps.