Tvermose.BlazorLocalizer 0.9.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Tvermose.BlazorLocalizer --version 0.9.1                
NuGet\Install-Package Tvermose.BlazorLocalizer -Version 0.9.1                
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="0.9.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tvermose.BlazorLocalizer --version 0.9.1                
#r "nuget: Tvermose.BlazorLocalizer, 0.9.1"                
#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=0.9.1

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

BlazorLocalizer

A library to provide asynchronous localization in Blazor WebAssembly applications.

Setup

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

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 Program.cs 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.FallbackCategory = "Your.Fallback.Category";
      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", "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 (null, empty or white space), FallbackCategory from your options will be used if that has been set.

Usage (Blazor Server)

Not currently supported.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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,861 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

Preview release