Add an option to chose the language of the application

This commit is contained in:
Tichau committed 2016-06-14 19:25:53 +02:00
1 parent 342c828721
commit b02da10dbc
6 files changed
+135 -10

No files matched your search

@@ -107,14 +107,14 @@
<Compile Include="Diagnostics\DiagnosticsData.cs" />
<Compile Include="Controls\EncodingMode.cs" />
<Compile Include="ConversionPreset\IConversionSettings.cs" />
<Compile Include="Helpers.cs" />
<Compile Include="InputPostConversionAction.cs" />
<Compile Include="IXmlSerializable.cs" />
<Compile Include="PathHelpers.cs" />
<Compile Include="Properties\Resources.en.Designer.cs">
<DependentUpon>Resources.en.resx</DependentUpon>
<Compile Include="Properties\Resources.fr1.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<ExcludeFromStyleCop>True</ExcludeFromStyleCop>
<DependentUpon>Resources.fr.resx</DependentUpon>
</Compile>
<Compile Include="Registry.cs" />
<Compile Include="Settings.Settings.cs" />
@@ -210,9 +210,9 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<EmbeddedResource Include="Properties\Resources.en.resx">
<EmbeddedResource Include="Properties\Resources.fr.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.en.Designer.cs</LastGenOutput>
<LastGenOutput>Resources.fr1.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
+26
View File
@@ -0,0 +1,26 @@
// // <copyright file="Helpers.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
namespace FileConverter
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
public static class Helpers
{
public static IEnumerable<CultureInfo> GetSupportedCulture()
{
//Get all culture
CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
//Find the location where application installed.
string exeLocation = Path.GetDirectoryName(Uri.UnescapeDataString(new UriBuilder(Assembly.GetExecutingAssembly().CodeBase).Path));
//Return all culture for which satellite folder found with culture code.
return cultures.Where(cultureInfo => Directory.Exists(Path.Combine(exeLocation, cultureInfo.Name)));
}
}
}
@@ -296,7 +296,7 @@ Special paths:
<value>See change log ...</value>
</data>
<data name="Settings" xml:space="preserve">
<value>Settings</value>
<value>Paramètres</value>
</data>
<data name="SettingsButtonTitle" xml:space="preserve">
<value>Settings</value>
@@ -1,5 +1,9 @@
// <copyright file="Settings.Settings.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
using System.Globalization;
using System.Windows;
using System.Windows.Markup;
namespace FileConverter
{
using System.Collections.ObjectModel;
@@ -14,6 +18,7 @@ namespace FileConverter
private float durationBetweenEndOfConversionsAndApplicationExit = 3f;
private ObservableCollection<ConversionPreset> conversionPresets = new ObservableCollection<ConversionPreset>();
private bool checkUpgradeAtStartup = true;
private CultureInfo applicationLanguage;
[XmlAttribute]
public int SerializationVersion
@@ -22,6 +27,57 @@ namespace FileConverter
set;
} = Version;
[XmlIgnore]
public CultureInfo ApplicationLanguage
{
get
{
return this.applicationLanguage;
}
set
{
if (this.applicationLanguage != null && this.applicationLanguage.Equals(value))
{
return;
}
this.applicationLanguage = value;
if (this.applicationLanguage != null)
{
System.Threading.Thread.CurrentThread.CurrentCulture = this.applicationLanguage;
System.Threading.Thread.CurrentThread.CurrentUICulture = this.applicationLanguage;
}
this.OnPropertyChanged();
}
}
[XmlElement]
public string ApplicationLanguageName
{
get
{
if (this.ApplicationLanguage == null)
{
return string.Empty;
}
return this.ApplicationLanguage.Name;
}
set
{
if (string.IsNullOrEmpty(value))
{
this.ApplicationLanguage = null;
return;
}
this.ApplicationLanguage = CultureInfo.GetCultureInfo(value);
}
}
[XmlIgnore]
public ObservableCollection<ConversionPreset> ConversionPresets
{
@@ -107,6 +163,35 @@ namespace FileConverter
{
this.ConversionPresets[index].OnDeserializationComplete();
}
// Initialize application if it was not deserialized from the settings.
if (this.ApplicationLanguage == null)
{
CultureInfo bestCandidate = null;
CultureInfo currentUICulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
foreach (CultureInfo culture in Helpers.GetSupportedCulture())
{
if (culture.Equals(currentUICulture))
{
bestCandidate = culture;
break;
}
else if (culture.Equals(currentUICulture.Parent))
{
bestCandidate = culture;
}
}
if (bestCandidate != null)
{
this.ApplicationLanguage = bestCandidate;
}
else
{
Diagnostics.Debug.Log("Can't find supported culture info for culture {0}. Fallback to default culture.", currentUICulture);
this.ApplicationLanguage = CultureInfo.GetCultureInfo("en");
}
}
}
}
}
@@ -755,6 +755,11 @@
<!-- Application settings -->
<TabItem Header="{x:Static project:Resources.Application}">
<StackPanel Margin="5,10,5,5">
<StackPanel Orientation="Horizontal" Margin="0,0,0,10">
<Label Content="Language :"/>
<ComboBox Name="LanguageComboBox" SelectedValue="{Binding ApplicationSettings.ApplicationLanguage, ElementName=window, Mode=TwoWay}"/>
</StackPanel>
<CheckBox x:Name="QuitAtEndCheckBox" Content="{x:Static project:Resources.AutomaticallyExitWhenAllConversionsFinished}" IsChecked="{Binding ApplicationSettings.ExitApplicationWhenConversionsFinished, ElementName=window, Mode=TwoWay}" Margin="0,0,0,5" />
<DockPanel Margin="40,0,0,5" Visibility="{Binding IsChecked, Converter={StaticResource BoolToVisibility}, ConverterParameter=Collapsed, ElementName=QuitAtEndCheckBox}">
<Label Content="Waiting duration :"/>
@@ -1,10 +1,12 @@
// <copyright file="SettingsWindow.xaml.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
namespace FileConverter
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Windows;
@@ -13,7 +15,6 @@ namespace FileConverter
using FileConverter.Annotations;
using FileConverter.Commands;
using FileConverter.Upgrade;
using Microsoft.Win32;
/// <summary>
@@ -69,11 +70,19 @@ 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;
public event System.EventHandler<System.EventArgs> OnSettingsWindowHide;
public event EventHandler<EventArgs> OnSettingsWindowHide;
public ICommand OpenUrlCommand
{
@@ -190,7 +199,7 @@ namespace FileConverter
this.OnPropertyChanged();
}
}
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
@@ -200,7 +209,7 @@ namespace FileConverter
private void DownloadChangeLogAction()
{
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
Helpers.GetChangeLogAsync(new UpgradeVersionDescription(), this.OnChangeLogRetrieved);
Upgrade.Helpers.GetChangeLogAsync(new UpgradeVersionDescription(), this.OnChangeLogRetrieved);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
this.AboutSectionContent = "###Downloading change log ...";
this.DisplaySeeChangeLogLink = false;