Agency8.MyLocalizer 0.0.1

dotnet add package Agency8.MyLocalizer --version 0.0.1
                    
NuGet\Install-Package Agency8.MyLocalizer -Version 0.0.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="Agency8.MyLocalizer" Version="0.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Agency8.MyLocalizer" Version="0.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Agency8.MyLocalizer" />
                    
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 Agency8.MyLocalizer --version 0.0.1
                    
#r "nuget: Agency8.MyLocalizer, 0.0.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.
#:package Agency8.MyLocalizer@0.0.1
                    
#: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=Agency8.MyLocalizer&version=0.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Agency8.MyLocalizer&version=0.0.1
                    
Install as a Cake Tool

Agency8.MyLocalizer

Agency8.MyLocalizer is a .NET 9 class library for database-driven string localization, designed for ASP.NET Core applications. It provides a flexible, culture-aware localization system with support for custom cultures, caching, and integration with Entity Framework Core.

Features

  • Database-backed localization: Store translations and cultures in a relational database.
  • Culture management: Add, enable/disable, and set default cultures.
  • Caching: In-memory cache for fast lookup of translations.
  • Dependency Injection: Easily integrate with ASP.NET Core DI.
  • Culture switching: Controller for runtime culture changes via cookies.
  • Fallbacks: Automatic fallback to default or parent cultures.
  • Extensible: Interfaces for custom repositories and cache implementations.

Installation

Add the NuGet package to your project:

dotnet add package Agency8.MyLocalizer

Getting Started

1. Configure Services

Register MyLocalizer in your Startup.cs or Program.cs:

services.AddMyLocalizer("YourConnectionString");

2. Configure Database

The library uses Entity Framework Core. Supported providers include SQL Server and SQLite.

  • MyLocalizerDbContext manages two tables:
    • MyTranslations: Stores key/value pairs per culture.
    • MyCultures: Stores available cultures.

Tables are created automatically if they do not exist.

3. Use Middleware

Set the default culture at application startup:

await app.UseMyLocalizer("en-US");

4. Inject and Use Localizer

Inject IMyStringLocalizer into your controllers or services:

public class HomeController : Controller
{
    private readonly IMyStringLocalizer _localizer;

    public HomeController(IMyStringLocalizer localizer)
    {
        _localizer = localizer;
    }

    public IActionResult Index()
    {
        var greeting = _localizer["Hello"];
        return View(model: greeting);
    }
}

5. Change Culture at Runtime

Use the built-in controller to change the UI culture:

GET /MyCulture/Set?culture=fr-FR&redirectUri=/

API Overview

Entities

  • MyTranslation: Represents a localized string for a specific culture.
  • MyCulture: Represents a supported culture.

Services

  • IMyStringLocalizer: Main interface for retrieving localized strings.
  • LocalizationProvider: Handles lookup and fallback logic.
  • ILocalizationCache: Interface for caching translations.

Extension Methods

  • AddMyLocalizer(IServiceCollection, string): Registers all required services.
  • UseMyLocalizer(IApplicationBuilder, string): Ensures tables exist and sets the default culture.

Example Database Schema

MyTranslations | Id (Guid) | Key (string) | Value (string) | Culture (string) | CultureId (Guid) |

MyCultures | Id (Guid) | CultureCode (string) | DisplayName (string) | IsEnabled (bool) | IsDefault (bool) |

Advanced Usage

  • Custom Cache: Implement ILocalizationCache for distributed caching.
  • Custom Repositories: Implement IMyCultureRepository or IMyTranslationRepository for advanced data access.
  • Culture Change Notification: Use CultureChangeNotifier to react to culture changes.

License

See LICENSE.txt for details.

Contributing

Pull requests and issues are welcome! Please open an issue to discuss your ideas.

Support

For questions or support, open an issue on GitHub.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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 was computed.  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 (1)

Showing the top 1 NuGet packages that depend on Agency8.MyLocalizer:

Package Downloads
Agency8.MyLocalizer.Components

A powerful localization component library for Blazor (.NET 9) applications. Agency8.MyLocalizer.Components enables easy multilingual support, dynamic language switching, and centralized translation management. Includes UI components for translation editing and resource management. Designed for extensibility and production readiness.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.1 210 1/26/2026