39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Text;
|
|
using Microsoft.UI.Xaml.Data;
|
|
using Microsoft.UI.Xaml.Markup;
|
|
|
|
namespace WinWARP.Ui.Converters;
|
|
|
|
[MarkupExtensionReturnType(ReturnType = typeof(IValueConverter))]
|
|
public class LanguageCodeToNameConverter : MarkupExtension, IValueConverter
|
|
{
|
|
protected override object ProvideValue() => this;
|
|
|
|
public object Convert(object value, Type targetType, object parameter, string language)
|
|
{
|
|
if (value is string languageCode && !string.IsNullOrWhiteSpace(languageCode))
|
|
{
|
|
try
|
|
{
|
|
CultureInfo culture = new CultureInfo(languageCode);
|
|
|
|
// DisplayName returns "English (United States)"
|
|
// NativeName returns "English (United States)" or "Español (España)"
|
|
return culture.NativeName;
|
|
}
|
|
catch (CultureNotFoundException)
|
|
{
|
|
return value;
|
|
}
|
|
}
|
|
return string.Empty;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
} |