Persilsoft.Localizer 1.0.3

dotnet add package Persilsoft.Localizer --version 1.0.3
NuGet\Install-Package Persilsoft.Localizer -Version 1.0.3
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.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Persilsoft.Localizer --version 1.0.3
#r "nuget: Persilsoft.Localizer, 1.0.3"
#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.3

// Install Persilsoft.Localizer as a Cake Tool
#tool nuget:?package=Persilsoft.Localizer&version=1.0.3

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 (4)

Showing the top 4 NuGet packages that depend on Persilsoft.Localizer:

Package Downloads
Persilsoft.Exceptions

Package Description

Persilsoft.Membership.Shared.Validators

Package Description

Persilsoft.GeolocationMap.Blazor

Package Description

Persilsoft.Membership.Blazor

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.3 950 4/11/2024
1.0.2 77 4/11/2024
1.0.1 71 4/10/2024
1.0.0 68 4/10/2024