Tvermose.BlazorLocalizer
11.0.4
dotnet add package Tvermose.BlazorLocalizer --version 11.0.4
NuGet\Install-Package Tvermose.BlazorLocalizer -Version 11.0.4
<PackageReference Include="Tvermose.BlazorLocalizer" Version="11.0.4" />
<PackageVersion Include="Tvermose.BlazorLocalizer" Version="11.0.4" />
<PackageReference Include="Tvermose.BlazorLocalizer" />
paket add Tvermose.BlazorLocalizer --version 11.0.4
#r "nuget: Tvermose.BlazorLocalizer, 11.0.4"
#:package Tvermose.BlazorLocalizer@11.0.4
#addin nuget:?package=Tvermose.BlazorLocalizer&version=11.0.4
#tool nuget:?package=Tvermose.BlazorLocalizer&version=11.0.4
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.
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.
Eager Loading
You can preload resources at app startup to avoid loading delays when the user navigates to a page. There are two approaches:
Option 1: Implement GetAllResources on your resource provider
Override the GetAllResources method on your IResourceProvider implementation to return all resources for all categories in a single call. This is the most efficient approach as it requires only a single HTTP request.
public class YourResourceProvider : IResourceProvider
{
// ... other methods ...
public async Task<IDictionary<string, IDictionary<string, string>>> GetAllResources(string cultureName)
{
// Return all resources grouped by category
return await _httpClient.GetFromJsonAsync<Dictionary<string, Dictionary<string, string>>>(
$"api/localization/all?culture={cultureName}");
}
}
Then call PreloadAsync() at startup:
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddTransient<IResourceProvider, YourResourceProvider>();
builder.Services.AddBlazorLocalization();
var host = builder.Build();
await host.Services.GetRequiredService<IBlazorLocalizer>().PreloadAsync();
await host.RunAsync();
}
Option 2: Specify categories to eager load
If you don't implement GetAllResources, you can specify individual categories to preload using the EagerLoadCategories option. Each category will be loaded individually using the existing GetCategoryResources method.
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddTransient<IResourceProvider, YourResourceProvider>();
builder.Services.AddBlazorLocalization(config => {
config.EagerLoadCategories = new List<string>
{
"MyApp.Shared.Layout",
"MyApp.Pages.Home",
"MyApp.Pages.About"
};
});
var host = builder.Build();
await host.Services.GetRequiredService<IBlazorLocalizer>().PreloadAsync();
await host.RunAsync();
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.AspNetCore.Components (>= 10.0.5)
- Microsoft.AspNetCore.Components.Web (>= 10.0.5)
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 | |
|---|---|---|---|
| 11.0.4 | 95 | 4/12/2026 | |
| 11.0.3 | 87 | 4/12/2026 | |
| 11.0.2 | 85 | 4/11/2026 | |
| 11.0.1 | 359 | 3/22/2026 | |
| 11.0.0 | 535 | 2/19/2026 | |
| 10.2.0 | 4,489 | 1/11/2024 | |
| 10.1.0 | 288 | 11/22/2023 | |
| 10.0.0 | 233 | 10/26/2023 | |
| 7.0.1 | 1,199 | 6/20/2023 | |
| 7.0.0 | 281 | 6/20/2023 | |
| 5.0.10 | 3,442 | 9/17/2021 | |
| 5.0.0 | 748 | 3/5/2021 | |
| 1.0.2 | 1,501 | 7/20/2020 | |
| 1.0.1 | 849 | 7/18/2020 | |
| 1.0.0 | 661 | 7/8/2020 | |
| 0.9.3 | 750 | 6/25/2020 | |
| 0.9.2 | 651 | 6/22/2020 | |
| 0.9.1 | 670 | 6/20/2020 | |
| 0.9.0 | 672 | 6/20/2020 |