-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathTranslation.cs
196 lines (170 loc) · 3.42 KB
/
Translation.cs
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
using System;
using System.ComponentModel;
using System.Xml.Serialization;
namespace PoeStrings
{
[Serializable]
public class Translation : INotifyPropertyChanged
{
private const int TruncationLength = 25;
public enum TranslationStatus
{
Invalid,
Ignore,
NeedToApply,
AlreadyApplied,
}
private static string TruncateString(string source, int truncationLength)
{
if (source == null)
return string.Empty;
return (source.Length < truncationLength ? source : source.Substring(0, truncationLength - 3) + "...").Replace(Environment.NewLine, "");
}
[XmlIgnore]
public string ShortNameOriginal
{
get
{
if (_shortNameOriginal == null)
_shortNameOriginal = TruncateString(OriginalText, TruncationLength);
return _shortNameOriginal;
}
}
private string _shortNameOriginal;
[XmlIgnore]
public string ShortNameCurrent
{
get
{
if (_shortNameCurrent == null)
_shortNameCurrent = TruncateString(CurrentText, TruncationLength);
return _shortNameCurrent;
}
}
private string _shortNameCurrent;
[XmlIgnore]
public string ShortNameTranslated
{
get
{
if (_shortNameTranslated == null)
_shortNameTranslated = TruncateString(TranslatedText, TruncationLength);
return _shortNameTranslated;
}
}
private string _shortNameTranslated;
[XmlIgnore]
public string Colour
{
get
{
switch (Status)
{
case TranslationStatus.Invalid:
return "Red";
case TranslationStatus.NeedToApply:
return "LimeGreen";
case TranslationStatus.AlreadyApplied:
return "Goldenrod";
case TranslationStatus.Ignore:
return "Gray";
}
throw new ArgumentOutOfRangeException("Colour.get: Invalid Status of translation");
}
}
[XmlIgnore]
public string FontStyle
{
get
{
if (Status == TranslationStatus.Ignore)
return "Normal";
return "Bold";
}
}
[XmlIgnore]
public string CurrentText
{
get
{
return _currentText;
}
set
{
_currentText = value;
}
}
private string _currentText;
[XmlIgnore]
public TranslationStatus Status
{
get
{
return _status;
}
set
{
_status = value;
OnPropertyChange("Colour");
OnPropertyChange("Status");
}
}
private TranslationStatus _status;
public string OriginalText
{
get
{
return _originalText;
}
set
{
_originalText = value;
}
}
private string _originalText;
public string TranslatedText
{
get
{
return _translatedText;
}
set
{
_translatedText = value;
if (string.IsNullOrEmpty(_translatedText))
{
Status = TranslationStatus.Ignore;
}
else if (_translatedText != string.Empty && CurrentText != _translatedText)
{
Status = TranslationStatus.NeedToApply;
}
}
}
private string _translatedText;
public Translation()
{
}
public Translation(string originalString)
{
this.OriginalText = originalString;
this.CurrentText = originalString;
this.TranslatedText = null;
this.Status = TranslationStatus.Ignore;
}
public override string ToString()
{
return CurrentText;
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChange(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
}
}