using AvParser.Core.Parsing; using AvParser.UI.Localization; using ReactiveUI; namespace AvParser.UI.ViewModels; /// One row of the collect error list, with its message translated. /// /// Sources and the fetcher are part of the domain and produce English text plus a code. This resolves /// Collect.Error.{Code} and falls back to the domain's own wording, so a code that has not /// been translated yet still says something useful instead of showing a missing-key marker. /// public sealed class CollectErrorViewModel(ParseError error) : ReactiveObject { /// The underlying error. public ParseError Error { get; } = error ?? throw new ArgumentNullException(nameof(error)); /// 1-based position of the offending item: a pasted line, or a place in a listing. public int Index => Error.Index; /// Translated message. public string Text { get { if (Error.Code is not { Length: > 0 } code) { return Error.Message; } var template = Localizer.Instance.GetOrDefault($"Collect.Error.{code}", Error.Message); return Error.Arguments.Count == 0 ? template : string.Format(Localizer.Instance.Culture, template, [.. Error.Arguments]); } } /// Re-reads the translated message. public void Refresh() => this.RaisePropertyChanged(nameof(Text)); }