Localizer.Blazor 1.0.7

Suggested Alternatives

Persilsoft.Localizer

Additional Details

You can use Persilsoft.Localizer

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Localizer.Blazor --version 1.0.7
NuGet\Install-Package Localizer.Blazor -Version 1.0.7
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="Localizer.Blazor" Version="1.0.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Localizer.Blazor --version 1.0.7
#r "nuget: Localizer.Blazor, 1.0.7"
#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 Localizer.Blazor as a Cake Addin
#addin nuget:?package=Localizer.Blazor&version=1.0.7

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

Localizer.Blazor

A simple localization tool for Blazor apps


First, you need to register the Localization service

builder.Services.AddLocalization();

Then, set culture settings.

var AppHost = builder.Build();

var jsRuntime = AppHost.Services.GetRequiredService<IJSRuntime>();
var RegionCode = await jsRuntime.InvokeAsync<string>("localStorage.getItem", "culture");
CultureInfo Culture = CultureInfo.CreateSpecificCulture("es-PE");
if (RegionCode != null)
{
    Culture = CultureInfo.CreateSpecificCulture(RegionCode);
}
CultureInfo.DefaultThreadCurrentCulture = Culture;
CultureInfo.DefaultThreadCurrentUICulture = Culture;

await AppHost.RunAsync();

Localized messages must be extracted from the properties of the class that interacts with the resource file, for example:

public class Messages
{
    public static string Home =>
        LocalizationUtils<Messages>.GetValue(nameof(Home));

    public static string About =>
        LocalizationUtils<Messages>.GetValue(nameof(About));

    public static string Hello =>
        LocalizationUtils<Messages>.GetValue(nameof(Hello));

    public static string Welcome =>
        LocalizationUtils<Messages>.GetValue(nameof(Welcome));
}

It is necessary that the name of the resource files follow the following 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

Finally, you can use them:

@page "/"

<PageTitle>@Messages.Home</PageTitle>
<h1>@Messages.Hello</h1>
@Messages.Welcome

To change the culture settings, we can use the CultureSelector component, for example in the MainLayout:

<CultureSelector SupportedCultures="SupportedCultures" />
@code {
    private string[] SupportedCultures;
    protected override async Task OnInitializedAsync()
    {
        SupportedCultures = new string[] { "en-US", "es-PE" };

        await Task.CompletedTask;
    }
}
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 (1)

Showing the top 1 NuGet packages that depend on Localizer.Blazor:

Package Downloads
ZMembership.Blazor

Membership Blazor

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated