Skip to content

Commit

Permalink
update dynamo locale based on setting or host
Browse files Browse the repository at this point in the history
  • Loading branch information
QilongTang committed Oct 16, 2023
1 parent 5f30633 commit c3518e0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
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
15 changes: 15 additions & 0 deletions src/DynamoCore/Models/DynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -2698,6 +2704,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);
}

/// <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

0 comments on commit c3518e0

Please sign in to comment.