Installation
Requirements
- .NET 8.0 or .NET 10.0
Install via NuGet
dotnet add package Bogoware.LocalizationInstall-Package Bogoware.LocalizationDependencies
Bogoware.Localization has minimal dependencies:
Microsoft.Extensions.DependencyInjection.Abstractions— for DI integrationMicrosoft.Extensions.Logging.Abstractions— for optional logging support
Basic Setup
-
Create your localizable types
Define types that implement the
ILocalizablemarker interface:using Bogoware.Localization;public class ValidationError(string fieldName, string message) : ILocalizable{public string FieldName { get; } = fieldName;public string Message { get; } = message;} -
Add JSON template files
Create JSON files with your localized templates as embedded resources:
{"MyApp.Errors.ValidationError": "Field '{FieldName}': {Message}"} -
Register with DI
services.AddLocalization(typeof(ValidationError).Assembly);This registers:
ILocalizationRegistry— loaded from JSON embedded resources in the specified assemblyILocalizationFormatter— the main formatting service
-
Use the formatter
public class MyService(ILocalizationFormatter formatter){public string GetMessage(ILocalizable localizable){return formatter.Format(localizable);}}
Next Steps
Localizable Types Learn how to define types that participate in localization
JSON Templates Create, organize, and load JSON template files
Provider Chain Understand the full resolution order