Tvermose.BlazorLocalizer 10.2.0

dotnet add package Tvermose.BlazorLocalizer --version 10.2.0                
NuGet\Install-Package Tvermose.BlazorLocalizer -Version 10.2.0                
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="Tvermose.BlazorLocalizer" Version="10.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tvermose.BlazorLocalizer --version 10.2.0                
#r "nuget: Tvermose.BlazorLocalizer, 10.2.0"                
#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 Tvermose.BlazorLocalizer as a Cake Addin
#addin nuget:?package=Tvermose.BlazorLocalizer&version=10.2.0

// Install Tvermose.BlazorLocalizer as a Cake Tool
#tool nuget:?package=Tvermose.BlazorLocalizer&version=10.2.0                

BlazorLocalizer

A library to provide asynchronous localization in Blazor WebAssembly applications. Caches localized values in memory and i localStorage for a configurable amount of time.

Nuget

Installing

You can install from NuGet using the following command:

Install-Package Tvermose.BlazorLocalizer

Or via the Visual Studio package manager.

Setup

You will need to implement the interface BlazorLocalizer.IResourceProvider and register the implementation with the service collection in your <i>Program.cs</i> in Blazor WebAssembly.

Likewise you will need to register the IBlazorLocalizer by using the extension method AddBlazorLocalization().

public static async Task Main(string[] args)
{
    var builder = WebAssemblyHostBuilder.CreateDefault(args);
    builder.RootComponents.Add<App>("app");
    
    builder.Services.AddTransient<BlazorLocalizer.IResourceProvider, YourResourceProviderImplementation>();
    builder.Services.AddBlazorLocalization();

    await builder.Build().RunAsync();
}

Configuration

BlazorLocalizer provides options that can be modified by you at registration in your <i>Program.cs</i> file in Blazor WebAssembly. Localized values will per default be cached for 3 days using localStorage. This can be modified or disabled using the LocalStorageOptions as shown below.

public static async Task Main(string[] args)
{
    var builder = WebAssemblyHostBuilder.CreateDefault(args);
    builder.RootComponents.Add<App>("app");
    
    builder.Services.AddTransient<BlazorLocalizer.IResourceProvider, YourResourceProviderImplementation>();
    builder.Services.AddBlazorLocalization(config => {
      config.LocalStorageOptions.CacheInvalidation = TimeSpan.FromDays(1);
      config.LocalStorageOptions.CacheDisabled = false;
    });

    await builder.Build().RunAsync();
}

Usage (Blazor WebAssembly)

To use BlazorLocalization in Blazor WebAssembly, inject the IBlazorLocalizeras in the example below.

@inject BlazorLocalizer.IBlazorLocalizer loc

<p title=@_title>
  @loc["Localize this text using the calling class fullname as category"]
  @loc["Localize this text", "Example.Category"]
</p>

@code {

    private string _title = "Title for localize this text";
  
    protected override async Task OnInitializedAsync()
    {
        _title = await loc.L(_title, "Example.Category");
    }

}

If you do not provide a category for the localized text, the calling class fullname will be used as category.

Usage (Blazor Server)

Not currently supported.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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

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
10.2.0 1,817 1/11/2024
10.1.0 198 11/22/2023
10.0.0 145 10/26/2023
7.0.1 1,085 6/20/2023
7.0.0 163 6/20/2023
5.0.10 3,260 9/17/2021
5.0.0 450 3/5/2021 5.0.0 is deprecated because it has critical bugs.
1.0.2 1,297 7/20/2020
1.0.1 615 7/18/2020
1.0.0 462 7/8/2020
0.9.3 531 6/25/2020
0.9.2 445 6/22/2020
0.9.1 468 6/20/2020
0.9.0 473 6/20/2020