Humanizr / Humanizer

Humanizer meets all your .NET needs for manipulating and displaying strings, enums, dates, times, timespans, numbers and quantities
Other
8.52k stars 947 forks source link

Mixed languages in TimeToClockNotation (ITimeOnlyToClockNotationConverter implementations do not forward the culture to ToWord) #1519

Open acidbubbles opened 3 weeks ago

acidbubbles commented 3 weeks ago

When using

Examples:

This results in mixed languages.

Repro

var time = Configurator
  .TimeOnlyToClockNotationConverters.ResolveForCulture(new CultureInfo("fr-FR"))
  .Convert(new TimeOnly(19, 35), ClockNotationRounding.NearestFiveMinutes);

This results in jeudi 3 février 2022, nineteen heures fifteen

Same for es-ES: ... las seven y ten de la tarde PM

I did not validate for further languages.

Solution

I'm guessing, forwarding the culture to e.g. EsTimeOnlyToClockNotationConverter so it can then forward it to ToWord would be the sensible solution, but it is an API change that I wouldn't be comfortable submitting, since it would affect potentially multiple files.

Workaround

Setting the CultureInfo.CurrentUICulture works, but it is not a desirable solution because it requires locking the string creation in multi-threaded environment, and we don't want to affect the UI culture necessarily.