elixir-cldr / cldr_units

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

Incorrect formatting of kilojoules #48

Open fekle opened 5 days ago

fekle commented 5 days ago

Hi there,

I'm using this great library to format various units correctly for different languages, and for almost everything I have tested, the unit names are correct.

However, what I've noticed is that there is an issue with the abbreviation for kilojoules. In many languages (and SI, as far as I know), the shorthand is kJ with an uppercase J, but cldr_units always returns kj:

> Cldr.Unit.to_string!(32, unit: :kilojoule, locale: "de", style: :short)
"32 kj"
> Cldr.Unit.to_string!(32, unit: :kilojoule, locale: "en", style: :short)
"32 kj"
> Cldr.Unit.to_string!(32, unit: :kilojoule, locale: "fr", style: :short)
"32 kj"
> Cldr.Unit.to_string!(32, unit: :kilojoule, locale: nil, style: :short)
"32 kj"

As far as I can tell, everything is configured correctly on my end, and the CLDR dataset also specifies "kJ." Is there anything I'm missing here?

Also, I hope I'm posting this issue in the correct repo; it is not entirely clear to me if the unit name formatting is done in this lib or the base CLDR library.

Some more information:

OS: macos 15.1

elixir:  1.17.3-otp-27
erlang:  27.1.2

ex_cldr: "2.40.1"
ex_cldr_calendars: "1.26.2"
ex_cldr_currencies: "2.16.3"
ex_cldr_dates_times: "2.20.3"
ex_cldr_languages: "0.3.3"
ex_cldr_lists: "2.11.1"
ex_cldr_numbers: "2.33.4"
ex_cldr_plugs: "1.3.3"
ex_cldr_territories: "2.9.0"
ex_cldr_units: "3.17.2"

Thank you for this great library, and let me know if there is anything I can do to help or if you need more information!

kipcole9 commented 4 days ago

Yes, that does look like a bug - and a strange one. I'll see if I can resolve it my day (sun just rising in UTC+11)

fekle commented 4 days ago

Thank you!

I found a few more oddities and created a small Minimal Reproduction project here: https://github.com/fekle/ex_cldr_units_repro. I hope this helps!

Specifically, Cldr.Unit.display_name does not work for kilojoules, and the formatting of bytes and bits seems odd - see test/ex_cldr_units_repro_test.exs in the linked repo.

Greetings from UTC+1 ;)

kipcole9 commented 4 days ago

Thanks @fekle, I'm still investigating - will do my best to get this resolved by Monday latest.

fekle commented 4 days ago

Thanks, and no stress!