Closed DaTrader closed 2 years ago
If a style does not exist, an error is raised.
The same as
from_territory_code/2
, but raises an exception if it fails.Example
iex> Cldr.Territory.from_territory_code!(:GB, TestBackend.Cldr) "United Kingdom" iex> Cldr.Territory.from_territory_code!(:GB, TestBackend.Cldr, [style: :short]) "UK" iex> Cldr.Territory.from_territory_code!(:GB, TestBackend.Cldr, [locale: "pt"]) "Reino Unido"
This is an expected behavior and outline in the docs: https://hexdocs.pm/ex_cldr_territories/Cldr.Territory.html#from_territory_code!/3.
If you believe that this is a mistake then I believe the proper channel for this would be upstream in Unicode CLDR.
https://cldr.unicode.org/#h.vw32p8sealpj https://cldr.unicode.org/index/bug-reports https://github.com/unicode-org/cldr
If this has already been fixed upstream, then this would require a new version of ex_cldr.
Ok, but how does one verify if a style does not exist for a particular territory?
I see, the errors are not just errors, but legit alternative scenarios, so I should invoke the from_territory_code/3 and match against { :error, ..} .
Ok, but how does one verify if a style does not exist for a particular territory?
You can use the known_territories/1 to verify what style each territory has.
I see, the errors are not just errors, but legit alternative scenarios, so I should invoke the from_territory_code/3 and match against { :error, ..} .
Yeah, depending on your use-case then you could build a function in your MyWeb.Cldr
, that would try to translate into the short version or fallback to standard.
Ok. Thanks!
The following fails:
MyApp.Cldr.Territory.from_territory_code!( :de, style: :short)