From c3518e07e6c01485e4fb41649f032e46ce3167f9 Mon Sep 17 00:00:00 2001 From: "Aaron (Qilong)" Date: Mon, 16 Oct 2023 09:49:43 -0400 Subject: [PATCH 1/3] update dynamo locale based on setting or host --- src/DynamoApplications/StartupUtils.cs | 11 +++-------- src/DynamoCore/Configuration/Configurations.cs | 2 +- src/DynamoCore/Models/DynamoModel.cs | 15 +++++++++++++++ src/DynamoCore/Properties/Resources.Designer.cs | 2 +- src/DynamoCore/Properties/Resources.en-US.resx | 2 +- src/DynamoCore/Properties/Resources.resx | 2 +- 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/DynamoApplications/StartupUtils.cs b/src/DynamoApplications/StartupUtils.cs index e4b75db05a0..280d7bcadb9 100644 --- a/src/DynamoApplications/StartupUtils.cs +++ b/src/DynamoApplications/StartupUtils.cs @@ -245,9 +245,7 @@ private static IUpdateManager InitializeUpdateManager() { IPathResolver pathResolver = CreatePathResolver(false, string.Empty, string.Empty, string.Empty); PathManager.Instance.AssignHostPathAndIPathResolver(string.Empty, pathResolver); - - Thread.CurrentThread.CurrentUICulture = new CultureInfo(PreferenceSettings.Instance.Locale); - Thread.CurrentThread.CurrentCulture = new CultureInfo(PreferenceSettings.Instance.Locale); + DynamoModel.SetUICulture(PreferenceSettings.Instance.Locale); DynamoModel.OnDetectLanguage(); // Preload ASM and display corresponding message on splash screen @@ -284,9 +282,7 @@ public static DynamoModel MakeModel(bool CLImode, string asmPath = "", string ho { IPathResolver pathResolver = CreatePathResolver(false, string.Empty, string.Empty, string.Empty); PathManager.Instance.AssignHostPathAndIPathResolver(string.Empty, pathResolver); - - Thread.CurrentThread.CurrentUICulture = new CultureInfo(PreferenceSettings.Instance.Locale); - Thread.CurrentThread.CurrentCulture = new CultureInfo(PreferenceSettings.Instance.Locale); + DynamoModel.SetUICulture(PreferenceSettings.Instance.Locale); DynamoModel.OnDetectLanguage(); // Preload ASM and display corresponding message on splash screen @@ -425,8 +421,7 @@ public static string SetLocale(CommandLineArguments cmdLineArgs) if (!string.IsNullOrEmpty(cmdLineArgs.Locale)) { // Change the application locale, if a locale information is supplied. - Thread.CurrentThread.CurrentUICulture = new CultureInfo(cmdLineArgs.Locale); - Thread.CurrentThread.CurrentCulture = new CultureInfo(cmdLineArgs.Locale); + DynamoModel.SetUICulture(cmdLineArgs.Locale); libgLocale = cmdLineArgs.Locale; } else diff --git a/src/DynamoCore/Configuration/Configurations.cs b/src/DynamoCore/Configuration/Configurations.cs index 60c4a34870d..fa2a42ea0fd 100644 --- a/src/DynamoCore/Configuration/Configurations.cs +++ b/src/DynamoCore/Configuration/Configurations.cs @@ -377,7 +377,7 @@ public class Configurations /// /// Supported locales as a list /// - internal static readonly List SupportedLocaleList = new List() { "en-US", "cs-CZ", "de-DE", "es-ES", "fr-FR", "it-IT", "ja-JP", "ko-KR", "pl-PL", "pt-BR", "ru-RU", "zh-CN", "zh-TW" }; + internal static readonly List SupportedLocaleList = new List() { "Default", "en-US", "cs-CZ", "de-DE", "es-ES", "fr-FR", "it-IT", "ja-JP", "ko-KR", "pl-PL", "pt-BR", "ru-RU", "zh-CN", "zh-TW" }; /// /// Supported languages and locales as a dictionary in the current thread locale diff --git a/src/DynamoCore/Models/DynamoModel.cs b/src/DynamoCore/Models/DynamoModel.cs index 4ca4738f112..ce5c2060ce9 100644 --- a/src/DynamoCore/Models/DynamoModel.cs +++ b/src/DynamoCore/Models/DynamoModel.cs @@ -681,6 +681,12 @@ protected DynamoModel(IStartConfiguration config) PreferenceSettings = (PreferenceSettings)CreateOrLoadPreferences(config.Preferences); if (PreferenceSettings != null) { + // In a integration case, respect default setting to use the host locale + if (!PreferenceSettings.Locale.Equals(Configuration.Configurations.SupportedLocaleList.First()) && HostAnalyticsInfo.HostName != string.Empty) + { + // Setting the locale for Dynamo from loaded Preferences + SetUICulture(PreferenceSettings.Locale); + } PreferenceSettings.PropertyChanged += PreferenceSettings_PropertyChanged; PreferenceSettings.MessageLogged += LogMessage; } @@ -2698,6 +2704,15 @@ internal bool CanDumpLibraryToXml(object obj) #region public methods + /// + /// Set UI culture based on preferences + /// + public static void SetUICulture(string locale) + { + Thread.CurrentThread.CurrentUICulture = new CultureInfo(locale == "Default" ? "en-US" : locale); + Thread.CurrentThread.CurrentCulture = new CultureInfo(locale == "Default" ? "en-US" : locale); + } + /// /// Add a new HomeWorkspace and set as current /// diff --git a/src/DynamoCore/Properties/Resources.Designer.cs b/src/DynamoCore/Properties/Resources.Designer.cs index 917980b34bc..f523c41ad4c 100644 --- a/src/DynamoCore/Properties/Resources.Designer.cs +++ b/src/DynamoCore/Properties/Resources.Designer.cs @@ -570,7 +570,7 @@ public static string DuplicateMigrationTypeRegistered { } /// - /// Looks up a localized string similar to English,Čeština,Deutsch,Español,Français,Italiano,日本語,한국어,Polski,Português (Brasil),Русский,简体中文,繁體中文. + /// Looks up a localized string similar to Default,English,Čeština,Deutsch,Español,Français,Italiano,日本語,한국어,Polski,Português (Brasil),Русский,简体中文,繁體中文. /// public static string DynamoLanguages_noxlate { get { diff --git a/src/DynamoCore/Properties/Resources.en-US.resx b/src/DynamoCore/Properties/Resources.en-US.resx index 70da17d6afc..b40c51c4764 100644 --- a/src/DynamoCore/Properties/Resources.en-US.resx +++ b/src/DynamoCore/Properties/Resources.en-US.resx @@ -900,7 +900,7 @@ This package likely contains an assembly that is blocked. You will need to load Example file added to workspace. Run mode changed to Manual. - English,Čeština,Deutsch,Español,Français,Italiano,日本語,한국어,Polski,Português (Brasil),Русский,简体中文,繁體中文 + Default,English,Čeština,Deutsch,Español,Français,Italiano,日本語,한국어,Polski,Português (Brasil),Русский,简体中文,繁體中文 Formula failed to convert to DesignScript code. Please edit the formula manually to use it in a CodeBlock node. diff --git a/src/DynamoCore/Properties/Resources.resx b/src/DynamoCore/Properties/Resources.resx index 523bd8cf3ea..77d3d8340dd 100644 --- a/src/DynamoCore/Properties/Resources.resx +++ b/src/DynamoCore/Properties/Resources.resx @@ -903,7 +903,7 @@ This package likely contains an assembly that is blocked. You will need to load Example file added to workspace. Run mode changed to Manual. - English,Čeština,Deutsch,Español,Français,Italiano,日本語,한국어,Polski,Português (Brasil),Русский,简体中文,繁體中文 + Default,English,Čeština,Deutsch,Español,Français,Italiano,日本語,한국어,Polski,Português (Brasil),Русский,简体中文,繁體中文 Formula failed to convert to DesignScript code. Please edit the formula manually to use it in a CodeBlock node. From 8fbaf525e47a6ea0f5dd4b110a28a0079c4b5318 Mon Sep 17 00:00:00 2001 From: "Aaron (Qilong)" Date: Mon, 16 Oct 2023 15:24:02 -0400 Subject: [PATCH 2/3] Update --- src/DynamoCore/Models/DynamoModel.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/DynamoCore/Models/DynamoModel.cs b/src/DynamoCore/Models/DynamoModel.cs index ce5c2060ce9..e05d3e69c90 100644 --- a/src/DynamoCore/Models/DynamoModel.cs +++ b/src/DynamoCore/Models/DynamoModel.cs @@ -681,10 +681,11 @@ protected DynamoModel(IStartConfiguration config) PreferenceSettings = (PreferenceSettings)CreateOrLoadPreferences(config.Preferences); if (PreferenceSettings != null) { - // In a integration case, respect default setting to use the host locale - if (!PreferenceSettings.Locale.Equals(Configuration.Configurations.SupportedLocaleList.First()) && HostAnalyticsInfo.HostName != string.Empty) + // Setting the locale for Dynamo from loaded Preferences only when + // In a non-in-process integration case (when HostAnalyticsInfo.HostName is unspecified) + // Language is specified, otherwise Default setting means following host locale + if (string.IsNullOrEmpty(HostAnalyticsInfo.HostName) || !PreferenceSettings.Locale.Equals(Configuration.Configurations.SupportedLocaleList.First())) { - // Setting the locale for Dynamo from loaded Preferences SetUICulture(PreferenceSettings.Locale); } PreferenceSettings.PropertyChanged += PreferenceSettings_PropertyChanged; From 0b2b21b74743d6b6874d2401c6581ff0a8c44ce3 Mon Sep 17 00:00:00 2001 From: "Aaron (Qilong)" Date: Tue, 17 Oct 2023 00:55:34 -0400 Subject: [PATCH 3/3] update baseline test --- test/DynamoCoreTests/Configuration/PreferenceSettingsTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/DynamoCoreTests/Configuration/PreferenceSettingsTests.cs b/test/DynamoCoreTests/Configuration/PreferenceSettingsTests.cs index 0b1880756b0..9545df367c1 100644 --- a/test/DynamoCoreTests/Configuration/PreferenceSettingsTests.cs +++ b/test/DynamoCoreTests/Configuration/PreferenceSettingsTests.cs @@ -70,7 +70,7 @@ public void TestSettingsSerialization() Assert.AreEqual(settings.ViewExtensionSettings.Count, 0); Assert.AreEqual(settings.DefaultRunType, RunType.Automatic); Assert.AreEqual(settings.DynamoPlayerFolderGroups.Count, 0); - Assert.AreEqual(settings.Locale, "en-US"); + Assert.AreEqual(settings.Locale, "Default"); // Save settings.Save(tempPath); @@ -89,7 +89,7 @@ public void TestSettingsSerialization() Assert.AreEqual(settings.ViewExtensionSettings.Count, 0); Assert.AreEqual(settings.DefaultRunType, RunType.Automatic); Assert.AreEqual(settings.DynamoPlayerFolderGroups.Count, 0); - Assert.AreEqual(settings.Locale, "en-US"); + Assert.AreEqual(settings.Locale, "Default"); // Change setting values settings.SetIsBackgroundPreviewActive("MyBackgroundPreview", false);