Skip to content

Commit

Permalink
Enable Locale Selection in Dynamo Preferences Panel (#13802)
Browse files Browse the repository at this point in the history
* First Commit

* Update locale on startup

* spelling

* dynamically display and select current locale

* Clean up

* Unit Tests

* Add toast notification

* Move constants out of PreferencesSetting object

* Add info icon and tooltip

* Update PreferenceSettingsTests.cs

* Update test file

* Remove interface change
  • Loading branch information
QilongTang authored and sm6srw committed Apr 5, 2023
1 parent 999b0ec commit 7f2a31e
Show file tree
Hide file tree
Showing 16 changed files with 156 additions and 127 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
using Dynamo.Logging;
using Dynamo.Utilities;
using Dynamo.Wpf.UI.GuidedTour;
using Microsoft.Web.WebView2.Core;
using Microsoft.Web.WebView2.Wpf;
using SharpDX.Direct3D9;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Web;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Dynamo.Logging;
using Dynamo.Utilities;
using Microsoft.Web.WebView2.Core;
using Microsoft.Web.WebView2.Wpf;

namespace Dynamo.DocumentationBrowser
{
Expand Down
6 changes: 1 addition & 5 deletions src/DynamoApplications/StartupUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,7 @@ private static DynamoModel StartDynamoWithDefaultConfig(bool CLImode,

public static string SetLocale(CommandLineArguments cmdLineArgs)
{
var supportedLocale = new HashSet<string>(new[]
{
"cs-CZ", "de-DE", "en-US", "es-ES", "fr-FR", "it-IT",
"ja-JP", "ko-KR", "pl-PL", "pt-BR", "ru-RU", "zh-CN", "zh-TW"
});
var supportedLocale = new HashSet<string>(Configuration.Configurations.SupportedLocaleDic.Values);
string libgLocale = string.Empty;

if (!string.IsNullOrEmpty(cmdLineArgs.Locale))
Expand Down
29 changes: 27 additions & 2 deletions src/DynamoCore/Configuration/Configurations.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Dynamo.Properties;
using Dynamo.Properties;
using Dynamo.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Dynamo.Configuration
{
Expand Down Expand Up @@ -369,5 +371,28 @@ public class Configurations
public static string BackupFileNamePrefix = "backup";

#endregion

#region Locale info and constants

/// <summary>
/// Supported locales as a list
/// </summary>
internal static readonly List<string> SupportedLocaleList = new List<string>() { "en-US", "cs-CZ", "de-DE", "es-ES", "fr-FR", "it-IT", "ja-JP", "ko-KR", "pl-PL", "pt-BR", "pt-BR", "ru-RU", "zh-CN", "zh-TW" };

/// <summary>
/// Supported languages and locales as a dictionary in the current thread locale
/// </summary>
public static Dictionary<string, string> SupportedLocaleDic
{
get
{
// Dynamically create a dictionary mapping languages and locales in the current thread locale
// This is done so that Preferences Panel could display the languages selections using the current locale
return Properties.Resources.PreferencesWindowLanguages.Split(',').
Zip(SupportedLocaleList, (k, v) => (k, v)).ToDictionary(x => x.k, x => x.v);
}
}

#endregion
}
}
}
10 changes: 8 additions & 2 deletions src/DynamoCore/Configuration/PreferenceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ public class PreferenceSettings : NotificationObject, IPreferences, IRenderPreci
/// <summary>
/// Default time
/// </summary>
public static readonly System.DateTime DynamoDefaultTime = new System.DateTime(1977, 4, 12, 12, 12, 0, 0);
public static readonly DateTime DynamoDefaultTime = new DateTime(1977, 4, 12, 12, 12, 0, 0);

#endregion

/// The following settings are persistent between Dynamo sessions and are user-controllable
// The following settings are persistent between Dynamo sessions and are user-controllable
#region Collect Information settings

/// <summary>
Expand Down Expand Up @@ -141,6 +141,11 @@ public bool IsADPAnalyticsReportingApproved
/// </summary>
public int LibraryWidth { get; set; }

/// <summary>
/// The locale of Dynamo UI, serialize locale instead of language name as ease of conversion back and forth
/// </summary>
public string Locale { get; set; }

/// <summary>
/// The height of the console display.
/// </summary>
Expand Down Expand Up @@ -757,6 +762,7 @@ public PreferenceSettings()
// Default Settings
IsFirstRun = true;
IsAnalyticsReportingApproved = true;
Locale = Configurations.SupportedLocaleDic.FirstOrDefault().Value;
LibraryWidth = 304;
ConsoleHeight = 0;
ShowPreviewBubbles = true;
Expand Down
5 changes: 4 additions & 1 deletion src/DynamoCore/Models/DynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -669,11 +669,14 @@ protected DynamoModel(IStartConfiguration config)

geometryFactoryPath = config.GeometryFactoryPath;

DynamoModel.OnRequestUpdateLoadBarStatus(new SplashScreenLoadEventArgs(Resources.SplashScreenInitPreferencesSettings, 30));
OnRequestUpdateLoadBarStatus(new SplashScreenLoadEventArgs(Resources.SplashScreenInitPreferencesSettings, 30));
IPreferences preferences = CreateOrLoadPreferences(config.Preferences);
if (preferences is PreferenceSettings settings)
{
PreferenceSettings = settings;
// Setting the new locale for Dynamo after Preferences loaded
Thread.CurrentThread.CurrentUICulture = new CultureInfo(PreferenceSettings.Locale);
Thread.CurrentThread.CurrentCulture = new CultureInfo(PreferenceSettings.Locale);
PreferenceSettings.PropertyChanged += PreferenceSettings_PropertyChanged;
PreferenceSettings.MessageLogged += LogMessage;
}
Expand Down
9 changes: 9 additions & 0 deletions src/DynamoCore/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/DynamoCore/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -899,4 +899,7 @@ This package likely contains an assembly that is blocked. You will need to load
<data name="InsertGraphRunModeNotificationText" xml:space="preserve">
<value>Example file added to workspace. Run mode changed to Manual.</value>
</data>
<data name="PreferencesWindowLanguages" xml:space="preserve">
<value>English,Czech,German,Spanish,French,Italian,Japanese,Korean,Polish,Portuguese,Brazilian,Russian,Chinese Simplified,Chinese Traditional</value>
</data>
</root>
3 changes: 3 additions & 0 deletions src/DynamoCore/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -902,4 +902,7 @@ This package likely contains an assembly that is blocked. You will need to load
<data name="InsertGraphRunModeNotificationText" xml:space="preserve">
<value>Example file added to workspace. Run mode changed to Manual.</value>
</data>
<data name="PreferencesWindowLanguages" xml:space="preserve">
<value>English,Czech,German,Spanish,French,Italian,Japanese,Korean,Polish,Portuguese,Brazilian,Russian,Chinese Simplified,Chinese Traditional</value>
</data>
</root>
18 changes: 9 additions & 9 deletions src/DynamoCoreWpf/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2303,9 +2303,6 @@ Uninstall the following packages: {0}?</value>
<data name="PreferencesViewVisualSettingsTab" xml:space="preserve">
<value>Visual Settings</value>
</data>
<data name="PreferencesWindowLanguages" xml:space="preserve">
<value>English,Czech,German,Spanish,French,Italian,Japanese,Korean,Polish,Portuguese,Brazilian,Russian,Chinese Simplified,Chinese Traditional</value>
</data>
<data name="PreferencesViewFontSizeLabel" xml:space="preserve">
<value>Node Font Size</value>
</data>
Expand Down Expand Up @@ -3497,6 +3494,9 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in
<data name="DynamoViewSettingLibraryZoomScale" xml:space="preserve">
<value>Library</value>
</data>
<data name="PreferencesViewLanguageSwitchHelp" xml:space="preserve">
<value>Dynamo must be relaunched to apply the language selection.</value>
</data>
<data name="CustomColorPickerApplyBtn" xml:space="preserve">
<value>Apply</value>
</data>
Expand Down
6 changes: 3 additions & 3 deletions src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2519,9 +2519,6 @@ Uninstall the following packages: {0}?</value>
<data name="PreferencesViewVisualSettingsTab" xml:space="preserve">
<value>Visual Settings</value>
</data>
<data name="PreferencesWindowLanguages" xml:space="preserve">
<value>English,Czech,German,Spanish,French,Italian,Japanese,Korean,Polish,Portuguese,Brazilian,Russian,Chinese Simplified,Chinese Traditional</value>
</data>
<data name="PreferencesViewFontSizeLabel" xml:space="preserve">
<value>Node Font Size</value>
</data>
Expand Down Expand Up @@ -3484,6 +3481,9 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in
<data name="DynamoViewSettingLibraryZoomScale" xml:space="preserve">
<value>Library</value>
</data>
<data name="PreferencesViewLanguageSwitchHelp" xml:space="preserve">
<value>Dynamo must be relaunched to apply the language selection.</value>
</data>
<data name="CustomColorPickerApplyBtn" xml:space="preserve">
<value>Apply</value>
</data>
Expand Down
Loading

0 comments on commit 7f2a31e

Please sign in to comment.