Mafesoft.Localization.Extensions 4.3.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Mafesoft.Localization.Extensions --version 4.3.0
                    
NuGet\Install-Package Mafesoft.Localization.Extensions -Version 4.3.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="Mafesoft.Localization.Extensions" Version="4.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Mafesoft.Localization.Extensions" Version="4.3.0" />
                    
Directory.Packages.props
<PackageReference Include="Mafesoft.Localization.Extensions" />
                    
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 Mafesoft.Localization.Extensions --version 4.3.0
                    
#r "nuget: Mafesoft.Localization.Extensions, 4.3.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.
#:package Mafesoft.Localization.Extensions@4.3.0
                    
#: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=Mafesoft.Localization.Extensions&version=4.3.0
                    
Install as a Cake Addin
#tool nuget:?package=Mafesoft.Localization.Extensions&version=4.3.0
                    
Install as a Cake Tool

Mafesoft.Localization.Extensions

NuGet Downloads Build License: MIT

Microsoft.Extensions integration of Mafesoft.Localization: registers the LocalizationManager in the dependency injection and provides IStringLocalizer, IStringLocalizer<T> and IStringLocalizerFactory backed by its vocabularies. Every consumer of Microsoft.Extensions.Localization (DataAnnotations, IViewLocalizer, Blazor components, third-party UI libraries) reads the same vocabularies.

Target frameworks: .NET 10, .NET 8, .NET Standard 2.0.

Quick start

dotnet add package Mafesoft.Localization.Extensions
using Mafesoft.Localization.Extensions;

builder.Services.AddLocalizationManager(options =>
{
    options.ServiceProvider = new MyVocabularyServiceProvider();
    options.Culture = new CultureInfo("it-IT");
})
.AddStringLocalizer();
public class HomeController(IStringLocalizer<HomeController> localizer) : Controller
{
    public IActionResult Index() => View(model: localizer["Welcome"].Value);
}
  • A missing key returns the key itself with ResourceNotFound = true, and the provider is notified (AddOrUpdateTermAsync), exactly like LocalizationManager.Instance[key].
  • localizer["Format", arg] formats the value with the current culture.
  • GetAllStrings() returns the vocabulary of the current culture.
  • With AddStringLocalizer(o => o.UseTypeNamePrefix = true) the keys are prefixed with the type name: IStringLocalizer<HomeController>["Title"] reads HomeController.Title. Off by default.

With ASP.NET Core MVC, AddDataAnnotationsLocalization() uses it to translate [Display(Name = "...")] and the validation messages.

Differences from the resx localizer

Replacing AddLocalization() with AddLocalizationManager(...).AddStringLocalizer() keeps the code that uses IStringLocalizer<T>, IViewLocalizer, IHtmlLocalizer<T> and DataAnnotations unchanged, but the behaviour is not the same as the resx-based ResourceManagerStringLocalizer:

resx (AddLocalization()) Mafesoft.Localization
Culture CultureInfo.CurrentUICulture, per request with UseRequestLocalization() One culture for the whole application, changed with SetCulture. With FollowCurrentUICulture = true: CultureInfo.CurrentUICulture, per request like resx
Keys One resource file per type or view (Controllers.HomeController.it.resx) One vocabulary per culture, shared by every localizer. With UseTypeNamePrefix the key is TypeName.Key (Type.Name, without namespace) or baseName.Key for the views
Parent cultures it-IT falls back to it and then to the neutral resources No fallback, includeParentCultures is ignored
Missing key Returns the key, ResourceNotFound = true Same, and the provider is notified (AddOrUpdateTermAsync)
Source of the strings .resx files embedded in the assembly The IVocabularyServiceProvider (the resx strings must be moved there)
  • One culture per application by default. Without FollowCurrentUICulture the localizer does not read CultureInfo.CurrentUICulture, so UseRequestLocalization(), the culture cookie and Accept-Language have no effect and every user sees the same language. On a server enable it (each culture is loaded once and cached):

    builder.Services.AddLocalizationManager(options =>
    {
        options.ServiceProvider = new MyVocabularyServiceProvider();
        options.FollowCurrentUICulture = true;
    })
    .AddStringLocalizer();
    
    app.UseRequestLocalization(o => o.AddSupportedCultures("it-IT", "en-US").AddSupportedUICultures("it-IT", "en-US"));
    
  • Shared keys. Two resx files that translate the same key differently collide in the vocabulary: rename the keys or enable UseTypeNamePrefix.

  • The default validation messages of DataAnnotations (without ErrorMessage) are not translated, as with resx.

Licensed under the MIT License.

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 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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
4.4.0 83 11/19/2026
4.3.0 97 11/14/2026
4.1.1 90 11/13/2026
4.1.0 269 11/11/2026
4.1.0-rc.1 59 11/10/2026