From 2fd8d86aa13c3164ddbb062273de3bc65681dfdd Mon Sep 17 00:00:00 2001 From: Tichau Date: Wed, 15 Jun 2016 08:39:43 +0200 Subject: [PATCH] Display supported cultures in their native names. --- .../FileConverter/FileConverter.csproj | 1 + Application/FileConverter/Helpers.cs | 2 +- .../FileConverter/Settings.Settings.cs | 2 +- .../Generic/CultureInfoToStringConverter.cs | 38 +++++++++++++++++++ .../FileConverter/Windows/SettingsWindow.xaml | 10 ++++- .../Windows/SettingsWindow.xaml.cs | 18 ++++----- 6 files changed, 59 insertions(+), 12 deletions(-) create mode 100644 Application/FileConverter/ValueConverters/Generic/CultureInfoToStringConverter.cs diff --git a/Application/FileConverter/FileConverter.csproj b/Application/FileConverter/FileConverter.csproj index 7dd801f..fbc9ebb 100644 --- a/Application/FileConverter/FileConverter.csproj +++ b/Application/FileConverter/FileConverter.csproj @@ -124,6 +124,7 @@ + diff --git a/Application/FileConverter/Helpers.cs b/Application/FileConverter/Helpers.cs index eee12f3..c0250c4 100644 --- a/Application/FileConverter/Helpers.cs +++ b/Application/FileConverter/Helpers.cs @@ -11,7 +11,7 @@ namespace FileConverter public static class Helpers { - public static IEnumerable GetSupportedCulture() + public static IEnumerable GetSupportedCultures() { //Get all culture CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures); diff --git a/Application/FileConverter/Settings.Settings.cs b/Application/FileConverter/Settings.Settings.cs index 3084a4c..9890605 100644 --- a/Application/FileConverter/Settings.Settings.cs +++ b/Application/FileConverter/Settings.Settings.cs @@ -169,7 +169,7 @@ namespace FileConverter { CultureInfo bestCandidate = null; CultureInfo currentUICulture = System.Threading.Thread.CurrentThread.CurrentUICulture; - foreach (CultureInfo culture in Helpers.GetSupportedCulture()) + foreach (CultureInfo culture in Helpers.GetSupportedCultures()) { if (culture.Equals(currentUICulture)) { diff --git a/Application/FileConverter/ValueConverters/Generic/CultureInfoToStringConverter.cs b/Application/FileConverter/ValueConverters/Generic/CultureInfoToStringConverter.cs new file mode 100644 index 0000000..76798ba --- /dev/null +++ b/Application/FileConverter/ValueConverters/Generic/CultureInfoToStringConverter.cs @@ -0,0 +1,38 @@ +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. + +namespace FileConverter.ValueConverters.Generic +{ + using System; + using System.Globalization; + using System.Windows.Data; + + public class CultureInfoToStringConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + CultureInfo cultureInfo = value as CultureInfo; + if (cultureInfo == null) + { + throw new System.ArgumentException("The object must be a culture info instance."); + } + + string nativeName = cultureInfo.NativeName; + if (string.IsNullOrEmpty(nativeName)) + { + return cultureInfo.Name; + } + + if (nativeName.Length == 1) + { + return nativeName.ToUpper(cultureInfo); + } + + return nativeName.Substring(0, 1).ToUpper(cultureInfo) + nativeName.Substring(1, nativeName.Length - 1); ; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Application/FileConverter/Windows/SettingsWindow.xaml b/Application/FileConverter/Windows/SettingsWindow.xaml index 502e6db..f4c4043 100644 --- a/Application/FileConverter/Windows/SettingsWindow.xaml +++ b/Application/FileConverter/Windows/SettingsWindow.xaml @@ -83,6 +83,7 @@ + @@ -757,7 +758,14 @@ diff --git a/Application/FileConverter/Windows/SettingsWindow.xaml.cs b/Application/FileConverter/Windows/SettingsWindow.xaml.cs index ad241a2..8e1111c 100644 --- a/Application/FileConverter/Windows/SettingsWindow.xaml.cs +++ b/Application/FileConverter/Windows/SettingsWindow.xaml.cs @@ -32,9 +32,11 @@ namespace FileConverter private OpenUrlCommand openUrlCommand; private DelegateCommand getChangeLogContentCommand; private bool displaySeeChangeLogLink = true; - + public SettingsWindow() { + this.SupportedCultures = Helpers.GetSupportedCultures().Where(cultureInfo => cultureInfo.IsNeutralCulture).ToArray(); + this.InitializeComponent(); Application application = Application.Current as Application; @@ -70,14 +72,6 @@ namespace FileConverter this.PostConversionActionComboBox.ItemsSource = postConversionActions; this.InitializeCompatibleInputExtensions(); - - foreach (CultureInfo cultureInfo in Helpers.GetSupportedCulture()) - { - if (cultureInfo.IsNeutralCulture) - { - this.LanguageComboBox.Items.Add(cultureInfo); - } - } } public event PropertyChangedEventHandler PropertyChanged; @@ -170,6 +164,12 @@ namespace FileConverter } } + public CultureInfo[] SupportedCultures + { + get; + set; + } + public string AboutSectionContent { get