LocalizedNeverConverter.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. namespace Ryujinx.Ava.UI.Helpers
  8. {
  9. /// <summary>
  10. /// 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.
  11. /// 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.
  12. /// </summary>
  13. // TODO: localize ValueFormatUtils.FormateDateTime
  14. internal class LocalizedNeverConverter : MarkupExtension, IValueConverter
  15. {
  16. private static readonly LocalizedNeverConverter _instance = new();
  17. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  18. {
  19. if (value is not string valStr)
  20. {
  21. return "";
  22. }
  23. if (valStr == "Never")
  24. {
  25. return LocaleManager.Instance[LocaleKeys.Never];
  26. }
  27. return valStr;
  28. }
  29. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  30. {
  31. throw new NotSupportedException();
  32. }
  33. public override object ProvideValue(IServiceProvider serviceProvider)
  34. {
  35. return _instance;
  36. }
  37. }
  38. }