-
-
Notifications
You must be signed in to change notification settings - Fork 132
Expand file tree
/
Copy pathCompatibility.cs
More file actions
335 lines (294 loc) · 11.5 KB
/
Copy pathCompatibility.cs
File metadata and controls
335 lines (294 loc) · 11.5 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
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#region Copyright information
// <copyright file="Compatibility.cs">
// Licensed under Microsoft Public License (Ms-PL)
// https://github.com/XAMLMarkupExtensions/WPFLocalizationExtension/blob/master/LICENSE
// </copyright>
// <author>Bernhard Millauer</author>
// <author>Uwe Mayer</author>
#endregion
namespace WPFLocalizeExtension.Deprecated.Extensions
{
#region Usings
using System;
using System.Windows.Markup;
using WPFLocalizeExtension.Engine;
using WPFLocalizeExtension.Extensions;
using XAMLMarkupExtensions.Base;
#endregion
/// <inheritdoc/>
[Obsolete("LocBrushExtension is deprecated and will be removed in version 4.0, please use lex:Loc instead and see documentation", false)]
[MarkupExtensionReturnType(typeof(System.Windows.Media.Brush))]
public class LocBrushExtension : LocBaseExtension
{
/// <inheritdoc/>
public LocBrushExtension()
{ }
/// <inheritdoc/>
public LocBrushExtension(string key) : base(key) { }
}
/// <inheritdoc/>
[Obsolete("LocDoubleExtension is deprecated and will be removed in version 4.0, please use lex:Loc instead and see documentation", false)]
[MarkupExtensionReturnType(typeof(double))]
public class LocDoubleExtension : LocBaseExtension
{
/// <inheritdoc/>
public LocDoubleExtension()
{ }
/// <inheritdoc/>
public LocDoubleExtension(string key) : base(key) { }
}
/// <inheritdoc/>
[MarkupExtensionReturnType(typeof(System.Windows.FlowDirection))]
[Obsolete("LocFlowDirectionExtension is deprecated and will be removed in version 4.0, please use lex:Loc instead and see documentation", false)]
public class LocFlowDirectionExtension : LocBaseExtension
{
/// <inheritdoc/>
public LocFlowDirectionExtension()
{ }
/// <inheritdoc/>
public LocFlowDirectionExtension(string key) : base(key) { }
}
/// <inheritdoc/>
[MarkupExtensionReturnType(typeof(System.Windows.Media.Imaging.BitmapSource))]
[Obsolete("LocImageExtension is deprecated and will be removed in version 4.0, please use lex:Loc instead and see documentation", false)]
public class LocImageExtension : LocBaseExtension
{
/// <inheritdoc/>
public LocImageExtension()
{ }
/// <inheritdoc/>
public LocImageExtension(string key) : base(key) { }
}
/// <inheritdoc/>
[MarkupExtensionReturnType(typeof(string))]
[Obsolete("LocTextExtension is deprecated and will be removed in version 4.0, please use lex:Loc instead and see documentation", false)]
public class LocTextExtension : LocBaseExtension
{
#region Constructors
/// <inheritdoc/>
public LocTextExtension()
{ }
/// <inheritdoc/>
public LocTextExtension(string key) : base(key) { }
#endregion
#region Enum Definition
/// <summary>
/// This enumeration is used to determine the type
/// of the return value of <see cref="GetAppendText"/>
/// </summary>
protected enum TextAppendType
{
/// <summary>
/// The return value is used as prefix
/// </summary>
Prefix,
/// <summary>
/// The return value is used as suffix
/// </summary>
Suffix
}
#endregion
#region Variables
/// <summary>
/// Holds the local prefix value
/// </summary>
private string _prefix;
/// <summary>
/// Holds the local suffix value
/// </summary>
private string _suffix;
/// <summary>
/// Holds the local format segment array
/// </summary>
private readonly string[] _formatSegments = new string[5];
#endregion
#region Properties
/// <summary>
/// Gets or sets a prefix for the localized text
/// </summary>
public string Prefix
{
get => _prefix;
set => _prefix = value;
}
/// <summary>
/// Gets or sets a suffix for the localized text
/// </summary>
public string Suffix
{
get => _suffix;
set => _suffix = value;
}
/// <summary>
/// Gets or sets the format segment 1.
/// This will be used to replace format place holders from the localized text.
/// <see cref="LocTextLowerExtension"/> and <see cref="LocTextUpperExtension"/> will format this segment.
/// </summary>
/// <value>The format segment 1.</value>
public string FormatSegment1
{
get => _formatSegments[0];
set => _formatSegments[0] = value;
}
/// <summary>
/// Gets or sets the format segment 2.
/// This will be used to replace format place holders from the localized text.
/// <see cref="LocTextUpperExtension"/> and <see cref="LocTextLowerExtension"/> will format this segment.
/// </summary>
/// <value>The format segment 2.</value>
public string FormatSegment2
{
get => _formatSegments[1];
set => _formatSegments[1] = value;
}
/// <summary>
/// Gets or sets the format segment 3.
/// This will be used to replace format place holders from the localized text.
/// <see cref="LocTextUpperExtension"/> and <see cref="LocTextLowerExtension"/> will format this segment.
/// </summary>
/// <value>The format segment 3.</value>
public string FormatSegment3
{
get => _formatSegments[2];
set => _formatSegments[2] = value;
}
/// <summary>
/// Gets or sets the format segment 4.
/// This will be used to replace format place holders from the localized text.
/// <see cref="LocTextUpperExtension"/> and <see cref="LocTextLowerExtension"/> will format this segment.
/// </summary>
/// <value>The format segment 4.</value>
public string FormatSegment4
{
get => _formatSegments[3];
set => _formatSegments[3] = value;
}
/// <summary>
/// Gets or sets the format segment 5.
/// This will be used to replace format place holders from the localized text.
/// <see cref="LocTextUpperExtension"/> and <see cref="LocTextLowerExtension"/> will format this segment.
/// </summary>
/// <value>The format segment 5.</value>
public string FormatSegment5
{
get => _formatSegments[4];
set => _formatSegments[4] = value;
}
#endregion
#region Text Formatting
/// <summary>
/// Returns the prefix or suffix text, depending on the supplied <see cref="TextAppendType"/>.
/// If the prefix or suffix is null, it will be returned a string.empty.
/// </summary>
/// <param name="at">The <see cref="TextAppendType"/> defines the format of the return value</param>
/// <returns>Returns the formated prefix or suffix</returns>
private string GetAppendText(TextAppendType at)
{
// define a return value
var retVal = string.Empty;
// check if it should be a prefix, the format will be [PREFIX],
// or check if it should be a suffix, the format will be [SUFFIX]
if (at == TextAppendType.Prefix && !string.IsNullOrEmpty(_prefix))
{
retVal = _prefix ?? string.Empty;
}
else if (at == TextAppendType.Suffix && !string.IsNullOrEmpty(_suffix))
{
retVal = _suffix ?? string.Empty;
}
// return the formated prefix or suffix
return retVal;
}
/// <summary>
/// This method formats the localized text.
/// If the passed target text is null, string.empty will be returned.
/// </summary>
/// <param name="target">The text to format.</param>
/// <returns>Returns the formated text or string.empty, if the target text was null.</returns>
protected virtual string FormatText(string target)
{
return target ?? string.Empty;
}
/// <inheritdoc/>
public override object FormatOutput(TargetInfo endPoint, TargetInfo info)
{
var textMain = base.FormatOutput(endPoint, info) as string ?? string.Empty;
try
{
// add some format segments, in case that the main text contains format place holders like {0}
textMain = string.Format(
LocalizeDictionary.Instance.SpecificCulture,
textMain,
_formatSegments[0] ?? string.Empty,
_formatSegments[1] ?? string.Empty,
_formatSegments[2] ?? string.Empty,
_formatSegments[3] ?? string.Empty,
_formatSegments[4] ?? string.Empty);
}
catch (FormatException)
{
// if a format exception was thrown, change the text to an error string
textMain = "TextFormatError: Max 5 Format PlaceHolders! {0} to {4}";
}
// get the prefix
var textPrefix = GetAppendText(TextAppendType.Prefix);
// get the suffix
var textSuffix = GetAppendText(TextAppendType.Suffix);
// format the text with prefix and suffix to [PREFIX]LocalizedText[SUFFIX]
textMain = FormatText(textPrefix + textMain + textSuffix);
return textMain;
}
#endregion
}
/// <inheritdoc/>
[MarkupExtensionReturnType(typeof(string))]
[Obsolete("LocTextLowerExtension is deprecated and will be removed in version 4.0, please use lex:Loc instead and see documentation", false)]
public class LocTextLowerExtension : LocTextExtension
{
#region Constructors
/// <inheritdoc/>
public LocTextLowerExtension()
{ }
/// <inheritdoc/>
public LocTextLowerExtension(string key) : base(key) { }
#endregion
#region Text Formatting
/// <inheritdoc/>
protected override string FormatText(string target)
{
return target?.ToLower(GetForcedCultureOrDefault()) ?? string.Empty;
}
#endregion
}
/// <inheritdoc/>
[MarkupExtensionReturnType(typeof(string))]
[Obsolete("LocTextUpperExtension is deprecated and will be removed in version 4.0, please use lex:Loc instead and see documentation", false)]
public class LocTextUpperExtension : LocTextExtension
{
#region Constructors
/// <inheritdoc/>
public LocTextUpperExtension()
{ }
/// <inheritdoc/>
public LocTextUpperExtension(string key) : base(key) { }
#endregion
#region Text Formatting
/// <inheritdoc/>
protected override string FormatText(string target)
{
return target?.ToUpper(GetForcedCultureOrDefault()) ?? string.Empty;
}
#endregion
}
/// <inheritdoc/>
[MarkupExtensionReturnType(typeof(System.Windows.Thickness))]
[Obsolete("LocThicknessExtension is deprecated and will be removed in version 4.0, please use lex:Loc instead and see documentation", false)]
public class LocThicknessExtension : LocBaseExtension
{
/// <inheritdoc/>
public LocThicknessExtension()
{ }
/// <inheritdoc/>
public LocThicknessExtension(string key) : base(key) { }
}
}