A language switch re-read computed properties only: the job bar of a running job,
the Jobs rows, the editor's chart legends and summaries, Auto chips, markers and
info line, the Archive figures and the Import session table kept the old language
until their next change. LocalizedViewModel gains OnLanguageChanged, where each of
them makes those texts again.
Meta lines joined their fields with a plain " · ": in Arabic or Hebrew a number
after a Latin field ("Canon EOS R5 · 2 h") joined the Latin run and split its own
field. Loc.Separator puts right-to-left marks around the dot in right-to-left
languages and is used for every such line. Desktop file sizes use the Common.Size
formats, as the Setup and the Uploader do.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
46 lines
1.7 KiB
C#
46 lines
1.7 KiB
C#
using System.ComponentModel;
|
|
using System.Runtime.CompilerServices;
|
|
using Titano.Core.Localization;
|
|
|
|
namespace Titano.Ui.Mvvm;
|
|
|
|
/// <summary>Minimal INotifyPropertyChanged base.</summary>
|
|
public abstract class ObservableObject : INotifyPropertyChanged
|
|
{
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
protected bool Set<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
|
|
{
|
|
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
|
|
field = value;
|
|
OnPropertyChanged(propertyName);
|
|
return true;
|
|
}
|
|
|
|
protected void OnPropertyChanged([CallerMemberName] string? propertyName = null) =>
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
/// <summary>Signals that every property changed (used after a culture switch).</summary>
|
|
protected void OnAllPropertiesChanged() => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(string.Empty));
|
|
}
|
|
|
|
/// <summary>View model whose computed, localized texts refresh when the UI language changes.</summary>
|
|
public abstract class LocalizedViewModel : ObservableObject, IDisposable
|
|
{
|
|
protected LocalizedViewModel() => Loc.CultureChanged += OnCultureChanged;
|
|
|
|
public virtual void Dispose()
|
|
{
|
|
Loc.CultureChanged -= OnCultureChanged;
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
private void OnCultureChanged(object? sender, EventArgs e) => OnLanguageChanged();
|
|
|
|
/// <summary>
|
|
/// The UI language changed: every property is read again. A view model that keeps texts in objects (chart series
|
|
/// and legends, rows, cached sentences) builds them again here, then calls the base.
|
|
/// </summary>
|
|
protected virtual void OnLanguageChanged() => OnAllPropertiesChanged();
|
|
}
|