LMP.Localize
8.1.0
dotnet add package LMP.Localize --version 8.1.0
NuGet\Install-Package LMP.Localize -Version 8.1.0
<PackageReference Include="LMP.Localize" Version="8.1.0" />
<PackageVersion Include="LMP.Localize" Version="8.1.0" />
<PackageReference Include="LMP.Localize" />
paket add LMP.Localize --version 8.1.0
#r "nuget: LMP.Localize, 8.1.0"
#:package LMP.Localize@8.1.0
#addin nuget:?package=LMP.Localize&version=8.1.0
#tool nuget:?package=LMP.Localize&version=8.1.0
LMP.Localize
A lightweight, thread-safe text localization library for .NET. It supports hierarchical culture fallback, on-the-fly hot reloading, and zero-allocation logging.
Features
- 🌲 Culture Inheritance (Fallback): Automatically resolves missing keys through the culture hierarchy (e.g.,
en-US→en). - 🔄 Hot Reloading: Monitors folders using
FileSystemWatcherand instantly updates dictionaries without blocking reader threads. - 🛡️ Thread-Safe: Designed from the ground up for high-concurrency environments using
ConcurrentDictionaryand atomic references. - 📊 Production-Ready: Natively integrates with
ILoggerFactoryusing high-performance, compile-time generatedLoggerMessagemethods.
File Format
The library expects plain text files with a simple key=value structure. Keys are case-insensitive.
Example file: C:\Localization\en\strings.txt
welcome_message = Welcome to our application!
error_unknown = An unexpected error occurred.
button_save = Save changes
Quick Start
1. Initialize Options and Path Provider
using YourLibrary.Localization;
using Microsoft.Extensions.Logging;
// 1. Configure options
var options = new LanguageManagerOptions(
BaseFolder: @"C:\Localization",
TrackChanges: true // Enables hot reloading via FileSystemWatcher
);
// 2. Choose a path provider (Default structure: {BaseFolder}/{Culture}/{FileName})
// By default, it looks for {YourAssemblyName}.txt, or you can specify a custom name:
ILanguagePathProvider pathProvider = new DefaultLanguagePathProvider("strings.txt");
// 3. Create the manager (ILoggerFactory parameter is optional)
ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
using var manager = new LanguageManager(options, pathProvider, loggerFactory);
2. Access Localized Strings
You can easily retrieve translations via indexers using either culture string names or CultureInfo objects:
// Access via string indexer (culture names are case-insensitive and trimmed)
ILanguage english = manager["en-US"];
Console.WriteLine(english["welcome_message"]); // Output: Welcome to our application!
// Access via CultureInfo indexer
ILanguage russian = manager[CultureInfo.GetCultureInfo("ru")];
Console.WriteLine(russian["button_save"]); // Output: Save changes
Culture Fallback Mechanics
The library utilizes the Chain of Responsibility design pattern. If a specific region file (e.g., en-US) does not
contain the requested key, the system recursively looks for it in the parent culture file (en).
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 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. |
-
net8.0
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.