Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing resources errors #1426

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/Humanizer/Localisation/Formatters/DefaultFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@ string GetResourceForTimeSpan(TimeUnit unit, int count, bool toWords = false)
/// <exception cref="ArgumentException">If the resource not exists on the specified culture.</exception>
protected virtual string Format(string resourceKey)
{
var resourceString = Resources.GetResource(GetResourceKey(resourceKey), _culture);
var resolvedKey = GetResourceKey(resourceKey);
var resourceString = Resources.GetResource(resolvedKey, _culture);

if (string.IsNullOrEmpty(resourceString))
{
throw new ArgumentException($"The resource object with key '{resourceKey}' was not found", nameof(resourceKey));
throw new ArgumentException($"The resource object with key '{resourceKey}' (resolved to '{resolvedKey}') was not found", nameof(resourceKey));
}

return resourceString;
Expand All @@ -94,11 +95,12 @@ protected virtual string Format(string resourceKey)
/// <exception cref="ArgumentException">If the resource not exists on the specified culture.</exception>
protected virtual string Format(string resourceKey, int number, bool toWords = false)
{
var resourceString = Resources.GetResource(GetResourceKey(resourceKey, number), _culture);
var resolvedKey = GetResourceKey(resourceKey, number);
var resourceString = Resources.GetResource(resolvedKey, _culture);

if (string.IsNullOrEmpty(resourceString))
{
throw new ArgumentException($"The resource object with key '{resourceKey}' was not found", nameof(resourceKey));
throw new ArgumentException($"The resource object with key '{resourceKey}' for number `{number}' (resolved to '{resolvedKey}') was not found", nameof(resourceKey));
}

if (toWords)
Expand Down
69 changes: 69 additions & 0 deletions src/Humanizer/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -735,4 +735,73 @@
<data name="TimeUnit_Year" xml:space="preserve">
<value>y</value>
</data>
<data name="DateHumanize_MultipleDaysAgo_DualTrialQuadral" xml:space="preserve">
<value>{0} days ago</value>
</data>
<data name="DateHumanize_MultipleDaysAgo_Paucal" xml:space="preserve">
<value>{0} days ago</value>
</data>
<data name="DateHumanize_MultipleDaysFromNow_Paucal" xml:space="preserve">
<value>{0} days from now</value>
</data>
<data name="DateHumanize_MultipleHoursAgo_Paucal" xml:space="preserve">
<value>{0} hours ago</value>
</data>
<data name="DateHumanize_MultipleHoursFromNow_Paucal" xml:space="preserve">
<value>{0} hours from now</value>
</data>
<data name="DateHumanize_MultipleMinutesAgo_Paucal" xml:space="preserve">
<value>{0} minutes ago</value>
</data>
<data name="DateHumanize_MultipleMinutesFromNow_Paucal" xml:space="preserve">
<value>{0} minutes from now</value>
</data>
<data name="DateHumanize_MultipleMonthsAgo_Paucal" xml:space="preserve">
<value>{0} months ago</value>
</data>
<data name="DateHumanize_MultipleMonthsFromNow_Paucal" xml:space="preserve">
<value>{0} months from now</value>
</data>
<data name="DateHumanize_MultipleSecondsAgo_Paucal" xml:space="preserve">
<value>{0} seconds ago</value>
</data>
<data name="DateHumanize_MultipleSecondsFromNow_Paucal" xml:space="preserve">
<value>{0} seconds from now</value>
</data>
<data name="DateHumanize_MultipleYearsAgo_Paucal" xml:space="preserve">
<value>{0} years from ago</value>
</data>
<data name="DateHumanize_MultipleYearsFromNow_Paucal" xml:space="preserve">
<value>{0} years from now</value>
</data>
<data name="DateHumanize_TwoDaysAgo" xml:space="preserve">
<value>two days ago</value>
</data>
<data name="DateHumanize_TwoDaysFromNow" xml:space="preserve">
<value>two days from now</value>
</data>
<data name="TimeSpanHumanize_MultipleDays_Paucal" xml:space="preserve">
<value>{0} days</value>
</data>
<data name="TimeSpanHumanize_MultipleHours_Paucal" xml:space="preserve">
<value>{0} hours</value>
</data>
<data name="TimeSpanHumanize_MultipleMilliseconds_Paucal" xml:space="preserve">
<value>{0} milliseconds</value>
</data>
<data name="TimeSpanHumanize_MultipleMinutes_Paucal" xml:space="preserve">
<value>{0} minutes</value>
</data>
<data name="TimeSpanHumanize_MultipleMonths_Paucal" xml:space="preserve">
<value>{0} months</value>
</data>
<data name="TimeSpanHumanize_MultipleSeconds_Paucal" xml:space="preserve">
<value>{0} months</value>
</data>
<data name="TimeSpanHumanize_MultipleWeeks_Paucal" xml:space="preserve">
<value>{0} weeks</value>
</data>
<data name="TimeSpanHumanize_MultipleYears_Paucal" xml:space="preserve">
<value>{0} years</value>
</data>
</root>