From a8ee39c58acc636347b949bd61bab68f559403d3 Mon Sep 17 00:00:00 2001 From: Lesueur Benjamin Date: Tue, 3 May 2022 20:53:43 +0200 Subject: [PATCH] implement language setting (#136) --- HandheldCompanion/App.xaml.cs | 19 +++++++ .../Properties/Resources.Designer.cs | 36 +++++++++++++ .../Properties/Resources.fr.resx | 52 +++++++++---------- HandheldCompanion/Properties/Resources.resx | 26 +++++----- .../Properties/Settings.Designer.cs | 14 ++++- .../Properties/Settings.settings | 3 ++ .../Views/Pages/SettingsPage.xaml | 39 ++++++++++---- .../Views/Pages/SettingsPage.xaml.cs | 49 +++++++++++++++++ .../Views/Windows/MainWindow.xaml.cs | 1 - 9 files changed, 187 insertions(+), 52 deletions(-) diff --git a/HandheldCompanion/App.xaml.cs b/HandheldCompanion/App.xaml.cs index d3bc8b3d5..090721d6c 100644 --- a/HandheldCompanion/App.xaml.cs +++ b/HandheldCompanion/App.xaml.cs @@ -4,6 +4,7 @@ using Serilog; using Serilog.Extensions.Logging; using System; +using System.Globalization; using System.IO; using System.Threading; using System.Windows; @@ -25,6 +26,24 @@ public partial class App : Application [STAThread] private void Main(object sender, StartupEventArgs Arguments) { + string CurrentCulture = HandheldCompanion.Properties.Settings.Default.CurrentCulture; + CultureInfo culture = CultureInfo.CurrentCulture; + + switch (CurrentCulture) + { + default: + break; + case "fr-FR": + case "en-US": + case "zh-CN": + case "zh-Hant": + culture = new CultureInfo(CurrentCulture); + break; + } + + Thread.CurrentThread.CurrentCulture = culture; + Thread.CurrentThread.CurrentUICulture = culture; + if (mutex.WaitOne(TimeSpan.Zero, true)) { Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); diff --git a/HandheldCompanion/Properties/Resources.Designer.cs b/HandheldCompanion/Properties/Resources.Designer.cs index 3c62d8e9b..22c9f23c2 100644 --- a/HandheldCompanion/Properties/Resources.Designer.cs +++ b/HandheldCompanion/Properties/Resources.Designer.cs @@ -1419,6 +1419,42 @@ public static string ServiceName { } } + /// + /// Looks up a localized string similar to Language. + /// + public static string SettingsPage_AppLanguage { + get { + return ResourceManager.GetString("SettingsPage_AppLanguage", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The application language. + /// + public static string SettingsPage_AppLanguageDesc { + get { + return ResourceManager.GetString("SettingsPage_AppLanguageDesc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Restart required. + /// + public static string SettingsPage_AppLanguageWarning { + get { + return ResourceManager.GetString("SettingsPage_AppLanguageWarning", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to In order for the changes to take effect, please restart the application. + /// + public static string SettingsPage_AppLanguageWarningDesc { + get { + return ResourceManager.GetString("SettingsPage_AppLanguageWarningDesc", resourceCulture); + } + } + /// /// Looks up a localized string similar to Application theme. /// diff --git a/HandheldCompanion/Properties/Resources.fr.resx b/HandheldCompanion/Properties/Resources.fr.resx index 905b90b6a..05e49c9fa 100644 --- a/HandheldCompanion/Properties/Resources.fr.resx +++ b/HandheldCompanion/Properties/Resources.fr.resx @@ -223,22 +223,18 @@ OK - update Déployer le service - Service manager - update + Gestionnaire de service - Oups. There was an issue while we tried to start the service. - update + Oups. Il y a eu un problème lorsque nous avons essayé de démarrer le service. - Oups. There was an issue while we tried to stop the service. - update + Oups. Il y a eu un problème lorsque nous avons essayé d'arrêter le service. Supprimer le service @@ -428,31 +424,25 @@ Modifier l'anti-zone morte, en pourcentage - Are you sure you want to delete - update + Êtes-vous sûr de vouloir supprimer - This item will be deleted immediatly. You can't undo this action. - update + Cet élément sera supprimé immédiatement. Vous ne pouvez pas annuler cette action. - Are you sure you want to overwrite - update + Etes-vous sûr de vouloir écraser - This item will be overwriten. You can't undo this action. - update + Cet élément sera écrasé. Vous ne pouvez pas annuler cette action. - Cancel - update + Annuler Créer un nouveau profil - Delete - update + Supprimer Supprimer le profil @@ -501,7 +491,6 @@ OK - update Détails du profil @@ -525,12 +514,10 @@ Paramètres du profil - Profile updated - update + Profil mis à jour - was updated. - update + a été mis à jour. Roulis @@ -572,8 +559,7 @@ Lacet - Yes - update + Oui Fournit une prise en charge du gyroscope et de l'accéléromètre aux ordinateurs de jeu portables Windows par le biais d'un contrôleur virtuel. Si le service est activé, le contrôleur intégré sera masqué pour les applications en dehors de la liste blanche. Si le service est désactivé, le contrôleur embarqué ne sera plus caché et le contrôleur virtuel sera désactivé @@ -581,6 +567,18 @@ Controller Service + + Langue + + + La langue de l'application + + + Redémarrage nécessaire + + + Pour que les modifications soient prises en compte, veuillez redémarrer l'application + Thème de l'application @@ -663,7 +661,7 @@ Mises à jour disponibles - Vérification des mises à jour.. + Vérification des mises à jour... Vous êtes à jour diff --git a/HandheldCompanion/Properties/Resources.resx b/HandheldCompanion/Properties/Resources.resx index 083d7fc45..73507b3f1 100644 --- a/HandheldCompanion/Properties/Resources.resx +++ b/HandheldCompanion/Properties/Resources.resx @@ -221,22 +221,18 @@ OK - update Deploy service Service manager - update Oups. There was an issue while we tried to start the service. - update Oups. There was an issue while we tried to stop the service. - update Remove service @@ -429,30 +425,24 @@ Are you sure you want to delete - update This item will be deleted immediatly. You can't undo this action. - update Are you sure you want to overwrite - update This item will be overwriten. You can't undo this action. - update Cancel - update Create a new profile Delete - update Delete profile @@ -501,7 +491,6 @@ OK - update Profile details @@ -526,11 +515,9 @@ Profile updated - update was updated. - update Roll @@ -573,7 +560,6 @@ Yes - update Properties.Resources.ControllerPage_Disconnect @@ -584,6 +570,18 @@ Controller Service + + Language + + + The application language + + + Restart required + + + In order for the changes to take effect, please restart the application + Application theme diff --git a/HandheldCompanion/Properties/Settings.Designer.cs b/HandheldCompanion/Properties/Settings.Designer.cs index aad3197cb..2429c612a 100644 --- a/HandheldCompanion/Properties/Settings.Designer.cs +++ b/HandheldCompanion/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace HandheldCompanion.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.0.3.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.1.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -286,5 +286,17 @@ public int OverlayTrackpadsSize { this["OverlayTrackpadsSize"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string CurrentCulture { + get { + return ((string)(this["CurrentCulture"])); + } + set { + this["CurrentCulture"] = value; + } + } } } diff --git a/HandheldCompanion/Properties/Settings.settings b/HandheldCompanion/Properties/Settings.settings index 0219bacd4..5f116b3f4 100644 --- a/HandheldCompanion/Properties/Settings.settings +++ b/HandheldCompanion/Properties/Settings.settings @@ -68,5 +68,8 @@ 250 + + + \ No newline at end of file diff --git a/HandheldCompanion/Views/Pages/SettingsPage.xaml b/HandheldCompanion/Views/Pages/SettingsPage.xaml index 467a80e3e..93641b53d 100644 --- a/HandheldCompanion/Views/Pages/SettingsPage.xaml +++ b/HandheldCompanion/Views/Pages/SettingsPage.xaml @@ -161,12 +161,35 @@ - - - - + + + + + + + + + + + + + + + + + + + + + + + + @@ -226,9 +249,7 @@ - + diff --git a/HandheldCompanion/Views/Pages/SettingsPage.xaml.cs b/HandheldCompanion/Views/Pages/SettingsPage.xaml.cs index c169c1968..d286aa28a 100644 --- a/HandheldCompanion/Views/Pages/SettingsPage.xaml.cs +++ b/HandheldCompanion/Views/Pages/SettingsPage.xaml.cs @@ -2,10 +2,14 @@ using ControllerCommon.Utils; using Microsoft.Extensions.Logging; using ModernWpf; +using ModernWpf.Controls; using System; +using System.Globalization; using System.Linq; using System.ServiceProcess; +using System.Threading; using System.Windows.Controls; +using Page = System.Windows.Controls.Page; using ServiceControllerStatus = ControllerCommon.ServiceControllerStatus; namespace HandheldCompanion.Views.Pages @@ -114,6 +118,26 @@ public SettingsPage(string Tag, MainWindow mainWindow, ILogger logger) : this() foreach (ServiceStartMode mode in ((ServiceStartMode[])Enum.GetValues(typeof(ServiceStartMode))).Where(mode => mode >= ServiceStartMode.Automatic)) cB_StartupType.Items.Add(EnumUtils.GetDescriptionFromEnumValue(mode)); + + // supported languages + cB_Language.Items.Add(new CultureInfo("en-US")); + cB_Language.Items.Add(new CultureInfo("fr-FR")); + cB_Language.Items.Add(new CultureInfo("zh-CN")); + cB_Language.Items.Add(new CultureInfo("zh-Hant")); + + string CurrentCulture = Thread.CurrentThread.CurrentCulture.Name; + switch (CurrentCulture) + { + default: + cB_Language.SelectedItem = new CultureInfo("en-US"); + break; + case "fr-FR": + case "en-US": + case "zh-CN": + case "zh-Hant": + cB_Language.SelectedItem = new CultureInfo(CurrentCulture); + break; + } } private void Toggle_AutoStart_Toggled(object sender, System.Windows.RoutedEventArgs e) @@ -191,6 +215,24 @@ private void Toggle_ServiceStartup_Toggled(object sender, System.Windows.RoutedE StartServiceWithCompanion = Toggle_ServiceStartup.IsOn; } + private void cB_Language_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + if (cB_Language.SelectedItem == null) + return; + + // skip if setting is identical to current + CultureInfo culture = (CultureInfo)cB_Language.SelectedItem; + if (culture.Name == Properties.Settings.Default.CurrentCulture) + return; + + Properties.Settings.Default.CurrentCulture = culture.Name; + Properties.Settings.Default.Save(); + + Dialog.ShowAsync($"{Properties.Resources.SettingsPage_AppLanguageWarning}", + Properties.Resources.SettingsPage_AppLanguageWarningDesc, + ContentDialogButton.Primary, null, $"{Properties.Resources.ProfilesPage_OK}"); + } + private void Toggle_Notification_Toggled(object sender, System.Windows.RoutedEventArgs e) { Properties.Settings.Default.ToastEnable = Toggle_Notification.IsOn; @@ -202,6 +244,13 @@ private void Toggle_Notification_Toggled(object sender, System.Windows.RoutedEve private void cB_Theme_SelectionChanged(object sender, SelectionChangedEventArgs e) { + if (cB_Theme.SelectedIndex == -1) + return; + + // skip if setting is identical to current + if (cB_Theme.SelectedIndex == Properties.Settings.Default.MainWindowTheme) + return; + Properties.Settings.Default.MainWindowTheme = cB_Theme.SelectedIndex; Properties.Settings.Default.Save(); diff --git a/HandheldCompanion/Views/Windows/MainWindow.xaml.cs b/HandheldCompanion/Views/Windows/MainWindow.xaml.cs index 880d551b0..1152bc4f2 100644 --- a/HandheldCompanion/Views/Windows/MainWindow.xaml.cs +++ b/HandheldCompanion/Views/Windows/MainWindow.xaml.cs @@ -115,7 +115,6 @@ public MainWindow(StartupEventArgs arguments, ILogger logger) logger.LogInformation("{0} ({1})", ManufacturerName, ProductName); Assembly CurrentAssembly = Assembly.GetExecutingAssembly(); - Thread.CurrentThread.CurrentUICulture = CultureInfo.CurrentCulture; fileVersionInfo = FileVersionInfo.GetVersionInfo(CurrentAssembly.Location); // initialize log