| 1 | #nullable enable |
| 2 | |
| 3 | using System.ComponentModel; |
| 4 | using System.Globalization; |
| 5 | using System.Reflection; |
| 6 | using System.Runtime.CompilerServices; |
| 7 | using System.Threading; |
| 8 | |
| 9 | namespace CascadeIDE.Lang; |
| 10 | |
| 11 | /// <summary> |
| 12 | /// Обёртка над <see cref="Resources"/> для смены языка в рантайме: привязки к свойствам |
| 13 | /// получают <see cref="INotifyPropertyChanged"/> после смены <see cref="Resources.Culture"/>. |
| 14 | /// </summary> |
| 15 | public sealed class LocViewModel : INotifyPropertyChanged |
| 16 | { |
| 17 | public static LocViewModel? Current { get; private set; } |
| 18 | |
| 19 | static readonly Lazy<PropertyInfo[]> StringPropertyCache = new(() => |
| 20 | typeof(LocViewModel) |
| 21 | .GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly) |
| 22 | .Where(p => p.PropertyType == typeof(string) && p.CanRead && p.GetIndexParameters().Length == 0) |
| 23 | .ToArray()); |
| 24 | |
| 25 | public LocViewModel() => Current = this; |
| 26 | |
| 27 | public event PropertyChangedEventHandler? PropertyChanged; |
| 28 | |
| 29 | void OnPropertyChanged([CallerMemberName] string? name = null) |
| 30 | { |
| 31 | if (name is not null) |
| 32 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); |
| 33 | } |
| 34 | |
| 35 | /// <summary>Установить культуру ресурсов и потока и уведомить все строковые свойства.</summary> |
| 36 | public void SetCulture(CultureInfo culture) |
| 37 | { |
| 38 | Resources.Culture = culture; |
| 39 | Thread.CurrentThread.CurrentUICulture = culture; |
| 40 | foreach (var p in StringPropertyCache.Value) |
| 41 | OnPropertyChanged(p.Name); |
| 42 | } |
| 43 | |
| 44 | public string ChatPanel_PlanHeader => Resources.ChatPanel_PlanHeader; |
| 45 | public string ChatPanel_PlanEmptyHint => Resources.ChatPanel_PlanEmptyHint; |
| 46 | public string ChatPanel_NextActionHeader => Resources.ChatPanel_NextActionHeader; |
| 47 | public string ChatPanel_AgentOpsHeader => Resources.ChatPanel_AgentOpsHeader; |
| 48 | public string ChatPanel_AgentOpsEmptyHint => Resources.ChatPanel_AgentOpsEmptyHint; |
| 49 | public string ChatPanel_ConfirmHeader => Resources.ChatPanel_ConfirmHeader; |
| 50 | public string ChatPanel_ConfirmHint => Resources.ChatPanel_ConfirmHint; |
| 51 | public string ChatPanel_ConfirmButton => Resources.ChatPanel_ConfirmButton; |
| 52 | public string ChatPanel_CancelButton => Resources.ChatPanel_CancelButton; |
| 53 | public string ChatPanel_ExplainStep => Resources.ChatPanel_ExplainStep; |
| 54 | public string ChatPanel_EmergencyStop => Resources.ChatPanel_EmergencyStop; |
| 55 | public string ChatPanel_TraceHeader => Resources.ChatPanel_TraceHeader; |
| 56 | public string ChatPanel_TraceEmptyHint => Resources.ChatPanel_TraceEmptyHint; |
| 57 | public string ChatPanel_TraceRollback => Resources.ChatPanel_TraceRollback; |
| 58 | public string ChatPanel_SafetyDockTitlePower => Resources.ChatPanel_SafetyDockTitlePower; |
| 59 | public string ChatPanel_SafetyTierObserve => Resources.ChatPanel_SafetyTierObserve; |
| 60 | public string ChatPanel_SafetyTierConfirm => Resources.ChatPanel_SafetyTierConfirm; |
| 61 | public string ChatPanel_SafetyTierAutonomous => Resources.ChatPanel_SafetyTierAutonomous; |
| 62 | public string ChatPanel_SafetyTierObserveSubtitle => Resources.ChatPanel_SafetyTierObserveSubtitle; |
| 63 | public string ChatPanel_SafetyTierConfirmSubtitle => Resources.ChatPanel_SafetyTierConfirmSubtitle; |
| 64 | public string ChatPanel_SafetyTierAutonomousSubtitle => Resources.ChatPanel_SafetyTierAutonomousSubtitle; |
| 65 | public string ChatPanel_SafetyCompactHeader => Resources.ChatPanel_SafetyCompactHeader; |
| 66 | public string ChatPanel_EmergencyStopCompact => Resources.ChatPanel_EmergencyStopCompact; |
| 67 | public string ChatPanel_ChatExpandButton => Resources.ChatPanel_ChatExpandButton; |
| 68 | public string ChatPanel_ChatExpandTooltip => Resources.ChatPanel_ChatExpandTooltip; |
| 69 | public string ChatPanel_ChatCollapseTooltip => Resources.ChatPanel_ChatCollapseTooltip; |
| 70 | public string ChatPanel_AgentTyping => Resources.ChatPanel_AgentTyping; |
| 71 | public string ChatPanel_NoMessagesYet => Resources.ChatPanel_NoMessagesYet; |
| 72 | public string ChatPanel_MessageWatermark => Resources.ChatPanel_MessageWatermark; |
| 73 | public string ChatPanel_SendButton => Resources.ChatPanel_SendButton; |
| 74 | public string PanelChrome_EmergencyStopCaps => Resources.PanelChrome_EmergencyStopCaps; |
| 75 | public string PanelChrome_OverflowActionsPlaceholder => Resources.PanelChrome_OverflowActionsPlaceholder; |
| 76 | public string PanelChrome_CopyTitle => Resources.PanelChrome_CopyTitle; |
| 77 | public string Lang_Menu_UiLanguage => Resources.Lang_Menu_UiLanguage; |
| 78 | public string Lang_Menu_Russian => Resources.Lang_Menu_Russian; |
| 79 | public string Lang_Menu_English => Resources.Lang_Menu_English; |
| 80 | public string Lang_Menu_FollowSystem => Resources.Lang_Menu_FollowSystem; |
| 81 | } |
| 82 | |