Zonit.Extensions.Cultures 10.0.0-preview.2

This is a prerelease version of Zonit.Extensions.Cultures.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Zonit.Extensions.Cultures --version 10.0.0-preview.2
                    
NuGet\Install-Package Zonit.Extensions.Cultures -Version 10.0.0-preview.2
                    
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="Zonit.Extensions.Cultures" Version="10.0.0-preview.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Zonit.Extensions.Cultures" Version="10.0.0-preview.2" />
                    
Directory.Packages.props
<PackageReference Include="Zonit.Extensions.Cultures" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Zonit.Extensions.Cultures --version 10.0.0-preview.2
                    
#r "nuget: Zonit.Extensions.Cultures, 10.0.0-preview.2"
                    
#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.
#:package Zonit.Extensions.Cultures@10.0.0-preview.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Zonit.Extensions.Cultures&version=10.0.0-preview.2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Zonit.Extensions.Cultures&version=10.0.0-preview.2&prerelease
                    
Install as a Cake Tool

Zonit.Extensions.Cultures

Per-scope culture / time-zone state, translation registry and 17 built-in BCP-47 languages for ASP.NET Core and Blazor. Built on top of the Culture and Translated value objects from Zonit.Extensions.

NuGet Downloads

dotnet add package Zonit.Extensions.Cultures

What you get

  • ICultureState — read-only view (Current : Culture, TimeZone, Supported) for renderers.
  • ICultureManager : ICultureState — adds SetCulture(Culture) and SetTimeZone(string) for switchers.
  • ICultureProviderTranslate(content, args) : Translated, ClientTimeZone(utc) and DateTimeFormat.
  • ILanguageProvider — process-wide registry of 17 languages, O(1) exact lookup + O(1) primary-subtag fallback (so en-gb resolves to en-us).
  • TranslationRepository / DefaultTranslationRepository / MissingTranslationRepository — concurrent dictionaries keyed by translation name; missing-key tracking for development.
  • ASP.NET Core middleware that resolves the requested culture from URL path / cookie / Accept-Language and writes a one-year Culture cookie.

Setup

// Program.cs
builder.Services.AddCulturesExtension(o =>
{
    o.DefaultCulture = "en-us";
    o.DefaultTimeZone = "Europe/Warsaw";
    o.SupportedCultures = ["en-us", "pl-pl", "de-de"];
});

var app = builder.Build();
app.UseMiddleware<CultureMiddleware>();

For Blazor add the persistence bridge component once (e.g. in Routes.razor):

@using Zonit.Extensions
<ZonitCulturesExtension />

Translating

@inject ICultureProvider Culture

<h1>@Culture.Translate("Hello, {0}!", User.Name)</h1>
<p>Created at @Culture.ClientTimeZone(order.CreatedAtUtc)
   in @Culture.Current.NativeName</p>

Translate(...) returns Translated, which implicitly converts to string, so existing call sites keep working.

Switching culture

@inject ICultureManager Manager

<button @onclick="@(() => Manager.SetCulture("pl-pl"))">Polski</button>

The change raises ICultureState.OnChange, which ICultureProvider re-emits — components subscribed to it can re-render automatically (the Website integration's ExtensionsBase already handles this).

Loading translations

[Inject] ITranslationManager Translations { get; set; } = null!;

Translations.AddRange(new[]
{
    new Variable("Hello, {0}!", new List<Translate>
    {
        new() { Culture = "pl-pl", Content = "Cześć, {0}!" },
        new() { Culture = "de-de", Content = "Hallo, {0}!" },
    }),
});

Backed by a thread-safe ConcurrentDictionary keyed by the source string — translation lookups are O(1).

Built-in languages

ar-sa cs-cz da-dk nl-nl en-us fi-fi fr-fr de-de hu-hu it-it no-no pl-pl pt-pt ru-ru sk-sk es-es sv-se

Resolved via ILanguageProvider.GetByCode(code). The lookup falls back to the primary subtag (en-gben-us) and then to en-us. Each language is a LanguageModel with Code, EnglishName and an inline SVG IconFlag.

Lifetimes

  • Translation repositories — singleton (process-wide).
  • LanguageService — singleton (immutable).
  • CultureStateService — scoped, exposed under ICultureState / ICultureManager / CultureStateService pointing to the same instance, so writers and readers in one request observe the same state and OnChange notifications.
  • CultureService (ICultureProvider) — scoped, subscribes to the state's OnChange and re-emits.

License

MIT.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Zonit.Extensions.Cultures:

Package Downloads
Zonit.Extensions.Website

ASP.NET Core and Blazor web extensions providing base components (PageBase, PageEditBase, PageViewBase), navigation services, breadcrumbs management, toast notifications, cookie handling, and data protection utilities for building modern web applications.

Zonit.Services.Dashboard

Package Description

Zonit.Services.Manager

Package Description

Zonit.Services.Dashboard.Components

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.0.0-preview.9 57 5/16/2026
10.0.0-preview.6 54 5/15/2026
10.0.0-preview.2 68 5/12/2026
0.1.51 129 1/15/2026
0.1.50 529 11/18/2025
0.1.7 266 8/9/2025
0.1.6 220 7/31/2025
0.1.5 318 7/26/2025
0.1.4 357 7/26/2025
0.1.3 271 5/28/2025
0.1.2 479 1/29/2025
0.1.1 240 5/28/2024
0.1.0 188 5/27/2024
0.0.31 192 5/21/2024
0.0.30 178 5/20/2024
0.0.23 212 5/18/2024
0.0.21 208 5/16/2024
0.0.18 213 5/15/2024
0.0.17 197 5/15/2024
0.0.16 209 5/14/2024
Loading failed