|
9 | 9 | using System; |
10 | 10 | using System.Diagnostics; |
11 | 11 | using System.Globalization; |
| 12 | +using System.Linq; |
12 | 13 | using Rubberduck.Parsing.UIContext; |
13 | 14 | using Rubberduck.Resources; |
14 | 15 | using Rubberduck.UI.Command; |
@@ -182,24 +183,22 @@ private void ApplyCultureConfig() |
182 | 183 |
|
183 | 184 | private static void LocalizeResources(CultureInfo culture) |
184 | 185 | { |
185 | | - //TODO: this method needs something better - maybe use reflection to discover all resourcees |
186 | | - // to set culture for all resources files? |
187 | | - Resources.RubberduckUI.Culture = culture; |
188 | | - Resources.About.AboutUI.Culture = culture; |
189 | | - Resources.Inspections.InspectionInfo.Culture = culture; |
190 | | - Resources.Inspections.InspectionNames.Culture = culture; |
191 | | - Resources.Inspections.InspectionResults.Culture = culture; |
192 | | - Resources.Inspections.InspectionsUI.Culture = culture; |
193 | | - Resources.Inspections.QuickFixes.Culture = culture; |
194 | | - Resources.Menus.RubberduckMenus.Culture = culture; |
195 | | - Resources.RegexAssistant.RegexAssistantUI.Culture = culture; |
196 | | - Resources.Settings.SettingsUI.Culture = culture; |
197 | | - Resources.Settings.ToDoExplorerPage.Culture = culture; |
198 | | - Resources.Settings.UnitTestingPage.Culture = culture; |
199 | | - Resources.ToDoExplorer.ToDoExplorerUI.Culture = culture; |
200 | | - Resources.UnitTesting.AssertMessages.Culture = culture; |
201 | | - Resources.UnitTesting.TestExplorer.Culture = culture; |
202 | | - Resources.Templates.Culture = culture; |
| 186 | + var localizers = AppDomain.CurrentDomain.GetAssemblies() |
| 187 | + .SingleOrDefault(assembly => assembly.GetName().Name == "Rubberduck.Resources") |
| 188 | + ?.DefinedTypes.SelectMany(type => type.DeclaredProperties.Where(prop => |
| 189 | + prop.CanWrite && prop.Name.Equals("Culture") && prop.PropertyType == typeof(CultureInfo) && |
| 190 | + (prop.SetMethod?.IsStatic ?? false))); |
| 191 | + |
| 192 | + if (localizers == null) |
| 193 | + { |
| 194 | + return; |
| 195 | + } |
| 196 | + |
| 197 | + var args = new object[] { culture }; |
| 198 | + foreach (var localizer in localizers) |
| 199 | + { |
| 200 | + localizer.SetMethod.Invoke(null, args); |
| 201 | + } |
203 | 202 | } |
204 | 203 |
|
205 | 204 | private void CheckForLegacyIndenterSettings() |
@@ -230,14 +229,26 @@ public void LogRubberduckStart() |
230 | 229 | { |
231 | 230 | var version = _version.CurrentVersion; |
232 | 231 | GlobalDiagnosticsContext.Set("RubberduckVersion", version.ToString()); |
| 232 | + |
233 | 233 | var headers = new List<string> |
234 | 234 | { |
235 | 235 | $"\r\n\tRubberduck version {version} loading:", |
236 | | - $"\tOperating System: {Environment.OSVersion.VersionString} {(Environment.Is64BitOperatingSystem ? "x64" : "x86")}", |
237 | | - $"\tHost Product: {Application.ProductName} {(Environment.Is64BitProcess ? "x64" : "x86")}", |
238 | | - $"\tHost Version: {Application.ProductVersion}", |
239 | | - $"\tHost Executable: {Path.GetFileName(Application.ExecutablePath).ToUpper()}", // .ToUpper() used to convert ExceL.EXE -> EXCEL.EXE |
| 236 | + $"\tOperating System: {Environment.OSVersion.VersionString} {(Environment.Is64BitOperatingSystem ? "x64" : "x86")}" |
240 | 237 | }; |
| 238 | + try |
| 239 | + { |
| 240 | + headers.AddRange(new [] |
| 241 | + { |
| 242 | + $"\tHost Product: {Application.ProductName} {(Environment.Is64BitProcess ? "x64" : "x86")}", |
| 243 | + $"\tHost Version: {Application.ProductVersion}", |
| 244 | + $"\tHost Executable: {Path.GetFileName(Application.ExecutablePath).ToUpper()}", // .ToUpper() used to convert ExceL.EXE -> EXCEL.EXE |
| 245 | + }); |
| 246 | + } |
| 247 | + catch |
| 248 | + { |
| 249 | + headers.Add("\tHost could not be determined."); |
| 250 | + } |
| 251 | + |
241 | 252 | LogLevelHelper.SetDebugInfo(string.Join(Environment.NewLine, headers)); |
242 | 253 | } |
243 | 254 |
|
|
0 commit comments