Lepo.i18n.DependencyInjection 2.1.0

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

<div align="center"> <img src="https://github.com/lepoco/i18n/blob/main/build/nuget.png?raw=true" width="128" alt="Lepo.i18n logo"/> <h1>Lepo.i18n</h1> <h3><em>Internationalization library for .NET applications.</em></h3> </div>

<p align="center"> <strong>Add multilingual support to WPF, WinForms, or CLI apps. JSON, YAML, and RESX resources with Dependency Injection.</strong> </p>

<p align="center"> <a href="https://www.nuget.org/packages/Lepo.i18n"><img src="https://img.shields.io/nuget/v/Lepo.i18n.svg" alt="NuGet"/></a> <a href="https://www.nuget.org/packages/Lepo.i18n"><img src="https://img.shields.io/nuget/dt/Lepo.i18n.svg" alt="NuGet Downloads"/></a> <a href="https://github.com/lepoco/i18n/stargazers"><img src="https://img.shields.io/github/stars/lepoco/i18n?style=social" alt="GitHub stars"/></a> <a href="https://github.com/lepoco/i18n/blob/main/LICENSE"><img src="https://img.shields.io/github/license/lepoco/i18n" alt="License"/></a> </p>

<p align="center"> <a href="https://lepo.co/">Created in Poland by Leszek Pomianowski</a> and <a href="https://github.com/lepoco/i18n/graphs/contributors">open-source community</a>. </p>


Table of Contents


Why This Library?

Traditional .NET localization with resource files requires ceremony and scattered configuration:

// Traditional approach - manual resource loading
ResourceManager rm = new("MyApp.Resources.Strings", typeof(Program).Assembly);
CultureInfo culture = new("pl-PL");
string translated = rm.GetString("HelloWorld", culture) ?? "Hello World";

With Lepo.i18n, localizations are registered once and consumed anywhere - including directly in XAML:

// Lepo.i18n with Dependency Injection
services.AddStringLocalizer(b =>
{
    b.SetCulture("pl-PL");
    b.FromResource<Translations>(new CultureInfo("pl-PL"));
    b.FromResource<Translations>(new CultureInfo("en-US"));
});

<TextBlock Text="{i18n:StringLocalizer 'Hello World'}" />

Get Started

Install the Packages

dotnet add package Lepo.i18n

Pick additional packages based on your needs:

# Microsoft.Extensions.DependencyInjection integration
dotnet add package Lepo.i18n.DependencyInjection

# Load translations from JSON files
dotnet add package Lepo.i18n.Json

# WPF markup extensions
dotnet add package Lepo.i18n.Wpf

NuGet: https://www.nuget.org/packages/Lepo.i18n


How to Use

1. Register Localizations

<details open> <summary><strong>WPF Application (without DI)</strong></summary>

public partial class App : Application
{
    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);

        this.UseStringLocalizer(b =>
        {
            b.SetCulture(new CultureInfo("pl-PL"));
            b.FromResource<Translations>(new CultureInfo("pl-PL"));
            b.FromResource<Translations>(new CultureInfo("en-US"));
        });
    }
}

</details>

<details> <summary><strong>Generic Host with Dependency Injection</strong></summary>

IHost host = Host.CreateDefaultBuilder()
    .ConfigureServices((context, services) =>
    {
        services.AddStringLocalizer(b =>
        {
            b.SetCulture("pl-PL");
            b.FromResource<Translations>(new CultureInfo("pl-PL"));
            b.FromJson(assembly, "Resources.Translations-en.json", new CultureInfo("en-US"));
        });
    })
    .Build();

</details>

<details> <summary><strong>Loading from JSON files</strong></summary>

services.AddStringLocalizer(b =>
{
    b.SetCulture("en-US");
    b.FromJson(assembly, "Resources.en-US.json", new CultureInfo("en-US"));
    b.FromJson(assembly, "Resources.pl-PL.json", new CultureInfo("pl-PL"));
});

</details>


2. Localize in XAML

Add the i18n XML namespace and use the StringLocalizer markup extension:

<Window
    xmlns:i18n="http://schemas.lepo.co/i18n/2022/xaml">

    <StackPanel>
        
        <TextBlock Text="{i18n:StringLocalizer 'Hello World'}" />

        
        <TextBlock Text="{i18n:StringLocalizer 'Test {0}, of {1}!', Arg1='What?', Arg2='No'}" />

        
        <CheckBox Content="{i18n:StringLocalizer 'Enable notifications'}" />
    </StackPanel>
</Window>

3. Change Culture at Runtime

<details open> <summary><strong>WPF Application</strong></summary>

Application.Current.SetLocalizationCulture(new CultureInfo("en-US"));

</details>

<details> <summary><strong>With ILocalizationCultureManager (DI)</strong></summary>

public class SettingsViewModel(ILocalizationCultureManager cultureManager)
{
    public void SwitchToEnglish()
    {
        cultureManager.SetCulture("en-US");
    }
}

</details>


Packages

Package Description
Lepo.i18n Core library - localization builder, provider, and YAML support
Lepo.i18n.DependencyInjection IServiceCollection integration with IStringLocalizer
Lepo.i18n.Json Load translations from embedded or external JSON files
Lepo.i18n.Wpf WPF markup extensions (StringLocalizer, PluralStringLocalizer)

API Reference

LocalizationBuilder Methods

Method Description
SetCulture(CultureInfo) Set the default culture
SetCulture(string) Set the default culture by name
AddLocalization(LocalizationSet) Add a localization set manually
FromResource<T>(CultureInfo) Load from embedded RESX resource
FromJson(path, CultureInfo) Load from an embedded JSON file
FromJson(assembly, path, CultureInfo) Load from a JSON file in a specific assembly
FromYaml(assembly, path, CultureInfo) Load from an embedded YAML file

WPF XAML Extensions

Extension Description
{i18n:StringLocalizer 'key'} Localize a string in XAML
{i18n:PluralStringLocalizer ...} Localize with singular/plural forms

Culture Management

Method Description
app.UseStringLocalizer(Action) Configure localizations for a WPF app
app.SetLocalizationCulture(CultureInfo) Change culture at runtime (WPF)
services.AddStringLocalizer(Action) Register localizations via DI
ILocalizationCultureManager.SetCulture() Change culture via DI service

Maintainers


Support

For support, please open a GitHub issue. We welcome bug reports, feature requests, and questions.


License

This project is licensed under the terms of the MIT open source license. Please refer to the LICENSE file for the full terms.

You can use it in private and commercial projects. Keep in mind that you must include a copy of the license in your project.

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 is compatible. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 is compatible.  net48 was computed.  net481 is compatible. 
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 (1)

Showing the top 1 popular GitHub repositories that depend on Lepo.i18n.DependencyInjection:

Repository Stars
lepoco/wpfui
WPF UI provides the Fluent experience in your known and loved WPF framework. Intuitive design, themes, navigation and new immersive controls. All natively and effortlessly.
Version Downloads Last Updated
2.1.0 90 3/2/2026
2.0.0 16,716 6/1/2024