Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
KycLocalizedText.cs
1using System.ComponentModel;
2using System.Globalization;
3using System.Linq;
4
6{
10 public class KycLocalizedText : INotifyPropertyChanged
11 {
12 private readonly Dictionary<string, string> byLang = new(StringComparer.OrdinalIgnoreCase);
13 private string? primaryText;
14 private string? primaryLanguage;
15
19 public bool HasAny => this.byLang.Count > 0;
20
26 public void Add(string Lang, string Value)
27 {
28 if (this.primaryText is null && !string.IsNullOrWhiteSpace(Value) && !this.byLang.ContainsKey(Lang))
29 {
30 this.primaryText = Value;
31 this.primaryLanguage = Lang;
32 }
33 this.byLang[Lang] = Value;
34 this.OnPropertyChanged(nameof(this.Text));
35 this.OnPropertyChanged(nameof(this.PrimaryText));
36 }
37
43 public string? Get(string? Lang)
44 {
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();
48 }
49
53 public string Text
54 {
55 get
56 {
57 string Current = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
58 return this.Get(Current) ?? string.Empty;
59 }
60 }
61
65 public string? PrimaryText => this.primaryText ?? this.byLang.Values.FirstOrDefault();
66
70 public string? PrimaryLanguage => this.primaryLanguage;
71
72 public event PropertyChangedEventHandler? PropertyChanged;
77 protected void OnPropertyChanged(string Name)
78 {
79 this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(Name));
80 }
81 }
82}
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.