mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-10-31 03:59:58 +01:00
LanguageManager
This commit is contained in:
33
StarterNG/Services/LocalizationService.cs
Normal file
33
StarterNG/Services/LocalizationService.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.ComponentModel;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Styling;
|
||||
|
||||
namespace StarterNG.Services;
|
||||
|
||||
public class LocalizationService : INotifyPropertyChanged
|
||||
{
|
||||
private IResourceProvider _currentProvider = new ResourceDictionary();
|
||||
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
|
||||
public string this[string key]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_currentProvider.TryGetResource(key, null, out var value))
|
||||
{
|
||||
return value?.ToString() ?? key;
|
||||
}
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetLanguage(IResourceProvider provider)
|
||||
{
|
||||
_currentProvider = provider;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Item"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user