Skip to content

Commit 129310d

Browse files
Merge branch 'master' into DYN-9970-FixingLibrary-Group-DocumentationB
2 parents 28b4ee1 + 795ddd9 commit 129310d

7 files changed

Lines changed: 47 additions & 21 deletions

File tree

src/DynamoApplications/StartupUtils.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -470,32 +470,34 @@ private static DynamoModel StartDynamoWithDefaultConfig(bool CLImode,
470470
return model;
471471
}
472472

473+
/// <summary>
474+
/// Sets the application locale from parsed command-line arguments.
475+
/// </summary>
476+
/// <param name="cmdLineArgs">Parsed command-line arguments.</param>
477+
/// <returns>A locale environment string in the format <c>LANGUAGE=xx_YY</c> for the resolved locale.</returns>
478+
[Obsolete("The API has been deprecated and will be removed in a future release of Dynamo. Make a direct call to DynamoModel.SetUICulture instead.")]
473479
public static string SetLocale(CommandLineArguments cmdLineArgs)
474480
{
475-
var supportedLocale = new HashSet<string>(Configuration.Configurations.SupportedLocaleDic.Values);
476-
string libgLocale = string.Empty;
481+
var supportedLocale = new HashSet<string>(Configurations.SupportedLocaleDic.Values);
482+
string locale = string.Empty;
477483

478484
if (!string.IsNullOrEmpty(cmdLineArgs.Locale))
479485
{
480-
// Change the application locale, if a locale information is supplied.
481486
DynamoModel.SetUICulture(cmdLineArgs.Locale);
482-
libgLocale = cmdLineArgs.Locale;
487+
locale = cmdLineArgs.Locale;
483488
}
484489
else
485490
{
486-
// In case no language is specified, libG's locale should be that of the OS.
487-
// There is no need to set Dynamo's locale in this case.
488-
libgLocale = CultureInfo.InstalledUICulture.ToString();
491+
locale = CultureInfo.InstalledUICulture.ToString();
489492
}
490493

491494
// If locale is not supported by Dynamo, default to en-US.
492-
if (!supportedLocale.Any(s => s.Equals(libgLocale, StringComparison.InvariantCultureIgnoreCase)))
495+
if (!supportedLocale.Any(s => s.Equals(locale, StringComparison.InvariantCultureIgnoreCase)))
493496
{
494-
libgLocale = "en-US";
497+
locale = "en-US";
495498
}
496-
// Change the locale that LibG depends on.
497499
StringBuilder sb = new StringBuilder("LANGUAGE=");
498-
sb.Append(libgLocale.Replace("-", "_"));
500+
sb.Append(locale.Replace("-", "_"));
499501
return sb.ToString();
500502
}
501503

src/DynamoCLI/Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ internal static void Main(string[] args)
2020
{
2121
var cmdLineArgs = StartupUtils.CommandLineArguments.Parse(args);
2222
useConsole = !cmdLineArgs.NoConsole;
23-
var locale = StartupUtils.SetLocale(cmdLineArgs);
23+
if (!string.IsNullOrEmpty(cmdLineArgs.Locale))
24+
{
25+
DynamoModel.SetUICulture(cmdLineArgs.Locale);
26+
}
2427

2528
cmdLineArgs.SetDisableAnalytics();
2629

src/DynamoSandbox/DynamoCoreSetup.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Diagnostics;
33
using System.Linq;
4-
using System.Runtime.InteropServices;
54
using System.Windows;
65
using Dynamo.Applications;
76
using Dynamo.Controls;
@@ -28,18 +27,19 @@ class DynamoCoreSetup
2827
private const string sandboxWikiPage = @"https://github.com/DynamoDS/Dynamo/wiki/How-to-Utilize-Dynamo-Builds";
2928
private DynamoViewModel viewModel = null;
3029

31-
[DllImport("msvcrt.dll")]
32-
public static extern int _putenv(string env);
33-
3430
/// <summary>
3531
/// Constructor
3632
/// </summary>
3733
/// <param name="args"></param>
3834
public DynamoCoreSetup(string[] args)
3935
{
4036
var cmdLineArgs = StartupUtils.CommandLineArguments.Parse(args);
41-
var locale = StartupUtils.SetLocale(cmdLineArgs);
42-
_putenv(locale);
37+
// Set locale early so the splash screen renders in the correct language;
38+
// DynamoModel construction will also call SetUICulture from preferences.
39+
if (!string.IsNullOrEmpty(cmdLineArgs.Locale))
40+
{
41+
DynamoModel.SetUICulture(cmdLineArgs.Locale);
42+
}
4343

4444
cmdLineArgs.SetDisableAnalytics();
4545

src/DynamoWPFCLI/Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ internal static void Main(string[] args)
2828
{
2929
var cmdLineArgs = StartupUtils.CommandLineArguments.Parse(args);
3030
useConsole = !cmdLineArgs.NoConsole;
31-
var locale = StartupUtils.SetLocale(cmdLineArgs);
31+
if (!string.IsNullOrEmpty(cmdLineArgs.Locale))
32+
{
33+
DynamoModel.SetUICulture(cmdLineArgs.Locale);
34+
}
3235

3336
cmdLineArgs.SetDisableAnalytics();
3437

src/Engine/ProtoCore/FFI/ExtensionAppLoader.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,15 @@ private void InitializeExtensionApp(Assembly assembly)
169169

170170
if (null != extensionApp)
171171
{
172-
extensionApp.StartUp(new ExtensionStartupParams { DisableADP = Analytics.DisableAnalytics });
172+
extensionApp.StartUp(new ExtensionStartupParams
173+
{
174+
DisableADP = Analytics.DisableAnalytics,
175+
// If the extension app is initialized on a thread that hasn’t had DynamoModel.SetUICulture applied
176+
// (or had it changed later), Locale can differ from Dynamo’s resolved UI culture and
177+
// LibG/gettext will be set to the wrong language. This therefore assumes that the extension app is
178+
// initialized on the same thread as DynamoModel.SetUICulture, which is currently the case.
179+
Locale = System.Threading.Thread.CurrentThread.CurrentUICulture.Name
180+
});
173181
}
174182
}
175183

src/NodeServices/Interfaces.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33

44
namespace Autodesk.DesignScript.Interfaces
@@ -154,6 +154,15 @@ public bool DisableADP
154154
get;
155155
set;
156156
}
157+
158+
/// <summary>
159+
/// Gets the locale to use during extension startup, expressed as a
160+
/// BCP 47 culture name such as <c>en-US</c>
161+
/// (see <see cref="System.Globalization.CultureInfo.Name"/>).
162+
/// A <see langword="null"/> or empty value indicates that no explicit
163+
/// locale was provided by the host.
164+
/// </summary>
165+
public string Locale { get; internal set; }
157166
}
158167

159168
/// <summary>

src/NodeServices/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
Autodesk.DesignScript.Interfaces.ExtensionStartupParams.Locale.get -> string
12
Dynamo.Graph.Nodes.NodeCategoryAttribute
23
Dynamo.Graph.Nodes.NodeCategoryAttribute.ElementCategory.get -> string
34
Dynamo.Graph.Nodes.NodeCategoryAttribute.ElementCategory.set -> void

0 commit comments

Comments
 (0)