Closed maennchen closed 2 years ago
after updating deps, got this also =>
The call 'Elixir.Cldr.DateTime.Formatter':literal
(_@2 :: #{'hour' := _, 'minute' := _, _ => _},
<<45>>,
_@1 ::
#{'__struct__' := 'Elixir.Cldr.LanguageTag',
'cldr_locale_name' := 'und',
_ => _},
'Elixir.AhramSchoolWeb.Cldr',
_@5 :: any()) breaks the contract
(any(),
'Elixir.String':t(),
locale(),
'Elixir.Cldr':backend(),
map()) ->
'Elixir.String':t()
@maennchen sorry about this, I think the issue relates to ex_cldr_languages
. I have just now sent a PR to @LostKobrakai to fix the compatibility issue. Hopefully with his agreement a new version can be released soon.
@alaadahmed Can you please open an issue on ex_cldr_dates_times with an example of how that error is being returned? It looks like a dialyzer error?
yes it is dialyzer errors, 6 to be specific. That's why I didn't open issue.
.
Closing this issue since both reports are for different libraries (ex_cldr_languages and ex_cldr_dates_times). Both issues are being worked on.
@kipcole9 @maennchen I just released a new version of ex_cldr_languages. I want to make sure that while the string -> atom locale switch caused the error mentioned in the issue, it was ultimately caused by incorrect usage:
HygeiaCldr.get_locale().language()
|> (&HygeiaCldr.Language.to_string(&1, locale: &1)).()
|> elem(1)
Using the language as the locale only worked by accident given both languages and locales were identified by strings. Locales changes to be identified by atoms, languages are still strings, so the code should be like the following:
locale = HygeiaCldr.get_locale()
{:ok, lang} = HygeiaCldr.Language.to_string(locale.language, locale: locale)
lang
What should've worked before and was fixed in this release is that the first parameter could also be a LanguageTag. So this works as well:
language_tag = HygeiaCldr.get_locale()
{:ok, lang} = HygeiaCldr.Language.to_string(language_tag, locale: language_tag)
lang
@LostKobrakai Thanks for the update :)
@kipcole9 It seems that various user facing things changed:
https://github.com/jshmrtn/hygeia/runs/5389221417?check_suite_focus=true
Is there a function where I can provide a locale name as a string and if it exists, I get either the atom or the language tag back?
@maennchen, the canonical approach is to use MyApp.Cldr.validate_locale/1
. This takes an atom, string or Cldr.LanguageTag.t
and returns the Cldr.LanguageTag.t
. The language tag element :cldr_locale_name
then holds the CLDR locale being used.
It was not my intention to introduce breaking changes (except for ex_cldr libraries, which have been updated) so I will check your link and see where I can improve.
@kipcole9 I did not know about validate_locale
, that mostly did the trick.
I'm left with only one dialyzer error:
lib/hygeia_cldr.ex:1:invalid_contract
The @spec for the function does not match the success typing of the function.
Function:
HygeiaCldr.Language.to_string_by_locale/3
Success typing:
@spec to_string_by_locale(_, _, %{:fallback => boolean(), :locale => _, :style => :short | :standard}) ::
:error | {:error, {atom(), binary()}} | {:ok, _}
@maennchen I just published another version, which should fix the dialyzer error.
The change leads to problems with cldr_languages.
Error
The error can be observed here: https://github.com/jshmrtn/hygeia/pull/1247 / https://github.com/jshmrtn/hygeia/runs/5272966546?check_suite_focus=true
Versions
Triggering Code
https://github.com/jshmrtn/hygeia/blob/4d929ef882f6f81e720b1791279e3ed01143648a/lib/hygeia_web/live/header.sface#L184