-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathLocalizedString.cs
More file actions
67 lines (46 loc) · 1.49 KB
/
LocalizedString.cs
File metadata and controls
67 lines (46 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System.Globalization;
namespace RayCarrot.RCP.Metro;
/// <summary>
/// A string wrapper which changes regenerates itself when the current culture changes
/// </summary>
public abstract class LocalizedString : BaseViewModel, IDisposable
{
#region Constructors
protected LocalizedString(bool refreshOnCultureChanged = true)
{
// Subscribe to when the culture changes
if (refreshOnCultureChanged)
CultureChangedWeakEventManager.AddHandler(Services.InstanceData, Data_CultureChanged);
}
#endregion
#region Public Properties
/// <summary>
/// The current string value
/// </summary>
public string Value { get; protected set; } = null!;
#endregion
#region Static Implicit Operators
public static implicit operator LocalizedString(string str) => new ConstLocString(str);
public static implicit operator string(LocalizedString str) => str.Value;
#endregion
#region Private Methods
private void Data_CultureChanged(object sender, PropertyChangedEventArgs<CultureInfo> e)
{
RefreshValue();
}
#endregion
#region Protected Methods
protected abstract string GetValue();
#endregion
#region Public Methods
public void RefreshValue()
{
Value = GetValue();
}
public override string ToString() => Value;
public void Dispose()
{
CultureChangedWeakEventManager.RemoveHandler(Services.InstanceData, Data_CultureChanged);
}
#endregion
}