Persilsoft.Localizer 1.0.4

There is a newer version of this package available.
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                
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="Persilsoft.Localizer" Version="1.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Persilsoft.Localizer --version 1.0.4                
#r "nuget: Persilsoft.Localizer, 1.0.4"                
#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 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last updated
1.0.7 480 10/15/2024
1.0.6 1,564 7/19/2024
1.0.5 181 7/9/2024
1.0.4 1,624 5/22/2024
1.0.3 1,969 4/11/2024
1.0.2 103 4/11/2024
1.0.1 96 4/10/2024
1.0.0 93 4/10/2024