From 52f1016e08b39fcabf2d46e0ecffd1d6ac4d47a5 Mon Sep 17 00:00:00 2001 From: Ashish Aggarwal Date: Wed, 10 Jan 2024 16:08:16 -0500 Subject: [PATCH] Update PreferencesViewModel.cs --- .../ViewModels/Menu/PreferencesViewModel.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs b/src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs index b884ce40de1..9e74bb37fdd 100644 --- a/src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs @@ -197,13 +197,14 @@ public string SelectedUnits if (UseHostScaleUnits && IsDynamoRevit) return; - var result = Enum.TryParse(selectedUnits, out Configurations.Units currentUnit); + var enUnit = LocalizedUnitsMap.FirstOrDefault(x => x.Key == selectedUnits).Value; + var result = Enum.TryParse(enUnit, out Configurations.Units currentUnit); if (!result) return; if (Configurations.SupportedUnits.TryGetValue(currentUnit, out double units)) { // Update preferences setting and update the grapic helpers - preferenceSettings.GraphicScaleUnit = value; + preferenceSettings.GraphicScaleUnit = currentUnit.ToString(); preferenceSettings.GridScaleFactor = (float)units; dynamoViewModel.UpdateGraphicHelpersScaleCommand.Execute(null); @@ -1291,6 +1292,12 @@ public bool importSettingsContent(string content) return setSettings(newPreferences); } + /// + /// The dictionary that contains the localized resource strings for Units. + /// This is done to avoid a breaking change that is storing the selected unit in settings file in english language. + /// + private Dictionary LocalizedUnitsMap; + /// /// Returns localized resource strings for Units /// @@ -1392,6 +1399,12 @@ public PreferencesViewModel(DynamoViewModel dynamoViewModel) LanguagesList = Configurations.SupportedLocaleDic.Keys.ToObservableCollection(); SelectedLanguage = Configurations.SupportedLocaleDic.FirstOrDefault(x => x.Value == preferenceSettings.Locale).Key; + LocalizedUnitsMap = new Dictionary(); + foreach (var unit in Configurations.SupportedUnits) + { + LocalizedUnitsMap.Add(GetLocalizedUnits(unit.Key), unit.Key.ToString()); + } + // Chose the scaling unit, if option is allowed by user UnitList = Configurations.SupportedUnits.Keys.Select(x => GetLocalizedUnits(x)).ToObservableCollection(); SelectedUnits = GetLocalizedUnits(Configurations.SupportedUnits.FirstOrDefault(x => x.Key.ToString() == preferenceSettings.GraphicScaleUnit).Key);