Extract localizable strings from dotnet-run (#4769)
* Localization changes for dotnet-run * Fixed LocalizableString to correctly be LocalizableStrings * Localization changes for dotnet-restoreProjectJson * Loclization changes for dotnet-restore command. * Update Program.cs
This commit is contained in:
parent
a57b9e5d01
commit
706b8a802d
7 changed files with 124 additions and 35 deletions
|
@ -0,0 +1,9 @@
|
|||
namespace Microsoft.DotNet.Tools.RestoreProjectJson
|
||||
{
|
||||
internal class LocalizableStrings
|
||||
{
|
||||
public const string AddMinimal = "minimal";
|
||||
|
||||
public const string AddRestore = "restore";
|
||||
}
|
||||
}
|
|
@ -13,9 +13,9 @@ namespace Microsoft.DotNet.Tools.RestoreProjectJson
|
|||
if (!args.Any(s => s.Equals("--verbosity", StringComparison.OrdinalIgnoreCase) || s.Equals("-v", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
prefixArgs.Add("--verbosity");
|
||||
prefixArgs.Add("minimal");
|
||||
prefixArgs.Add(LocalizableStrings.AddMinimal);
|
||||
}
|
||||
prefixArgs.Add("restore");
|
||||
prefixArgs.Add(LocalizableStrings.AddRestore);
|
||||
|
||||
var nugetApp = new NuGetForwardingApp(Enumerable.Concat(prefixArgs, args));
|
||||
|
||||
|
|
33
src/dotnet/commands/dotnet-restore/LocalizableStrings.cs
Normal file
33
src/dotnet/commands/dotnet-restore/LocalizableStrings.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
namespace Microsoft.DotNet.Tools.Restore
|
||||
{
|
||||
internal class LocalizableStrings
|
||||
{
|
||||
public const string AppFullName = "restore";
|
||||
|
||||
public const string AppDescription = "restore for msbuild";
|
||||
|
||||
public const string CmdArgument = "root";
|
||||
|
||||
public const string CmdArgumentDescription = "Optional path to a project file or MSBuild arguments.";
|
||||
|
||||
public const string CmdSourceOption = "source";
|
||||
|
||||
public const string CmdSourceOptionDescription = "Specifies a NuGet package source to use during the restore.";
|
||||
|
||||
public const string CmdPackagesOption = "packagesDirectory";
|
||||
|
||||
public const string CmdPackagesOptionDescription = "Directory to install packages in.";
|
||||
|
||||
public const string CmdDisableParallelOptionDescription = "Disables restoring multiple projects in parallel.";
|
||||
|
||||
public const string CmdConfigFileOption = "file";
|
||||
|
||||
public const string CmdConfigFileOptionDescription = "The NuGet configuration file to use.";
|
||||
|
||||
public const string CmdNoCacheOptionDescription = "Do not cache packages and http requests.";
|
||||
|
||||
public const string CmdIgnoreFailedSourcesOptionDescription = "Treat package source failures as warnings.";
|
||||
|
||||
public const string CmdNoDependenciesOptionDescription = "Set this flag to ignore project to project references and only restore the root project";
|
||||
}
|
||||
}
|
|
@ -17,8 +17,8 @@ namespace Microsoft.DotNet.Tools.Restore
|
|||
CommandLineApplication cmd = new CommandLineApplication(throwOnUnexpectedArg: false)
|
||||
{
|
||||
Name = "restore",
|
||||
FullName = "restore",
|
||||
Description = "restore for msbuild",
|
||||
FullName = LocalizableStrings.AppFullName,
|
||||
Description = LocalizableStrings.AppDescription,
|
||||
AllowArgumentSeparator = true,
|
||||
ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText
|
||||
};
|
||||
|
@ -26,43 +26,43 @@ namespace Microsoft.DotNet.Tools.Restore
|
|||
cmd.HelpOption("-h|--help");
|
||||
|
||||
var argRoot = cmd.Argument(
|
||||
"[root]",
|
||||
"Optional path to a project file or MSBuild arguments.",
|
||||
"[{LocalizableStrings.CmdArgument}]",
|
||||
LocalizableStrings.CmdArgumentDescription,
|
||||
multipleValues: true);
|
||||
|
||||
var sourceOption = cmd.Option(
|
||||
"-s|--source <source>",
|
||||
"Specifies a NuGet package source to use during the restore.",
|
||||
"-s|--source <{LocalizableStrings.CmdSourceOption}>",
|
||||
LocalizableStrings.CmdSourceOptionDescription,
|
||||
CommandOptionType.MultipleValue);
|
||||
|
||||
var packagesOption = cmd.Option(
|
||||
"--packages <packagesDirectory>",
|
||||
"Directory to install packages in.",
|
||||
"--packages <{LocalizableStrings.CmdPackagesOption}>",
|
||||
LocalizableStrings.CmdPackagesOptionDescription,
|
||||
CommandOptionType.SingleValue);
|
||||
|
||||
var disableParallelOption = cmd.Option(
|
||||
"--disable-parallel",
|
||||
"Disables restoring multiple projects in parallel.",
|
||||
LocalizableStrings.CmdDisableParallelOptionDescription,
|
||||
CommandOptionType.NoValue);
|
||||
|
||||
var configFileOption = cmd.Option(
|
||||
"--configfile <file>",
|
||||
"The NuGet configuration file to use.",
|
||||
"--configfile <{LocalizableStrings.CmdConfigFileOption}>",
|
||||
LocalizableStrings.CmdConfigFileOptionDescription,
|
||||
CommandOptionType.SingleValue);
|
||||
|
||||
var noCacheOption = cmd.Option(
|
||||
"--no-cache",
|
||||
"Do not cache packages and http requests.",
|
||||
LocalizableStrings.CmdNoCacheOptionDescription,
|
||||
CommandOptionType.NoValue);
|
||||
|
||||
var ignoreFailedSourcesOption = cmd.Option(
|
||||
"--ignore-failed-sources",
|
||||
"Treat package source failures as warnings.",
|
||||
LocalizableStrings.CmdIgnoreFailedSourcesOptionDescription,
|
||||
CommandOptionType.NoValue);
|
||||
|
||||
var noDependenciesOption = cmd.Option(
|
||||
"--no-dependencies",
|
||||
"Set this flag to ignore project to project references and only restore the root project",
|
||||
LocalizableStrings.CmdNoDependenciesOptionDescription,
|
||||
CommandOptionType.NoValue);
|
||||
|
||||
CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(cmd);
|
||||
|
|
47
src/dotnet/commands/dotnet-run/LocalizableStrings.cs
Normal file
47
src/dotnet/commands/dotnet-run/LocalizableStrings.cs
Normal file
|
@ -0,0 +1,47 @@
|
|||
namespace Microsoft.DotNet.Tools.Run
|
||||
{
|
||||
internal class LocalizableStrings
|
||||
{
|
||||
public const string AppFullName = ".NET Run Command";
|
||||
|
||||
public const string AppDescription = "Command used to run .NET apps";
|
||||
|
||||
public const string CommandOptionConfigurationDescription = "Configuration under which to build";
|
||||
|
||||
public const string CommandOptionFramework = "FRAMEWORK";
|
||||
|
||||
public const string CommandOptionFrameworkDescription = "Compile a specific framework";
|
||||
|
||||
public const string CommandOptionProjectDescription = "The path to the project file to run (defaults to the current directory if there is only one project).";
|
||||
|
||||
public const string RunCommandException = "The build failed. Please fix the build errors and run again.";
|
||||
|
||||
public const string RunCommandMSBuildExtensionsPath = "MSBuildExtensionsPath";
|
||||
|
||||
public const string RunCommandConfiguration = "Configuration";
|
||||
|
||||
public const string RunCommandTargetFramework = "TargetFramework";
|
||||
|
||||
public const string RunCommandProjectInstance = "RunCommand";
|
||||
|
||||
public const string RunCommandOutputType = "OutputType";
|
||||
|
||||
public const string RunCommandExceptionUnableToRun1 = "Unable to run your project.";
|
||||
|
||||
public const string RunCommandExceptionUnableToRun2 = "Please ensure you have a runnable project type and ensure 'dotnet run' supports this project.";
|
||||
|
||||
public const string RunCommandExceptionUnableToRun3 = "The current OutputType is ";
|
||||
|
||||
public const string RunCommandRunArguments = "RunArguments";
|
||||
|
||||
public const string RunCommandRunWorkingDirectory = "RunWorkingDirectory";
|
||||
|
||||
public const string RunCommandInvalidOperationException1 = "Couldn't find a project to run. Ensure a project exists in ";
|
||||
|
||||
public const string RunCommandInvalidOperationException2 = "Or pass the path to the project using --project";
|
||||
|
||||
public const string RunCommandInvalidOperationException3 = "Specify which project file to use because this ";
|
||||
|
||||
public const string RunCommandInvalidOperationException4 = "contains more than one project file.";
|
||||
}
|
||||
}
|
|
@ -15,21 +15,21 @@ namespace Microsoft.DotNet.Tools.Run
|
|||
|
||||
CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false);
|
||||
app.Name = "dotnet run";
|
||||
app.FullName = ".NET Run Command";
|
||||
app.Description = "Command used to run .NET apps";
|
||||
app.FullName = LocalizableStrings.AppFullName;
|
||||
app.Description = LocalizableStrings.AppDescription;
|
||||
app.HandleResponseFiles = true;
|
||||
app.AllowArgumentSeparator = true;
|
||||
app.ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText;
|
||||
app.HelpOption("-h|--help");
|
||||
|
||||
CommandOption configuration = app.Option(
|
||||
"-c|--configuration", "Configuration under which to build",
|
||||
"-c|--configuration", LocalizableStrings.CommandOptionConfigurationDescription,
|
||||
CommandOptionType.SingleValue);
|
||||
CommandOption framework = app.Option(
|
||||
"-f|--framework <FRAMEWORK>", "Compile a specific framework",
|
||||
"-f|--framework <{LocalizableStrings.CommandOptionFramework}>", LocalizableStrings.CommandOptionFrameworkDescription,
|
||||
CommandOptionType.SingleValue);
|
||||
CommandOption project = app.Option(
|
||||
"-p|--project", "The path to the project file to run (defaults to the current directory if there is only one project).",
|
||||
"-p|--project", LocalizableStrings.CommandOptionProjectDescription,
|
||||
CommandOptionType.SingleValue);
|
||||
|
||||
app.OnExecute(() =>
|
||||
|
|
|
@ -61,7 +61,7 @@ namespace Microsoft.DotNet.Tools.Run
|
|||
if (buildResult != 0)
|
||||
{
|
||||
Reporter.Error.WriteLine();
|
||||
throw new GracefulException("The build failed. Please fix the build errors and run again.");
|
||||
throw new GracefulException(LocalizableStrings.RunCommandException);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,34 +69,34 @@ namespace Microsoft.DotNet.Tools.Run
|
|||
{
|
||||
Dictionary<string, string> globalProperties = new Dictionary<string, string>()
|
||||
{
|
||||
{ "MSBuildExtensionsPath", AppContext.BaseDirectory }
|
||||
{ LocalizableStrings.RunCommandMSBuildExtensionsPath, AppContext.BaseDirectory }
|
||||
};
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Configuration))
|
||||
{
|
||||
globalProperties.Add("Configuration", Configuration);
|
||||
globalProperties.Add(LocalizableStrings.RunCommandConfiguration, Configuration);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Framework))
|
||||
{
|
||||
globalProperties.Add("TargetFramework", Framework);
|
||||
globalProperties.Add(LocalizableStrings.RunCommandTargetFramework, Framework);
|
||||
}
|
||||
|
||||
ProjectInstance projectInstance = new ProjectInstance(Project, globalProperties, null);
|
||||
|
||||
string runProgram = projectInstance.GetPropertyValue("RunCommand");
|
||||
string runProgram = projectInstance.GetPropertyValue(LocalizableStrings.RunCommandProjectInstance);
|
||||
if (string.IsNullOrEmpty(runProgram))
|
||||
{
|
||||
string outputType = projectInstance.GetPropertyValue("OutputType");
|
||||
string outputType = projectInstance.GetPropertyValue(LocalizableStrings.RunCommandOutputType);
|
||||
|
||||
throw new GracefulException(string.Join(Environment.NewLine,
|
||||
"Unable to run your project.",
|
||||
"Please ensure you have a runnable project type and ensure 'dotnet run' supports this project.",
|
||||
$"The current OutputType is '{outputType}'."));
|
||||
LocalizableStrings.RunCommandExceptionUnableToRun1,
|
||||
LocalizableStrings.RunCommandExceptionUnableToRun2,
|
||||
$"{LocalizableStrings.RunCommandExceptionUnableToRun3} '{outputType}'."));
|
||||
}
|
||||
|
||||
string runArguments = projectInstance.GetPropertyValue("RunArguments");
|
||||
string runWorkingDirectory = projectInstance.GetPropertyValue("RunWorkingDirectory");
|
||||
string runArguments = projectInstance.GetPropertyValue(LocalizableStrings.RunCommandRunArguments);
|
||||
string runWorkingDirectory = projectInstance.GetPropertyValue(LocalizableStrings.RunCommandRunWorkingDirectory);
|
||||
|
||||
string fullArguments = runArguments;
|
||||
if (_args.Any())
|
||||
|
@ -120,13 +120,13 @@ namespace Microsoft.DotNet.Tools.Run
|
|||
if (projectFiles.Length == 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Couldn't find a project to run. Ensure a project exists in {directory}." + Environment.NewLine +
|
||||
"Or pass the path to the project using --project");
|
||||
$"{LocalizableStrings.RunCommandInvalidOperationException1} {directory}." + Environment.NewLine +
|
||||
LocalizableStrings.RunCommandInvalidOperationException2);
|
||||
}
|
||||
else if (projectFiles.Length > 1)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Specify which project file to use because this '{directory}' contains more than one project file.");
|
||||
$"{LocalizableStrings.RunCommandInvalidOperationException3}'{directory}'{LocalizableStrings.RunCommandInvalidOperationException4}");
|
||||
}
|
||||
|
||||
Project = projectFiles[0];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue