Toolbelt.SystemResourceManager
1.0.0
dotnet add package Toolbelt.SystemResourceManager --version 1.0.0
NuGet\Install-Package Toolbelt.SystemResourceManager -Version 1.0.0
<PackageReference Include="Toolbelt.SystemResourceManager" Version="1.0.0" />
paket add Toolbelt.SystemResourceManager --version 1.0.0
#r "nuget: Toolbelt.SystemResourceManager, 1.0.0"
// 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
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
- Install this library as a NuGet package.
dotnet add package Toolbelt.SystemResourceManager
- 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
Create a new Blazor application project.
Create a model class on your Blazor app project like below.
using System.ComponentModel.DataAnnotations;
public class ValidationTestModel
{
[Required]
public string RequiredField { get; set; } = "";
}
- 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();
}
- Prepare
Resource1.resx
andResource1.ja.resx
resource files on your Blazor project. Make theResource1.ja.resx
to be below.
Name | Value |
---|---|
RequiredAttribute_ValidationError | フィールド {0} は必須です。 |
- Inject the
Resource1
resource as a system resource.
// Program.cs
...
using SampleApp;
...
builder.Services.AddSystemResourceManager<Resource1>();
...
- Finally, you will see localized validation error messages on your Blazor app, like this.
Release Note
License
Product | Versions 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. |
-
.NETStandard 2.1
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 3.1.0)
- System.ComponentModel.Annotations (>= 4.1.0)
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