elixir-cldr / cldr_units

Unit formatting (volume, area, length, ...) functions for the Common Locale Data Repository (CLDR)
Other
16 stars 13 forks source link

No format pattern was found for unit ... with grammatical case :nominative, gender :neuter and plural type :one #21

Closed ghost closed 3 years ago

ghost commented 3 years ago

👋

I've just upgraded to the latest ExCLDR versions, and got the following error in one of the tests (which checks that all measurements used in the app can be "rendered"):

iex(1)> App.Cldr.Unit.to_string!(1, unit: :pascal, style: :short)
** (Cldr.Unit.NoPatternError) No format pattern was found for unit #Cldr.Unit<:pascal, 1> with grammatical case :nominative, gender :neuter and plural type :one
    (ex_cldr_units 3.5.1) lib/cldr/unit/format.ex:675: Cldr.Unit.Format.get_unit_pattern!/6
    (ex_cldr_units 3.5.1) lib/cldr/unit/format.ex:403: Cldr.Unit.Format.to_iolist/3
    (ex_cldr_units 3.5.1) lib/cldr/unit/format.ex:194: Cldr.Unit.Format.to_string/3
    (ex_cldr_units 3.5.1) lib/cldr/unit/format.ex:281: Cldr.Unit.Format.to_string!/3

Without :style option it works as expected:

iex(1)> App.Cldr.Unit.to_string!(1, unit: :pascal)               
"1 Pascal"

I wonder if maybe :style has been replaced with some other option?

Versions:

"ex_cldr": "2.20.0"
"ex_cldr_units": "3.5.1"

Thank you!

kipcole9 commented 3 years ago

Thanks for the report and sorry for the inconvenience. I've just tried on master branch and it seems ok. Can you let me know what locale you are operating in? Perhaps that makes a difference since not all locales have all data for units yet (its a CLDR work in progress).

The error indicates that ex_cldr_units couldn't find a unit pattern for

iex> Cldr.Unit.to_string!(1, [unit: :pascal, style: :short])
"1 Pa"
iex> MyApp.Cldr.Unit.to_string!(1, [unit: :pascal, style: :short])
"1 Pa"
ghost commented 3 years ago

Ah, right, sorry, forgot to mention that the default locale is set to de.

iex(3)> App.Cldr.Unit.to_string!(1, [unit: "pascal", style: :narrow, locale: "en"])
"1Pa"
iex(4)> App.Cldr.Unit.to_string!(1, [unit: "pascal", style: :narrow, locale: "de"])
** (Cldr.Unit.NoPatternError) No format pattern was found for unit #Cldr.Unit<:pascal, 1> with grammatical case :nominative, gender :neuter and plural type :one
    (ex_cldr_units 3.5.1) lib/cldr/unit/format.ex:675: Cldr.Unit.Format.get_unit_pattern!/6
    (ex_cldr_units 3.5.1) lib/cldr/unit/format.ex:403: Cldr.Unit.Format.to_iolist/3
    (ex_cldr_units 3.5.1) lib/cldr/unit/format.ex:194: Cldr.Unit.Format.to_string/3
    (ex_cldr_units 3.5.1) lib/cldr/unit/format.ex:281: Cldr.Unit.Format.to_string!/3
kipcole9 commented 3 years ago

Ahhhh, I suspect you are in the "de" locale given it refers to the :neuter gender. And only locales "de" and "fr" currently have grammatical features in them.

kipcole9 commented 3 years ago

Confirmed and can reproduce. I will explore further what I can do to mitigate the data gap. Should be able to resolve during your day and I'll publish an update when done.

ghost commented 3 years ago

Thank you!

kipcole9 commented 3 years ago

I have published ex_cldr_units 3.5.2 that fixes the error with this commit. The changelog entry is:

Bug Fixes

Thanks for your patience and collaboration!