Tvermose.BlazorLocalizer
0.9.1
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
<PackageReference Include="Tvermose.BlazorLocalizer" Version="0.9.1" />
paket add Tvermose.BlazorLocalizer --version 0.9.1
#r "nuget: Tvermose.BlazorLocalizer, 0.9.1"
// 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 IBlazorLocalizer
as 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 | Versions 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. |
-
.NETStandard 2.1
- Blazored.LocalStorage (>= 2.1.6)
- Microsoft.AspNetCore.Components (>= 3.1.5)
- Microsoft.AspNetCore.Components.Web (>= 3.1.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 | |
---|---|---|---|
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 | |
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