1using System.ComponentModel;
2using System.Globalization;
12 private readonly Dictionary<string, string> byLang =
new(StringComparer.OrdinalIgnoreCase);
13 private string? primaryText;
14 private string? primaryLanguage;
19 public bool HasAny => this.byLang.Count > 0;
26 public void Add(
string Lang,
string Value)
28 if (this.primaryText is
null && !
string.IsNullOrWhiteSpace(Value) && !this.byLang.ContainsKey(Lang))
30 this.primaryText = Value;
31 this.primaryLanguage = Lang;
33 this.byLang[Lang] = Value;
43 public string?
Get(
string? Lang)
45 if (Lang is not
null && this.byLang.TryGetValue(Lang, out
string? V))
return V;
46 if (this.byLang.TryGetValue(
"en", out
string? Ev))
return Ev;
47 return this.byLang.Values.FirstOrDefault();
57 string Current = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
58 return this.
Get(Current) ??
string.Empty;
65 public string?
PrimaryText => this.primaryText ?? this.byLang.Values.FirstOrDefault();
72 public event PropertyChangedEventHandler? PropertyChanged;
79 this.PropertyChanged?.Invoke(
this,
new PropertyChangedEventArgs(Name));
Represents a set of localized strings, addressable by language code (e.g. "en", "sv").
string? Get(string? Lang)
Gets a localized value for a specific language.
string? PrimaryText
Gets the first localized text that was added, regardless of current culture.
void Add(string Lang, string Value)
Adds or replaces a localized text value.
string Text
Gets the localized text for the current UI culture, or an appropriate fallback.
void OnPropertyChanged(string Name)
Raises the PropertyChanged event.
string? PrimaryLanguage
Gets the language code associated with PrimaryText, if available.
bool HasAny
Gets a value indicating whether any localized strings have been added.