LanguageManager

This commit is contained in:
2026-02-11 22:39:19 +01:00
parent 19a2ac8d59
commit a9c30bbdfe
8 changed files with 414 additions and 88 deletions

View 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"));
}
}