added multilang and settings

This commit is contained in:
2026-08-08 21:48:16 +05:00
parent 3d614255d8
commit d146fd442a
18 changed files with 1115 additions and 72 deletions
@@ -0,0 +1,46 @@
using System.Globalization;
using System.Resources;
using System.Windows.Data;
using CommunityToolkit.Mvvm.ComponentModel;
namespace CursorLang.Services;
/// <summary>
/// Берёт строки из ресурсов и при смене языка просит WPF перечитать все привязки.
/// </summary>
public sealed class LocalizationService : ObservableObject, ILocalizationService
{
private static readonly ResourceManager Resources =
new("CursorLang.Resources.Strings", typeof(App).Assembly);
private CultureInfo _culture = CultureInfo.GetCultureInfo("en");
public string this[string key] => Resources.GetString(key, _culture) ?? key;
public IReadOnlyList<LanguageOption> AvailableLanguages { get; } =
[
new LanguageOption("en", "English"),
new LanguageOption("ru", "Русский"),
];
public string CurrentLanguage
{
get => _culture.TwoLetterISOLanguageName;
set
{
if (string.IsNullOrWhiteSpace(value) || value == CurrentLanguage)
{
return;
}
_culture = CultureInfo.GetCultureInfo(value);
CultureInfo.CurrentUICulture = _culture;
OnPropertyChanged(nameof(CurrentLanguage));
// Сообщаем об изменении индексатора: так обновляются все привязки
// вида {Binding Localization[Key]}, то есть весь текст интерфейса
OnPropertyChanged(Binding.IndexerName);
}
}
}