Cacx.LanguageManager
1.1.2
dotnet add package Cacx.LanguageManager --version 1.1.2
NuGet\Install-Package Cacx.LanguageManager -Version 1.1.2
<PackageReference Include="Cacx.LanguageManager" Version="1.1.2" />
<PackageVersion Include="Cacx.LanguageManager" Version="1.1.2" />
<PackageReference Include="Cacx.LanguageManager" />
paket add Cacx.LanguageManager --version 1.1.2
#r "nuget: Cacx.LanguageManager, 1.1.2"
#:package Cacx.LanguageManager@1.1.2
#addin nuget:?package=Cacx.LanguageManager&version=1.1.2
#tool nuget:?package=Cacx.LanguageManager&version=1.1.2
π Resource Manager π
This Manager was originally created to manage languages in my WPF applications. <br> It also works on other kind of resources tho.
π Lets go through a step by step tutorial on how to setup and use this library.
π Setup
Open the project terminal and type in dotnet add package Cacx.LanguageManager --version 1.1.1
π» Usage
Optional: <br>
Register the LocalizationService via DI <br> You can also implement your own LocalizationService and register it via the Interface
public App()
{
AppHost = Host.CreateDefaultBuilder().ConfigureServices((context, services) =>
{
_ = services.AddSingleton<ILocalizationService, LocalizationService>((_) =>
{
return new LocalizationService(basePath: "Some path...");
});
}.Build();
_ = AppHost.Services.GetRequiredService<ILocalizationService>(); //This call is needed! Just disregard the service
}
Step 1
β‘οΈ Get the ILocalizationService implementation
There a two ways to achieve this. <br>
Either get it from your DI Container
public ExampleCtor(ILocalizationService service)
{
}
or instanciate an ILocalizationService one time...
//Call this at the start of your application
public void Method()
{
_ = new LocalizationService("some random path...") //You dont have to use the instance instantly you can disregrad it for now
}
and use this property afterwards to get it...
public void SomeOtherMethod()
{
ILocalizationService service = LocalizationProvider.Service;
}
Step 2
π Set the Language
This will be CultureInfo.CurrentUICulture by default
public void Example()
{
CultureInfo language = new CultureInfo("en-US");
service.SetLanguage(language);
}
Step 3
πUpdate/Set the Context
Imagine you have this folder structure (which is recommended)
/// MyApp(Project)
/// ->Resources(Folder)
/// ->Login(Folder)
/// Login.resx
/// Login.de-DE.resx
/// ->CreateAccount(Folder)
/// CreateAccount.resx
/// CreateAccount.de-DE.resx
β‘οΈ Imagine you wanna access the Login resource
public void Example()
{
string basePath = "MyApp.Resources.Login.Login"; //"{ProjectName}.{Folder}.{Folder}.{Filename}"
service.UpdateContext(basePath);
}
You have to do this context switch to access the resources of another file!
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0-windows7.0 is compatible. |
-
net10.0-windows7.0
- Cacx.LanguageManager.Abstractions (>= 1.1.2)
- Cacx.LanguageManager.Core (>= 1.1.2)
- Cacx.LanguageManager.Wpf (>= 1.1.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.