Toolbelt.SystemResourceManager 1.0.0

dotnet add package Toolbelt.SystemResourceManager --version 1.0.0                
NuGet\Install-Package Toolbelt.SystemResourceManager -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Toolbelt.SystemResourceManager" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Toolbelt.SystemResourceManager --version 1.0.0                
#r "nuget: Toolbelt.SystemResourceManager, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Toolbelt.SystemResourceManager as a Cake Addin
#addin nuget:?package=Toolbelt.SystemResourceManager&version=1.0.0

// Install Toolbelt.SystemResourceManager as a Cake Tool
#tool nuget:?package=Toolbelt.SystemResourceManager&version=1.0.0                

Toolbelt.SystemResourceManager NuGet Package

This is the library for .NET that allows you to inject your custom resource manager into your .NET apps, such as Blazor, as the System Resource Manager.

That means you can localize DataAnnotations validation error messages provided by the .NET runtime with this library.

Warning
⚠️ This library touches undocumented areas and private implementations of the .NET runtime, using the "Reflection" technology. So please remember that it might not be working on future .NET versions.

Usage

  1. Install this library as a NuGet package.
dotnet add package Toolbelt.SystemResourceManager
  1. Call the AddSystemResourceManager() extension method for a service collection at the startup of your apps with specifying the resource name you want to inject and its assembly.
// Program.cs
...
builder.Services.AddSystemResourceManager("SampleApp.Resource1", typeof(SampleApp.Resource1).Assembly);
...

You can also use the AddSystemResourceManager<TResource>() overload version instead.

// Program.cs
...
using SampleApp;
...
builder.Services.AddSystemResourceManager<Resource1>();
...

After doing that, the resource strings for the DataAnnotations validation error messages will be retrieved from the resource you specified at first. If the resource string with the specified key doesn't exist in the resource you specified, it will be retrieved from the resource that is before of you injected it.

You can call the AddSystemsResourceManager() extension method multiple with each different resource to inject it. The last injected resource is the most high-priority resource for retrieving resource strings.

Example

  1. Create a new Blazor application project.

  2. Create a model class on your Blazor app project like below.

using System.ComponentModel.DataAnnotations;
public class ValidationTestModel
{
    [Required]
    public string RequiredField { get; set; } = "";
}
  1. Implement a form on a Razor component on your Blazor app project.
<EditForm Model="_Model">
    <DataAnnotationsValidator/>
    <InputText @bind-Value="_Model.RequiredField" />
    <ValidationSummary />
    <button type="submit">Submit</button>
</EditForm>

@code {
    private ValidationTestModel _Model = new();
}
  1. Prepare Resource1.resx and Resource1.ja.resx resource files on your Blazor project. Make the Resource1.ja.resx to be below.
Name Value
RequiredAttribute_ValidationError フィールド {0} は必須です。
  1. Inject the Resource1 resource as a system resource.
// Program.cs
...
using SampleApp;
...
builder.Services.AddSystemResourceManager<Resource1>();
...
  1. Finally, you will see localized validation error messages on your Blazor app, like this.

alternate text is missing from this package README image

Release Note

Release notes

License

Mozilla Public License Version 2.0

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Toolbelt.SystemResourceManager:

Package Downloads
Toolbelt.ComponentModel.Annotations.Resources

Built-in validation error messages for validation attributes such as [Required], [StringLength], etc., on your ASP.NET Core and Blazor apps will be shown localized after installing this NuGet package.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 672 7/18/2022

v.1.0.0
- 1st release;

To see all the change logs, please visit the following URL.
- https://github.com/jsakamoto/Toolbelt.SystemResourceManager/blob/main/RELEASE-NOTES.txt