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:
Scott Carlton 2016-11-19 11:45:46 -08:00 committed by Piotr Puszkiewicz
parent a57b9e5d01
commit 706b8a802d
7 changed files with 124 additions and 35 deletions

View file

@ -0,0 +1,9 @@
namespace Microsoft.DotNet.Tools.RestoreProjectJson
{
internal class LocalizableStrings
{
public const string AddMinimal = "minimal";
public const string AddRestore = "restore";
}
}

View file

@ -13,9 +13,9 @@ namespace Microsoft.DotNet.Tools.RestoreProjectJson
if (!args.Any(s => s.Equals("--verbosity", StringComparison.OrdinalIgnoreCase) || s.Equals("-v", StringComparison.OrdinalIgnoreCase))) if (!args.Any(s => s.Equals("--verbosity", StringComparison.OrdinalIgnoreCase) || s.Equals("-v", StringComparison.OrdinalIgnoreCase)))
{ {
prefixArgs.Add("--verbosity"); 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)); var nugetApp = new NuGetForwardingApp(Enumerable.Concat(prefixArgs, args));

View 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";
}
}

View file

@ -17,8 +17,8 @@ namespace Microsoft.DotNet.Tools.Restore
CommandLineApplication cmd = new CommandLineApplication(throwOnUnexpectedArg: false) CommandLineApplication cmd = new CommandLineApplication(throwOnUnexpectedArg: false)
{ {
Name = "restore", Name = "restore",
FullName = "restore", FullName = LocalizableStrings.AppFullName,
Description = "restore for msbuild", Description = LocalizableStrings.AppDescription,
AllowArgumentSeparator = true, AllowArgumentSeparator = true,
ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText
}; };
@ -26,43 +26,43 @@ namespace Microsoft.DotNet.Tools.Restore
cmd.HelpOption("-h|--help"); cmd.HelpOption("-h|--help");
var argRoot = cmd.Argument( var argRoot = cmd.Argument(
"[root]", "[{LocalizableStrings.CmdArgument}]",
"Optional path to a project file or MSBuild arguments.", LocalizableStrings.CmdArgumentDescription,
multipleValues: true); multipleValues: true);
var sourceOption = cmd.Option( var sourceOption = cmd.Option(
"-s|--source <source>", "-s|--source <{LocalizableStrings.CmdSourceOption}>",
"Specifies a NuGet package source to use during the restore.", LocalizableStrings.CmdSourceOptionDescription,
CommandOptionType.MultipleValue); CommandOptionType.MultipleValue);
var packagesOption = cmd.Option( var packagesOption = cmd.Option(
"--packages <packagesDirectory>", "--packages <{LocalizableStrings.CmdPackagesOption}>",
"Directory to install packages in.", LocalizableStrings.CmdPackagesOptionDescription,
CommandOptionType.SingleValue); CommandOptionType.SingleValue);
var disableParallelOption = cmd.Option( var disableParallelOption = cmd.Option(
"--disable-parallel", "--disable-parallel",
"Disables restoring multiple projects in parallel.", LocalizableStrings.CmdDisableParallelOptionDescription,
CommandOptionType.NoValue); CommandOptionType.NoValue);
var configFileOption = cmd.Option( var configFileOption = cmd.Option(
"--configfile <file>", "--configfile <{LocalizableStrings.CmdConfigFileOption}>",
"The NuGet configuration file to use.", LocalizableStrings.CmdConfigFileOptionDescription,
CommandOptionType.SingleValue); CommandOptionType.SingleValue);
var noCacheOption = cmd.Option( var noCacheOption = cmd.Option(
"--no-cache", "--no-cache",
"Do not cache packages and http requests.", LocalizableStrings.CmdNoCacheOptionDescription,
CommandOptionType.NoValue); CommandOptionType.NoValue);
var ignoreFailedSourcesOption = cmd.Option( var ignoreFailedSourcesOption = cmd.Option(
"--ignore-failed-sources", "--ignore-failed-sources",
"Treat package source failures as warnings.", LocalizableStrings.CmdIgnoreFailedSourcesOptionDescription,
CommandOptionType.NoValue); CommandOptionType.NoValue);
var noDependenciesOption = cmd.Option( var noDependenciesOption = cmd.Option(
"--no-dependencies", "--no-dependencies",
"Set this flag to ignore project to project references and only restore the root project", LocalizableStrings.CmdNoDependenciesOptionDescription,
CommandOptionType.NoValue); CommandOptionType.NoValue);
CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(cmd); CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(cmd);

View 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.";
}
}

View file

@ -15,21 +15,21 @@ namespace Microsoft.DotNet.Tools.Run
CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false); CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false);
app.Name = "dotnet run"; app.Name = "dotnet run";
app.FullName = ".NET Run Command"; app.FullName = LocalizableStrings.AppFullName;
app.Description = "Command used to run .NET apps"; app.Description = LocalizableStrings.AppDescription;
app.HandleResponseFiles = true; app.HandleResponseFiles = true;
app.AllowArgumentSeparator = true; app.AllowArgumentSeparator = true;
app.ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText; app.ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText;
app.HelpOption("-h|--help"); app.HelpOption("-h|--help");
CommandOption configuration = app.Option( CommandOption configuration = app.Option(
"-c|--configuration", "Configuration under which to build", "-c|--configuration", LocalizableStrings.CommandOptionConfigurationDescription,
CommandOptionType.SingleValue); CommandOptionType.SingleValue);
CommandOption framework = app.Option( CommandOption framework = app.Option(
"-f|--framework <FRAMEWORK>", "Compile a specific framework", "-f|--framework <{LocalizableStrings.CommandOptionFramework}>", LocalizableStrings.CommandOptionFrameworkDescription,
CommandOptionType.SingleValue); CommandOptionType.SingleValue);
CommandOption project = app.Option( 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); CommandOptionType.SingleValue);
app.OnExecute(() => app.OnExecute(() =>

View file

@ -61,7 +61,7 @@ namespace Microsoft.DotNet.Tools.Run
if (buildResult != 0) if (buildResult != 0)
{ {
Reporter.Error.WriteLine(); 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>() Dictionary<string, string> globalProperties = new Dictionary<string, string>()
{ {
{ "MSBuildExtensionsPath", AppContext.BaseDirectory } { LocalizableStrings.RunCommandMSBuildExtensionsPath, AppContext.BaseDirectory }
}; };
if (!string.IsNullOrWhiteSpace(Configuration)) if (!string.IsNullOrWhiteSpace(Configuration))
{ {
globalProperties.Add("Configuration", Configuration); globalProperties.Add(LocalizableStrings.RunCommandConfiguration, Configuration);
} }
if (!string.IsNullOrWhiteSpace(Framework)) if (!string.IsNullOrWhiteSpace(Framework))
{ {
globalProperties.Add("TargetFramework", Framework); globalProperties.Add(LocalizableStrings.RunCommandTargetFramework, Framework);
} }
ProjectInstance projectInstance = new ProjectInstance(Project, globalProperties, null); ProjectInstance projectInstance = new ProjectInstance(Project, globalProperties, null);
string runProgram = projectInstance.GetPropertyValue("RunCommand"); string runProgram = projectInstance.GetPropertyValue(LocalizableStrings.RunCommandProjectInstance);
if (string.IsNullOrEmpty(runProgram)) if (string.IsNullOrEmpty(runProgram))
{ {
string outputType = projectInstance.GetPropertyValue("OutputType"); string outputType = projectInstance.GetPropertyValue(LocalizableStrings.RunCommandOutputType);
throw new GracefulException(string.Join(Environment.NewLine, throw new GracefulException(string.Join(Environment.NewLine,
"Unable to run your project.", LocalizableStrings.RunCommandExceptionUnableToRun1,
"Please ensure you have a runnable project type and ensure 'dotnet run' supports this project.", LocalizableStrings.RunCommandExceptionUnableToRun2,
$"The current OutputType is '{outputType}'.")); $"{LocalizableStrings.RunCommandExceptionUnableToRun3} '{outputType}'."));
} }
string runArguments = projectInstance.GetPropertyValue("RunArguments"); string runArguments = projectInstance.GetPropertyValue(LocalizableStrings.RunCommandRunArguments);
string runWorkingDirectory = projectInstance.GetPropertyValue("RunWorkingDirectory"); string runWorkingDirectory = projectInstance.GetPropertyValue(LocalizableStrings.RunCommandRunWorkingDirectory);
string fullArguments = runArguments; string fullArguments = runArguments;
if (_args.Any()) if (_args.Any())
@ -120,13 +120,13 @@ namespace Microsoft.DotNet.Tools.Run
if (projectFiles.Length == 0) if (projectFiles.Length == 0)
{ {
throw new InvalidOperationException( throw new InvalidOperationException(
$"Couldn't find a project to run. Ensure a project exists in {directory}." + Environment.NewLine + $"{LocalizableStrings.RunCommandInvalidOperationException1} {directory}." + Environment.NewLine +
"Or pass the path to the project using --project"); LocalizableStrings.RunCommandInvalidOperationException2);
} }
else if (projectFiles.Length > 1) else if (projectFiles.Length > 1)
{ {
throw new InvalidOperationException( 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]; Project = projectFiles[0];