Humanizer icon indicating copy to clipboard operation
Humanizer copied to clipboard

Missing resource TimeSpanHumanize_MultipleSeconds in Polish?

Open SirSparkles opened this issue 7 years ago • 7 comments

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

SirSparkles avatar Jan 17 '19 00:01 SirSparkles

Seems to be missing in the Resources.fi-FI.resx resources file

SirSparkles avatar Jan 22 '19 00:01 SirSparkles

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?

SirSparkles avatar Jan 22 '19 10:01 SirSparkles

The same exception for ru-RU, but in Xamarin.Forms

KSemenenko avatar Jan 24 '19 15:01 KSemenenko

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.

peppy avatar Aug 23 '19 04:08 peppy

Still a problem

matibak avatar Mar 23 '20 15:03 matibak

Exactly, problem still occurs.

Filipowicz251 avatar Jul 18 '20 14:07 Filipowicz251

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:

  1. Uninstall Humanizer.Core.pl (if installed)
  2. Install Humanizer.Core
  3. 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

BieleckiLtd avatar Sep 15 '21 13:09 BieleckiLtd

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.

amis92 avatar Oct 14 '22 22:10 amis92

Duplicate of #690

hazzik avatar Feb 22 '24 00:02 hazzik