mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-07-17 17:09:19 +02:00
35 lines
820 B
C#
35 lines
820 B
C#
using System.ComponentModel;
|
|
using Avalonia.Controls;
|
|
|
|
namespace StarterNG.Services;
|
|
|
|
public class LocalizationService : INotifyPropertyChanged
|
|
{
|
|
private IResourceProvider _currentProvider = new ResourceDictionary();
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
|
|
public string CurrentLanguage;
|
|
|
|
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, string langName)
|
|
{
|
|
_currentProvider = provider;
|
|
CurrentLanguage = langName;
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Item"));
|
|
}
|
|
|
|
|
|
} |