From bbefb7d507bb4f351185b7400ac8e0d782760e64 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Sun, 8 Jan 2017 15:29:04 +0100 Subject: [PATCH] Respect CurrentCulture also in CG --- ConfigGenerator/Localization/CGStrings.Designer.cs | 9 +++++++++ ConfigGenerator/Localization/CGStrings.resx | 3 +++ ConfigGenerator/MainForm.cs | 13 ++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/ConfigGenerator/Localization/CGStrings.Designer.cs b/ConfigGenerator/Localization/CGStrings.Designer.cs index 22011493a..d0cdd4bf5 100644 --- a/ConfigGenerator/Localization/CGStrings.Designer.cs +++ b/ConfigGenerator/Localization/CGStrings.Designer.cs @@ -168,6 +168,15 @@ namespace ConfigGenerator.Localization { } } + /// + /// Looks up a localized string similar to Your provided CurrentCulture is invalid, ConfigGenerator will keep running with default one!. + /// + internal static string ErrorInvalidCurrentCulture { + get { + return ResourceManager.GetString("ErrorInvalidCurrentCulture", resourceCulture); + } + } + /// /// Looks up a localized string similar to This name is already used!. /// diff --git a/ConfigGenerator/Localization/CGStrings.resx b/ConfigGenerator/Localization/CGStrings.resx index 547a0a89f..e285560bb 100644 --- a/ConfigGenerator/Localization/CGStrings.resx +++ b/ConfigGenerator/Localization/CGStrings.resx @@ -154,6 +154,9 @@ Configured {0} property is invalid: {1} {0} will be replaced by name of the configuration property, {1} will be replaced by invalid value + + Your provided CurrentCulture is invalid, ConfigGenerator will keep running with default one! + This name is already used! This happens e.g. when user wants to create a bot with name that exists already diff --git a/ConfigGenerator/MainForm.cs b/ConfigGenerator/MainForm.cs index 5dbbf2157..6ddc814b0 100644 --- a/ConfigGenerator/MainForm.cs +++ b/ConfigGenerator/MainForm.cs @@ -25,6 +25,7 @@ using System; using System.ComponentModel; using System.Diagnostics; +using System.Globalization; using System.IO; using System.Linq; using System.Text.RegularExpressions; @@ -64,8 +65,18 @@ namespace ConfigGenerator { return; } - ASFTab = new ConfigPage(GlobalConfig.Load(Path.Combine(SharedInfo.ConfigDirectory, SharedInfo.GlobalConfigFileName))); + GlobalConfig globalConfig = GlobalConfig.Load(Path.Combine(SharedInfo.ConfigDirectory, SharedInfo.GlobalConfigFileName)); + if (!string.IsNullOrEmpty(globalConfig.CurrentCulture)) { + try { + // GetCultureInfo() would be better but we can't use it for specifying neutral cultures such as "en" + CultureInfo culture = CultureInfo.CreateSpecificCulture(globalConfig.CurrentCulture); + CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = culture; + } catch (CultureNotFoundException) { + Logging.LogGenericErrorWithoutStacktrace(CGStrings.ErrorInvalidCurrentCulture); + } + } + ASFTab = new ConfigPage(globalConfig); MainTab.TabPages.Add(ASFTab); foreach (string configFile in Directory.EnumerateFiles(SharedInfo.ConfigDirectory, "*.json")) {