From 58d339ff57da253fcb2eef2d1b6ef360b3da339f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Paill=C3=A9?= Date: Sun, 1 Nov 2020 17:41:36 -0500 Subject: [PATCH 1/2] Added basic localization support. --- application/GW2 Addon Manager.sln | 6 + .../App/Configuration/Model/UserConfig.cs | 5 +- .../GW2 Addon Manager/Application.csproj | 7 +- .../Backend/Configuration/configuration.cs | 21 +++ .../UI/OpeningPage/OpeningView.xaml.cs | 3 + application/Localization/CultureConstants.cs | 12 ++ application/Localization/Localization.csproj | 22 +++ .../Localization/StaticText.Designer.cs | 99 +++++++++++++ .../Localization/StaticText.fr-CA.resx | 112 +++++++++++++++ .../Localization/StaticText.ko-KR.resx | 120 ++++++++++++++++ application/Localization/StaticText.resx | 132 ++++++++++++++++++ .../Localization/StaticText.zh-CN.resx | 101 ++++++++++++++ 12 files changed, 638 insertions(+), 2 deletions(-) create mode 100644 application/Localization/CultureConstants.cs create mode 100644 application/Localization/Localization.csproj create mode 100644 application/Localization/StaticText.Designer.cs create mode 100644 application/Localization/StaticText.fr-CA.resx create mode 100644 application/Localization/StaticText.ko-KR.resx create mode 100644 application/Localization/StaticText.resx create mode 100644 application/Localization/StaticText.zh-CN.resx diff --git a/application/GW2 Addon Manager.sln b/application/GW2 Addon Manager.sln index 856cd2e..36a0c81 100644 --- a/application/GW2 Addon Manager.sln +++ b/application/GW2 Addon Manager.sln @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Application", "GW2 Addon Ma EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApplicationTests", "ApplicationTests\ApplicationTests.csproj", "{170F11FB-4005-4A31-A746-32B46814F463}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Localization", "Localization\Localization.csproj", "{5B139D74-6A36-4F8F-833F-4D0DE41FF019}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,6 +29,10 @@ Global {170F11FB-4005-4A31-A746-32B46814F463}.Debug|Any CPU.Build.0 = Debug|Any CPU {170F11FB-4005-4A31-A746-32B46814F463}.Release|Any CPU.ActiveCfg = Release|Any CPU {170F11FB-4005-4A31-A746-32B46814F463}.Release|Any CPU.Build.0 = Release|Any CPU + {5B139D74-6A36-4F8F-833F-4D0DE41FF019}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5B139D74-6A36-4F8F-833F-4D0DE41FF019}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5B139D74-6A36-4F8F-833F-4D0DE41FF019}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5B139D74-6A36-4F8F-833F-4D0DE41FF019}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/application/GW2 Addon Manager/App/Configuration/Model/UserConfig.cs b/application/GW2 Addon Manager/App/Configuration/Model/UserConfig.cs index df74ff1..8ed5163 100644 --- a/application/GW2 Addon Manager/App/Configuration/Model/UserConfig.cs +++ b/application/GW2 Addon Manager/App/Configuration/Model/UserConfig.cs @@ -1,4 +1,5 @@ -using System; +using Localization; +using System; namespace GW2_Addon_Manager.App.Configuration.Model { @@ -15,6 +16,8 @@ public class UserConfig public string ExeName { get; set; } + public string Culture { get; set; } = CultureConstants.English; + public AddonsList AddonsList { get; set; } = new AddonsList(); } } \ No newline at end of file diff --git a/application/GW2 Addon Manager/Application.csproj b/application/GW2 Addon Manager/Application.csproj index b536198..cbf15f7 100644 --- a/application/GW2 Addon Manager/Application.csproj +++ b/application/GW2 Addon Manager/Application.csproj @@ -267,7 +267,12 @@ True - + + + {5b139d74-6a36-4f8f-833f-4d0de41ff019} + Localization + + mkdir "$(TargetDir)resources\plugins" diff --git a/application/GW2 Addon Manager/Backend/Configuration/configuration.cs b/application/GW2 Addon Manager/Backend/Configuration/configuration.cs index 06b7eec..455a695 100644 --- a/application/GW2 Addon Manager/Backend/Configuration/configuration.cs +++ b/application/GW2 Addon Manager/Backend/Configuration/configuration.cs @@ -39,6 +39,27 @@ public void SetGamePath(string path) DetermineSystemType(); } + /// + /// SetCulture both sets the culture for the current application session to and records it in the configuration file. + /// + /// + public void SetCulture(string culture) + { + Application.Current.Properties["culture"] = culture; + _configurationManager.UserConfig.Culture = culture; + _configurationManager.SaveConfiguration(); + RestartApplication(); + } + + /// + /// Restarts the application. + /// + private void RestartApplication() + { + System.Diagnostics.Process.Start(Application.ResourceAssembly.Location); + Application.Current.Shutdown(); + } + /// /// Checks if there is a new version of the application available. /// diff --git a/application/GW2 Addon Manager/UI/OpeningPage/OpeningView.xaml.cs b/application/GW2 Addon Manager/UI/OpeningPage/OpeningView.xaml.cs index dce9b4f..a47f58c 100644 --- a/application/GW2 Addon Manager/UI/OpeningPage/OpeningView.xaml.cs +++ b/application/GW2 Addon Manager/UI/OpeningPage/OpeningView.xaml.cs @@ -11,6 +11,8 @@ using GW2_Addon_Manager.App.Configuration; using Application = System.Windows.Application; using MessageBox = System.Windows.MessageBox; +using System.Threading; +using System.Globalization; namespace GW2_Addon_Manager { @@ -33,6 +35,7 @@ public OpeningView() DataContext = OpeningViewModel.GetInstance; _configurationManager = new ConfigurationManager(); + Thread.CurrentThread.CurrentUICulture = new CultureInfo(_configurationManager.UserConfig.Culture); var configuration = new Configuration(_configurationManager); configuration.CheckSelfUpdates(); configuration.DetermineSystemType(); diff --git a/application/Localization/CultureConstants.cs b/application/Localization/CultureConstants.cs new file mode 100644 index 0000000..04c0985 --- /dev/null +++ b/application/Localization/CultureConstants.cs @@ -0,0 +1,12 @@ +using System.Data; + +namespace Localization +{ + public static class CultureConstants + { + public const string Chinese = "zh-CN"; + public const string English = "en-US"; + public const string French = "fr-CA"; + public const string Korean = "ko-KR"; + } +} diff --git a/application/Localization/Localization.csproj b/application/Localization/Localization.csproj new file mode 100644 index 0000000..6a8dc29 --- /dev/null +++ b/application/Localization/Localization.csproj @@ -0,0 +1,22 @@ + + + + netstandard2.0 + + + + + True + True + StaticText.resx + + + + + + PublicResXFileCodeGenerator + StaticText.Designer.cs + + + + diff --git a/application/Localization/StaticText.Designer.cs b/application/Localization/StaticText.Designer.cs new file mode 100644 index 0000000..41ec47a --- /dev/null +++ b/application/Localization/StaticText.Designer.cs @@ -0,0 +1,99 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Localization { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + public class StaticText { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal StaticText() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Localization.StaticText", typeof(StaticText).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Chinese. + /// + public static string Chinese { + get { + return ResourceManager.GetString("Chinese", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to English. + /// + public static string English { + get { + return ResourceManager.GetString("English", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to French. + /// + public static string French { + get { + return ResourceManager.GetString("French", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Korean. + /// + public static string Korean { + get { + return ResourceManager.GetString("Korean", resourceCulture); + } + } + } +} diff --git a/application/Localization/StaticText.fr-CA.resx b/application/Localization/StaticText.fr-CA.resx new file mode 100644 index 0000000..709bb26 --- /dev/null +++ b/application/Localization/StaticText.fr-CA.resx @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Français + + + Anglais + + + Chinois + + + Coréen + + \ No newline at end of file diff --git a/application/Localization/StaticText.ko-KR.resx b/application/Localization/StaticText.ko-KR.resx new file mode 100644 index 0000000..d58980a --- /dev/null +++ b/application/Localization/StaticText.ko-KR.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/application/Localization/StaticText.resx b/application/Localization/StaticText.resx new file mode 100644 index 0000000..7672fab --- /dev/null +++ b/application/Localization/StaticText.resx @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + French + + + English + + + Chinese + + + Korean + + \ No newline at end of file diff --git a/application/Localization/StaticText.zh-CN.resx b/application/Localization/StaticText.zh-CN.resx new file mode 100644 index 0000000..4fdb1b6 --- /dev/null +++ b/application/Localization/StaticText.zh-CN.resx @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file From 964e785d390ce876d286ec55046b4070f06756b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Paill=C3=A9?= Date: Sun, 1 Nov 2020 17:52:24 -0500 Subject: [PATCH 2/2] Added language selection. --- .../UI/OpeningPage/OpeningView.xaml | 55 ++++++++++++++++--- .../UI/OpeningPage/OpeningViewModel.cs | 7 +++ .../Localization/StaticText.Designer.cs | 9 +++ .../Localization/StaticText.fr-CA.resx | 3 + application/Localization/StaticText.resx | 3 + 5 files changed, 69 insertions(+), 8 deletions(-) diff --git a/application/GW2 Addon Manager/UI/OpeningPage/OpeningView.xaml b/application/GW2 Addon Manager/UI/OpeningPage/OpeningView.xaml index 376a3c5..93b0088 100644 --- a/application/GW2 Addon Manager/UI/OpeningPage/OpeningView.xaml +++ b/application/GW2 Addon Manager/UI/OpeningPage/OpeningView.xaml @@ -3,6 +3,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:l="clr-namespace:Localization;assembly=Localization" xmlns:viewModel ="clr-namespace:GW2_Addon_Manager" x:Class="GW2_Addon_Manager.OpeningView" mc:Ignorable="d" @@ -41,7 +42,7 @@ + + + + + +