Humanizer
Humanizer copied to clipboard
Mixed languages in TimeToClockNotation (ITimeOnlyToClockNotationConverter implementations do not forward the culture to ToWord)
When using
Examples:
- In FrTimeOnlyToClockNotationConverter.cs :
_ => hour.ToWords(GrammaticalGender.Feminine) + (hour > 1 ? " heures" : " heure") - In EsTimeOnlyToClockNotationConverter.cs :
$"{article} {hour} y {normalizedMinutes.ToWords()} {dayPeriod}");etc.
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.