LocalizedNeverConverter.cs
1 using Avalonia.Data.Converters; 2 using Avalonia.Markup.Xaml; 3 using Ryujinx.Ava.Common.Locale; 4 using Ryujinx.UI.Common.Helper; 5 using System; 6 using System.Globalization; 7 8 namespace Ryujinx.Ava.UI.Helpers 9 { 10 /// <summary> 11 /// This <see cref="IValueConverter"/> makes sure that the string "Never" that's returned by <see cref="ValueFormatUtils.FormatDateTime"/> is properly localized in the Avalonia UI. 12 /// After the Avalonia UI has been made the default and the GTK UI is removed, <see cref="ValueFormatUtils"/> should be updated to directly return a localized string. 13 /// </summary> 14 internal class LocalizedNeverConverter : MarkupExtension, IValueConverter 15 { 16 private static readonly LocalizedNeverConverter _instance = new(); 17 18 public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 19 { 20 if (value is not string valStr) 21 { 22 return ""; 23 } 24 25 if (valStr == "Never") 26 { 27 return LocaleManager.Instance[LocaleKeys.Never]; 28 } 29 30 return valStr; 31 } 32 33 public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 34 { 35 throw new NotSupportedException(); 36 } 37 38 public override object ProvideValue(IServiceProvider serviceProvider) 39 { 40 return _instance; 41 } 42 } 43 }