Missing resource TimeSpanHumanize_MultipleSeconds in Polish?
Hi,
Just got the following error reported from a user. Unfortunately am not sure exactly which locale it is, but the user is Polish:
System.ArgumentException: The resource object with key 'TimeSpanHumanize_MultipleSeconds' was not found Nazwa parametru: resourceKey w Humanizer.Localisation.Formatters.DefaultFormatter.Format(String resourceKey, Int32 number, Boolean toWords) w Humanizer.TimeSpanHumanizeExtensions.CreateTheTimePartsWithUpperAndLowerLimits(TimeSpan timespan, CultureInfo culture, TimeUnit maxUnit, TimeUnit minUnit, Boolean toWords) w TVRename.ChooseFile..ctor(FileInfo left, FileInfo right)
The line of code that is producing the issue is: 10000.Seconds().Humanize(2);
Thanks
Seems to be missing in the Resources.fi-FI.resx resources file
Not sure what's going on. From the error message 'Nazwa parametru' is (apparently) Polish, but searching through the resource files, it looks like it's only missing in Resources.fi-FI.resx file.
In either event, I though it was meant to 'fallback' to another language rather than fail?
The same exception for ru-RU, but in Xamarin.Forms
Another instance of #690, related to xamarin (android?) not including satellite dependencies properly. Would be great if this didn't cause exceptions to be thrown.
Still a problem
Exactly, problem still occurs.
Note, that exception is thrown inconsistently. Only happens when NO relevant language lib is referenced (for example 'Humanizer.Core.pl') and under specific conditions.
Repro steps:
- Uninstall Humanizer.Core.pl (if installed)
- Install Humanizer.Core
- Run below:
var test = DateTime.UtcNow - TimeSpan.FromSeconds(2);
Debug.Print(test.Humanize(culture: new CultureInfo("en-GB"))); // OK: 2 seconds ago
Debug.Print(test.Humanize(culture: new CultureInfo("pl-PL"))); // FAILS - DOES NOT fallback to English: System.ArgumentException: 'The resource object with key 'DateHumanize_MultipleSecondsAgo' was not found Arg_ParamName_Name'
var test2 = DateTime.UtcNow - TimeSpan.FromSeconds(5);
Debug.Print(test2.Humanize(culture: new CultureInfo("en-GB"))); // OK: 5 seconds ago
Debug.Print(test2.Humanize(culture: new CultureInfo("pl-PL"))); // OK - DOES fallback to English: 5 seconds ago
Now with Humanizer.Core.pl installed:
var test = DateTime.UtcNow - TimeSpan.FromSeconds(2);
Debug.Print(test.Humanize(culture: new CultureInfo("en-GB"))); // OK: 2 seconds ago
Debug.Print(test.Humanize(culture: new CultureInfo("pl-PL"))); // OK: przed 2 sekundami
var test2 = DateTime.UtcNow - TimeSpan.FromSeconds(5);
Debug.Print(test2.Humanize(culture: new CultureInfo("en-GB"))); // OK: 5 seconds ago
Debug.Print(test2.Humanize(culture: new CultureInfo("pl-PL"))); // OK: przed 5 sekundami
I have found out why that happens.
The error is sadly a bit misleading. Consider these code excerpts:
https://github.com/Humanizr/Humanizer/blob/606e958cb83afc9be5b36716ac40d4daa9fa73a7/src/Humanizer/Localisation/Formatters/DefaultFormatter.cs#L131-L138
https://github.com/Humanizr/Humanizer/blob/606e958cb83afc9be5b36716ac40d4daa9fa73a7/src/Humanizer/Localisation/Formatters/CzechSlovakPolishFormatter.cs#L5-L20
So, the actual missing resource keys are missing, they just show up invalid in the exception text. The missing ones are those with _Paucal suffix - there are no such resource keys.
Generally, I'd say that it's a global issue. English (fallback) resources don't contain special, culture-specific-suffix additions. I have not come up with a good, quick fix for this. We'd probably need to somehow detect the fallback is used and retry with an unsuffixed resource key.
Duplicate of #690