Localizer.Tools
1.2.6
You can use Persilsoft.Localizer
dotnet add package Localizer.Tools --version 1.2.6
NuGet\Install-Package Localizer.Tools -Version 1.2.6
<PackageReference Include="Localizer.Tools" Version="1.2.6" />
paket add Localizer.Tools --version 1.2.6
#r "nuget: Localizer.Tools, 1.2.6"
// Install Localizer.Tools as a Cake Addin #addin nuget:?package=Localizer.Tools&version=1.2.6 // Install Localizer.Tools as a Cake Tool #tool nuget:?package=Localizer.Tools&version=1.2.6
Localizer.Tools
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
public class Messages
{
public static string Hello =>
LocalizationUtils<Messages>.GetValue(nameof(Hello));
}
Now you can use it.
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
Console.WriteLine(Messages.Hello);
Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-PE");
Console.WriteLine(Messages.Hello);
Global usings
global using Localizer.Tools;
global using System.Globalization;
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.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|