|
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()
|
|
0 commit comments