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

@@ -1,8 +1,10 @@
using System;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Markup.Xaml;
using Avalonia.Markup.Xaml.Styling;
namespace StarterNG.Views;
@@ -45,4 +47,28 @@ public partial class Settings : UserControl
int resolution = 1 << (int)shaderResolutionSlider.Value;
shaderResolution.Text = $"{resolution} px";
}
private void LanguageComboBox_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
{
if (sender is not ComboBox { SelectedItem: ComboBoxItem item }) return;
var lang = item.Content?.ToString();
if (string.IsNullOrEmpty(lang)) return;
var langDict = new ResourceInclude(new Uri("avares://StarterNG/"))
{
Source = new Uri($"Assets/Langs/{lang}.axaml", UriKind.Relative)
};
var currentLangDict = App.Current.Resources.MergedDictionaries
.OfType<ResourceInclude>()
.FirstOrDefault(d => d.Source != null && d.Source.OriginalString.Contains("Langs/"));
if (currentLangDict != null)
{
App.Current.Resources.MergedDictionaries.Remove(currentLangDict);
}
App.Current.Resources.MergedDictionaries.Add(langDict);
App.Loc.SetLanguage(langDict);
}
}