From 706b8a802d49be079fef570b354a70056aa2ad6f Mon Sep 17 00:00:00 2001 From: Scott Carlton Date: Sat, 19 Nov 2016 11:45:46 -0800 Subject: [PATCH] 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 --- .../LocalizableStrings.cs | 9 ++++ .../dotnet-restore-projectjson/NuGet3.cs | 4 +- .../dotnet-restore/LocalizableStrings.cs | 33 +++++++++++++ src/dotnet/commands/dotnet-restore/Program.cs | 28 +++++------ .../commands/dotnet-run/LocalizableStrings.cs | 47 +++++++++++++++++++ src/dotnet/commands/dotnet-run/Program.cs | 10 ++-- src/dotnet/commands/dotnet-run/RunCommand.cs | 28 +++++------ 7 files changed, 124 insertions(+), 35 deletions(-) create mode 100644 src/dotnet/commands/dotnet-restore-projectjson/LocalizableStrings.cs create mode 100644 src/dotnet/commands/dotnet-restore/LocalizableStrings.cs create mode 100644 src/dotnet/commands/dotnet-run/LocalizableStrings.cs diff --git a/src/dotnet/commands/dotnet-restore-projectjson/LocalizableStrings.cs b/src/dotnet/commands/dotnet-restore-projectjson/LocalizableStrings.cs new file mode 100644 index 000000000..cc76baf73 --- /dev/null +++ b/src/dotnet/commands/dotnet-restore-projectjson/LocalizableStrings.cs @@ -0,0 +1,9 @@ +namespace Microsoft.DotNet.Tools.RestoreProjectJson +{ + internal class LocalizableStrings + { + public const string AddMinimal = "minimal"; + + public const string AddRestore = "restore"; + } +} diff --git a/src/dotnet/commands/dotnet-restore-projectjson/NuGet3.cs b/src/dotnet/commands/dotnet-restore-projectjson/NuGet3.cs index a8d54900a..7196e04ed 100644 --- a/src/dotnet/commands/dotnet-restore-projectjson/NuGet3.cs +++ b/src/dotnet/commands/dotnet-restore-projectjson/NuGet3.cs @@ -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)); diff --git a/src/dotnet/commands/dotnet-restore/LocalizableStrings.cs b/src/dotnet/commands/dotnet-restore/LocalizableStrings.cs new file mode 100644 index 000000000..dc9cf6d96 --- /dev/null +++ b/src/dotnet/commands/dotnet-restore/LocalizableStrings.cs @@ -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"; + } +} diff --git a/src/dotnet/commands/dotnet-restore/Program.cs b/src/dotnet/commands/dotnet-restore/Program.cs index 1aa2f5573..c9e5f80f6 100644 --- a/src/dotnet/commands/dotnet-restore/Program.cs +++ b/src/dotnet/commands/dotnet-restore/Program.cs @@ -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 ", - "Specifies a NuGet package source to use during the restore.", + "-s|--source <{LocalizableStrings.CmdSourceOption}>", + LocalizableStrings.CmdSourceOptionDescription, CommandOptionType.MultipleValue); var packagesOption = cmd.Option( - "--packages ", - "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 ", - "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); diff --git a/src/dotnet/commands/dotnet-run/LocalizableStrings.cs b/src/dotnet/commands/dotnet-run/LocalizableStrings.cs new file mode 100644 index 000000000..a2c08f750 --- /dev/null +++ b/src/dotnet/commands/dotnet-run/LocalizableStrings.cs @@ -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."; + } +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-run/Program.cs b/src/dotnet/commands/dotnet-run/Program.cs index 39b523239..2c9c01756 100644 --- a/src/dotnet/commands/dotnet-run/Program.cs +++ b/src/dotnet/commands/dotnet-run/Program.cs @@ -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 ", "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(() => diff --git a/src/dotnet/commands/dotnet-run/RunCommand.cs b/src/dotnet/commands/dotnet-run/RunCommand.cs index 738780fa2..63f55412b 100644 --- a/src/dotnet/commands/dotnet-run/RunCommand.cs +++ b/src/dotnet/commands/dotnet-run/RunCommand.cs @@ -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 globalProperties = new Dictionary() { - { "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];