Persilsoft.Localizer
1.0.4
See the version list below for details.
dotnet add package Persilsoft.Localizer --version 1.0.4
NuGet\Install-Package Persilsoft.Localizer -Version 1.0.4
<PackageReference Include="Persilsoft.Localizer" Version="1.0.4" />
paket add Persilsoft.Localizer --version 1.0.4
#r "nuget: Persilsoft.Localizer, 1.0.4"
// Install Persilsoft.Localizer as a Cake Addin #addin nuget:?package=Persilsoft.Localizer&version=1.0.4 // Install Persilsoft.Localizer as a Cake Tool #tool nuget:?package=Persilsoft.Localizer&version=1.0.4
Persilsoft.Localizer
A simple tool for Localization of projects
First, you need to create resource files. The name of each resource file must be follow the format:
{Extractor}.{Culture}.{resx}
Where:
Extractor: The name class to used to interact with the resource files, for example: Messages
Culture: The culture identifier, for example: en-US, es-PE
resx: This is the file extension for resource files
The following are some examples of resource file names:
- Messages.en-US.resx (English for USA)
- Messages.es-PE.resx (Spanish for Peru)
In each resource file create an entry with the same key but with the value according to the corresponding language, for example:
- Name: Message Value=Hello World!
- Name: Message Value=¡Hola Mundo!
Now, you need to create a class to access each key in the resource file. In the example, we are creating the class called Messages
using Persilsoft.Localizer;
public class Messages
{
public static string Hello =>
LocalizationUtils<Messages>.GetValue(nameof(Hello));
}
Now you can use it.
using System.Globalization;
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
Console.WriteLine(Messages.Hello);
Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-PE");
Console.WriteLine(Messages.Hello);
In the case of AspNet Core application, you need to configure the Localization Middleware:
builder.Services.Configure<RequestLocalizationOptions>(options =>
{
var SupportedCultures = new[] { "en-US", "es-PE" };
var NeutralCulture = SupportedCultures[0];
options.SetDefaultCulture(NeutralCulture)
.AddSupportedCultures(SupportedCultures)
.AddSupportedUICultures(SupportedCultures);
});
Then add the Localization pipeline:
app.UseRequestLocalization();
Finally, you can use it.
app.MapGet("/localizer/message", () =>
{
return Results.Ok(Messages.Hello);
})
.WithName("Localizer");
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
-
net8.0
- Microsoft.Extensions.Localization (>= 8.0.5)
NuGet packages (7)
Showing the top 5 NuGet packages that depend on Persilsoft.Localizer:
Package | Downloads |
---|---|
Persilsoft.Exceptions
Custom exceptions with their respective handlers |
|
Persilsoft.Membership.Blazor
Contains razor clases for use in frontend membership projects |
|
Persilsoft.Membership.Shared.Validators
Contains validators for backend and frontend membership projects |
|
Persilsoft.ExceptionHandler.Blazor
Contains Razor components to manage exceptions in Blazor Apps |
|
Persilsoft.Mail.MailKit.Sender
An implementation of MailKit (a popular Mail library) |
GitHub repositories
This package is not used by any popular GitHub repositories.