Repository navigation
Expand file tree
/
Copy pathLocalizationConverter.cs
More file actions
executable file
·68 lines (58 loc) · 2.76 KB
/
Copy pathLocalizationConverter.cs
File metadata and controls
executable file
·68 lines (58 loc) · 2.76 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
//
// This is the source code of Telegram for Windows Phone v. 3.x.x.
// It is licensed under GNU GPL v. 2 or later.
// You should have received a copy of the license in this archive (see LICENSE).
//
// Copyright Evgeny Nadymov, 2013-present.
//
using System;
using System.Globalization;
using System.Windows.Data;
namespace TelegramClient.Resources
{
/// <summary>
/// Values that represent type of localized string.
/// </summary>
public enum StringType
{
Normal,
UpperCase,
LowerCase
}
/// <summary>
/// Localizes string from resources.
/// </summary>
public class LocalizationConverter : IValueConverter
{
public StringType Type { get; set; }
#region Implementation of IValueConverter
/// <summary>
/// Modifies the source data before passing it to the target for display in the UI.
/// </summary>
/// <returns>
/// The value to be passed to the target dependency property.
/// </returns>
/// <param name="value">The source data being passed to the target.</param><param name="targetType">The <see cref="T:System.Type"/> of data expected by the target dependency property.</param><param name="parameter">An optional parameter to be used in the converter logic.</param><param name="culture">The culture of the conversion.</param>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null) return null;
var localizedString = AppResources.ResourceManager.GetString(value.ToString());
if (localizedString == null) return null;
if (Type == StringType.UpperCase) return localizedString.ToUpper();
if (Type == StringType.LowerCase) return localizedString.ToLower();
return localizedString;
}
/// <summary>
/// Modifies the target data before passing it to the source object. This method is called only in <see cref="F:System.Windows.Data.BindingMode.TwoWay"/> bindings.
/// </summary>
/// <returns>
/// The value to be passed to the source object.
/// </returns>
/// <param name="value">The target data being passed to the source.</param><param name="targetType">The <see cref="T:System.Type"/> of data expected by the source object.</param><param name="parameter">An optional parameter to be used in the converter logic.</param><param name="culture">The culture of the conversion.</param>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
}