Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DYN-5961 Set Dynamo locale based on setting or host #14486

Merged
merged 3 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions src/DynamoApplications/StartupUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/DynamoCore/Configuration/Configurations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public class Configurations
/// <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", "ru-RU", "zh-CN", "zh-TW" };
internal static readonly List<string> SupportedLocaleList = new List<string>() { "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" };

/// <summary>
/// Supported languages and locales as a dictionary in the current thread locale
Expand Down
16 changes: 16 additions & 0 deletions src/DynamoCore/Models/DynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,13 @@ protected DynamoModel(IStartConfiguration config)
PreferenceSettings = (PreferenceSettings)CreateOrLoadPreferences(config.Preferences);
if (PreferenceSettings != null)
{
// 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()))
{
SetUICulture(PreferenceSettings.Locale);
}
PreferenceSettings.PropertyChanged += PreferenceSettings_PropertyChanged;
PreferenceSettings.MessageLogged += LogMessage;
}
Expand Down Expand Up @@ -2698,6 +2705,15 @@ internal bool CanDumpLibraryToXml(object obj)

#region public methods

/// <summary>
/// Set UI culture based on preferences
/// </summary>
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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These code were added in Dynamo 2.18 but removed in Dynamo 2.19. So this would mean adding these code back but conditionally (in-process integration)

}

/// <summary>
/// Add a new HomeWorkspace and set as current
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/DynamoCore/Properties/Resources.Designer.cs

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

2 changes: 1 addition & 1 deletion src/DynamoCore/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ This package likely contains an assembly that is blocked. You will need to load
<value>Example file added to workspace. Run mode changed to Manual.</value>
</data>
<data name="DynamoLanguages_noxlate" xml:space="preserve">
<value>English,Čeština,Deutsch,Español,Français,Italiano,日本語,한국어,Polski,Português (Brasil),Русский,简体中文,繁體中文</value>
<value>Default,English,Čeština,Deutsch,Español,Français,Italiano,日本語,한국어,Polski,Português (Brasil),Русский,简体中文,繁體中文</value>
</data>
<data name="FormulaDSConversionFailure" xml:space="preserve">
<value>Formula failed to convert to DesignScript code. Please edit the formula manually to use it in a CodeBlock node.</value>
Expand Down
2 changes: 1 addition & 1 deletion src/DynamoCore/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ This package likely contains an assembly that is blocked. You will need to load
<value>Example file added to workspace. Run mode changed to Manual.</value>
</data>
<data name="DynamoLanguages_noxlate" xml:space="preserve">
<value>English,Čeština,Deutsch,Español,Français,Italiano,日本語,한국어,Polski,Português (Brasil),Русский,简体中文,繁體中文</value>
<value>Default,English,Čeština,Deutsch,Español,Français,Italiano,日本語,한국어,Polski,Português (Brasil),Русский,简体中文,繁體中文</value>
</data>
<data name="FormulaDSConversionFailure" xml:space="preserve">
<value>Formula failed to convert to DesignScript code. Please edit the formula manually to use it in a CodeBlock node.</value>
Expand Down
4 changes: 2 additions & 2 deletions test/DynamoCoreTests/Configuration/PreferenceSettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Loading