Skip to content

Commit

Permalink
fix language CLI argument
Browse files Browse the repository at this point in the history
  • Loading branch information
chubakueno committed Dec 31, 2024
1 parent 57ecd2f commit d5ef1ba
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 38 deletions.
82 changes: 46 additions & 36 deletions src/DynamoApplications/StartupUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,36 @@ public static void PreloadShapeManager(ref string geometryFactoryPath, ref strin
geometryFactoryPath = preloader.GeometryFactoryPath;
preloaderLocation = preloader.PreloaderLocation;
}

/// <summary>
/// Use this overload to construct a DynamoModel in CLI context when the location of ASM to use is known, host analytics info is known and you want to set data paths.
/// </summary>
/// <param name="asmPath">Path to directory containing geometry library binaries</param>
/// <param name="userDataFolder">Path to be used by PathResolver for UserDataFolder</param>
/// <param name="commonDataFolder">Path to be used by PathResolver for CommonDataFolder</param>
/// <param name="info">Host analytics info specifying Dynamo launching host related information.</param>
/// <returns></returns>
public static DynamoModel MakeCLIModel(string asmPath, string userDataFolder, string commonDataFolder, HostAnalyticsInfo info = new HostAnalyticsInfo())
public static DynamoModel PrepareModel(
string cliLocale,
string asmPath,
bool noNetworkMode,
HostAnalyticsInfo analyticsInfo,
bool cliMode = true,
string userDataFolder = "",
string commonDataFolder = "",
bool serviceMode = false)
{
var normalizedCLILocale = string.IsNullOrEmpty(cliLocale) ? null : cliLocale;
IPathResolver pathResolver = CreatePathResolver(false, string.Empty, string.Empty, string.Empty);
PathManager.Instance.AssignHostPathAndIPathResolver(string.Empty, pathResolver);
DynamoModel.SetUICulture(normalizedCLILocale ?? PreferenceSettings.Instance.Locale);
DynamoModel.OnDetectLanguage();

// Preload ASM and display corresponding message on splash screen
DynamoModel.OnRequestUpdateLoadBarStatus(new SplashScreenLoadEventArgs(Resources.SplashScreenPreLoadingAsm, 10));
var isASMloaded = PreloadASM(asmPath, out string geometryFactoryPath, out string preloaderLocation);
var model = StartDynamoWithDefaultConfig(true, userDataFolder, commonDataFolder, geometryFactoryPath, preloaderLocation, false, info);
var model = StartDynamoWithDefaultConfig(
CLImode: cliMode,
userDataFolder: userDataFolder,
commonDataFolder: commonDataFolder,
geometryFactoryPath: geometryFactoryPath,
preloaderLocation: preloaderLocation,
noNetworkMode: noNetworkMode,
info: analyticsInfo,
isServiceMode: serviceMode,
cliLocale: normalizedCLILocale
);
model.IsASMLoaded = isASMloaded;
return model;
}
Expand All @@ -193,18 +208,15 @@ public static void PreloadShapeManager(ref string geometryFactoryPath, ref strin
/// <returns></returns>
public static DynamoModel MakeCLIModel(CommandLineArguments cmdLineArgs)
{
var asmPath = String.IsNullOrEmpty(cmdLineArgs.ASMPath) ? string.Empty : cmdLineArgs.ASMPath;
IPathResolver pathResolver = CreatePathResolver(false, string.Empty, string.Empty, string.Empty);
PathManager.Instance.AssignHostPathAndIPathResolver(string.Empty, pathResolver);
DynamoModel.SetUICulture(PreferenceSettings.Instance.Locale);
DynamoModel.OnDetectLanguage();

// Preload ASM and display corresponding message on splash screen
DynamoModel.OnRequestUpdateLoadBarStatus(new SplashScreenLoadEventArgs(Resources.SplashScreenPreLoadingAsm, 10));
var isASMloaded = PreloadASM(asmPath, out string geometryFactoryPath, out string preloaderLocation);
var model = StartDynamoWithDefaultConfig(true, cmdLineArgs.UserDataFolder, cmdLineArgs.CommonDataFolder,
geometryFactoryPath, preloaderLocation, cmdLineArgs.NoNetworkMode, cmdLineArgs.AnalyticsInfo, cmdLineArgs.ServiceMode);
model.IsASMLoaded = isASMloaded;
var asmPath = string.IsNullOrEmpty(cmdLineArgs.ASMPath) ? string.Empty : cmdLineArgs.ASMPath;
var model = PrepareModel(
cliLocale: cmdLineArgs.Locale,
asmPath: asmPath,
noNetworkMode: cmdLineArgs.NoNetworkMode,
analyticsInfo: cmdLineArgs.AnalyticsInfo,
userDataFolder: cmdLineArgs.UserDataFolder,
commonDataFolder: cmdLineArgs.CommonDataFolder,
serviceMode: cmdLineArgs.ServiceMode);
return model;
}

Expand All @@ -228,23 +240,19 @@ public static DynamoModel MakeModel(bool CLImode, string asmPath = "", string ho
/// Use this overload to construct a DynamoModel when the location of ASM to use is known and host analytics info is known.
/// </summary>
/// <param name="CLImode">CLI mode starts the model in test mode and uses a separate path resolver.</param>
/// <param name="CLIlocale">CLI argument to force dynamo locale</param>
/// <param name="noNetworkMode">Option to initialize Dynamo in no-network mode</param>
/// <param name="asmPath">Path to directory containing geometry library binaries</param>
/// <param name="info">Host analytics info specifying Dynamo launching host related information.</param>
/// <returns></returns>
public static DynamoModel MakeModel(bool CLImode, bool noNetworkMode, string asmPath = "", HostAnalyticsInfo info = new HostAnalyticsInfo())
public static DynamoModel MakeModel(bool CLImode, string CLIlocale, bool noNetworkMode, string asmPath = "", HostAnalyticsInfo info = new HostAnalyticsInfo())
{
IPathResolver pathResolver = CreatePathResolver(false, string.Empty, string.Empty, string.Empty);
PathManager.Instance.AssignHostPathAndIPathResolver(string.Empty, pathResolver);
DynamoModel.SetUICulture(PreferenceSettings.Instance.Locale);
DynamoModel.OnDetectLanguage();

// Preload ASM and display corresponding message on splash screen
DynamoModel.OnRequestUpdateLoadBarStatus(new SplashScreenLoadEventArgs(Resources.SplashScreenPreLoadingAsm, 10));
var isASMloaded = PreloadASM(asmPath, out string geometryFactoryPath, out string preloaderLocation);
var model = StartDynamoWithDefaultConfig(CLImode, string.Empty, string.Empty, geometryFactoryPath,
preloaderLocation, noNetworkMode, info);
model.IsASMLoaded = isASMloaded;
var model = PrepareModel(
cliLocale: CLIlocale,
asmPath: asmPath,
noNetworkMode: noNetworkMode,
analyticsInfo: info,
cliMode: CLImode);
return model;
}

Expand Down Expand Up @@ -322,7 +330,8 @@ private static DynamoModel StartDynamoWithDefaultConfig(bool CLImode,
string preloaderLocation,
bool noNetworkMode,
HostAnalyticsInfo info = new HostAnalyticsInfo(),
bool isServiceMode = false)
bool isServiceMode = false,
string cliLocale = null)
{

var config = new DynamoModel.DefaultStartConfiguration
Expand All @@ -337,6 +346,7 @@ private static DynamoModel StartDynamoWithDefaultConfig(bool CLImode,
IsServiceMode = isServiceMode,
Preferences = PreferenceSettings.Instance,
NoNetworkMode = noNetworkMode,
CLILocale = cliLocale,
//Breaks all Lucene calls. TI enable this would require a lot of refactoring around Lucene usage in Dynamo.
//IsHeadless = CLImode
};
Expand Down
9 changes: 8 additions & 1 deletion src/DynamoCore/Models/DynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ public static string Version
/// </summary>
internal bool NoNetworkMode { get; }

/// <summary>
/// Locale forced by cli arguments
/// </summary>
internal string CLILocale { get; set; }

/// <summary>
/// The path manager that configures path information required for
/// Dynamo to function properly. See IPathManager interface for more
Expand Down Expand Up @@ -589,6 +594,7 @@ public struct DefaultStartConfiguration : IStartConfiguration
/// CLIMode indicates if we are running in DynamoCLI or DynamoWPFCLI mode.
/// </summary>
public bool CLIMode { get; set; }
public string CLILocale { get; set; }
}

/// <summary>
Expand Down Expand Up @@ -635,6 +641,7 @@ protected DynamoModel(IStartConfiguration config)
DefaultPythonEngine = defaultStartConfig.DefaultPythonEngine;
CLIMode = defaultStartConfig.CLIMode;
IsServiceMode = defaultStartConfig.IsServiceMode;
CLILocale = defaultStartConfig.CLILocale;
}

if (config is IStartConfigCrashReporter cerConfig)
Expand Down Expand Up @@ -685,7 +692,7 @@ protected DynamoModel(IStartConfiguration config)

if (PreferenceSettings != null)
{
SetUICulture(PreferenceSettings.Locale);
SetUICulture(CLILocale ?? PreferenceSettings.Locale);
PreferenceSettings.PropertyChanged += PreferenceSettings_PropertyChanged;
PreferenceSettings.MessageLogged += LogMessage;
}
Expand Down
2 changes: 2 additions & 0 deletions src/DynamoCore/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1813,6 +1813,8 @@ Dynamo.Models.DynamoModel.CurrentWorkspace.set -> void
Dynamo.Models.DynamoModel.DefaultStartConfiguration
Dynamo.Models.DynamoModel.DefaultStartConfiguration.AuthProvider.get -> Greg.IAuthProvider
Dynamo.Models.DynamoModel.DefaultStartConfiguration.AuthProvider.set -> void
Dynamo.Models.DynamoModel.DefaultStartConfiguration.CLILocale.get -> string
Dynamo.Models.DynamoModel.DefaultStartConfiguration.CLILocale.set -> void
Dynamo.Models.DynamoModel.DefaultStartConfiguration.CLIMode.get -> bool
Dynamo.Models.DynamoModel.DefaultStartConfiguration.CLIMode.set -> void
Dynamo.Models.DynamoModel.DefaultStartConfiguration.Context.get -> string
Expand Down
4 changes: 3 additions & 1 deletion src/DynamoSandbox/DynamoCoreSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class DynamoCoreSetup
private readonly string ASMPath;
private readonly HostAnalyticsInfo analyticsInfo;
private readonly bool noNetworkMode;
private readonly string CLILocale;
private const string sandboxWikiPage = @"https://github.com/DynamoDS/Dynamo/wiki/How-to-Utilize-Dynamo-Builds";
private DynamoViewModel viewModel = null;

Expand Down Expand Up @@ -59,6 +60,7 @@ public DynamoCoreSetup(string[] args)
// HostVersion = new Version(3, 3, 0),
//};
noNetworkMode = cmdLineArgs.NoNetworkMode;
CLILocale = cmdLineArgs.Locale;
}

public void RunApplication(Application app)
Expand Down Expand Up @@ -140,7 +142,7 @@ public void RunApplication(Application app)
private void LoadDynamoView()
{
DynamoModel model;
model = StartupUtils.MakeModel(false, noNetworkMode, ASMPath ?? string.Empty, analyticsInfo);
model = StartupUtils.MakeModel(false, CLILocale, noNetworkMode, ASMPath ?? string.Empty, analyticsInfo);
model.CERLocation = CERLocation;

viewModel = DynamoViewModel.Start(
Expand Down

0 comments on commit d5ef1ba

Please sign in to comment.