From dc3d88c58710cf781056f57f3fa55c82521555bc Mon Sep 17 00:00:00 2001 From: Scott Carlton Date: Sun, 4 Dec 2016 21:33:43 -0800 Subject: [PATCH] Localize changes for dotnet-remove (#4900) * Rename centralized LocalizableStrings file * Added RemoveDefinition * Rebase * rebase, remove localizablestrings for help * loc for help command * remove localizablestrings * Localization changes for dotnet-remove * Slight refactoring --- ...Strings.cs => CommonLocalizableStrings.cs} | 19 +++----------- src/dotnet/DispatchCommand.cs | 4 +-- src/dotnet/MsbuildProject.cs | 26 +++++++++---------- .../dotnet-add-p2p/LocalizableStrings.cs | 11 ++++++++ .../dotnet-add-p2p/Program.cs | 2 +- .../dotnet-remove/LocalizableStrings.cs | 25 ++++++++++++++++++ src/dotnet/commands/dotnet-remove/Program.cs | 20 +++++++------- .../dotnet-remove-p2p/LocalizableStrings.cs | 16 ++++++++++++ .../dotnet-remove-p2p/Program.cs | 2 +- test/dotnet-pack.Tests/PackTests.cs | 2 -- 10 files changed, 83 insertions(+), 44 deletions(-) rename src/dotnet/{LocalizableStrings.cs => CommonLocalizableStrings.cs} (91%) create mode 100644 src/dotnet/commands/dotnet-add/dotnet-add-p2p/LocalizableStrings.cs rename src/dotnet/commands/{ => dotnet-add}/dotnet-add-p2p/Program.cs (96%) create mode 100644 src/dotnet/commands/dotnet-remove/LocalizableStrings.cs create mode 100644 src/dotnet/commands/dotnet-remove/dotnet-remove-p2p/LocalizableStrings.cs rename src/dotnet/commands/{ => dotnet-remove}/dotnet-remove-p2p/Program.cs (96%) diff --git a/src/dotnet/LocalizableStrings.cs b/src/dotnet/CommonLocalizableStrings.cs similarity index 91% rename from src/dotnet/LocalizableStrings.cs rename to src/dotnet/CommonLocalizableStrings.cs index 6fc910d34f..1d1acf267c 100644 --- a/src/dotnet/LocalizableStrings.cs +++ b/src/dotnet/CommonLocalizableStrings.cs @@ -1,6 +1,6 @@ namespace Microsoft.DotNet.Tools { - internal class LocalizableStrings + internal class CommonLocalizableStrings { public const string CouldNotFindAnyProjectInDirectory = "Could not find any project in `{0}`."; public const string MoreThanOneProjectInDirectory = "Found more than one project in `{0}`. Please specify which one to use."; @@ -29,6 +29,9 @@ internal class LocalizableStrings public const string Library = "Library"; public const string Program = "Program"; public const string Application = "Application"; + public const string ReferenceDoesNotExist = "Reference {0} does not exist. If you still want to add it, please use --force option. Please note that this may have adverse effects on the project. "; + public const string ReferenceAddedToTheProject = "Reference `{0}` added to the project."; + // Verbs public const string Add = "Add"; @@ -112,13 +115,6 @@ internal class LocalizableStrings public const string SolutionDoesNotExist = "Specified solution file {0} does not exist, or there is no solution file in the directory."; public const string SolutionAlreadyContainsAProject = "Solution {0} already contains project {1}."; - /// add p2p - public const string ReferenceDoesNotExist = "Reference {0} does not exist. If you still want to add it, please use --force option. Please note that this may have adverse effects on the project. "; - public const string ReferenceIsInvalid = "Reference `{0}` is invalid."; - public const string SpecifyAtLeastOneReferenceToAdd = "You must specify at least one reference to add. Please run dotnet add --help for more information."; - public const string ReferenceAddedToTheProject = "Reference `{0}` added to the project."; - public const string ProjectAlreadyHasAReference = "Project {0} already has a reference `{1}`."; - /// add package public const string PackageReferenceDoesNotExist = "Package reference `{0}` does not exist."; public const string PackageReferenceIsInvalid = "Package reference `{0}` is invalid."; @@ -134,13 +130,6 @@ internal class LocalizableStrings public const string ProjectAddedToTheSolution = "Project `{0}` added to the solution."; public const string SolutionAlreadyHasAProject = "Solution {0} already contains project {1}."; - /// del p2p - public const string ReferenceNotFoundInTheProject = "Specified reference {0} does not exist in project {1}."; - public const string ReferenceRemoved = "Reference `{0}` deleted from the project."; - public const string SpecifyAtLeastOneReferenceToRemove = "You must specify at least one reference to delete. Please run dotnet delete --help for more information."; - public const string ReferenceDeleted = "Reference `{0}` deleted."; - public const string SpecifyAtLeastOneReferenceToDelete = "You must specify at least one reference to delete. Please run dotnet delete --help for more information."; - /// del pkg public const string PackageReferenceNotFoundInTheProject = "Package reference `{0}` could not be found in the project."; public const string PackageReferenceRemoved = "Reference `{0}` deleted from the project."; diff --git a/src/dotnet/DispatchCommand.cs b/src/dotnet/DispatchCommand.cs index 7878fcfdc9..8ea50b8c4b 100644 --- a/src/dotnet/DispatchCommand.cs +++ b/src/dotnet/DispatchCommand.cs @@ -34,7 +34,7 @@ public int Run(string[] args) } else if (args.Length == 1) { - Reporter.Error.WriteLine(string.Format(LocalizableStrings.RequiredArgumentNotPassed, "").Red()); + Reporter.Error.WriteLine(string.Format(CommonLocalizableStrings.RequiredArgumentNotPassed, "").Red()); Reporter.Output.WriteLine(HelpText); return 1; } @@ -52,7 +52,7 @@ public int Run(string[] args) return builtin(args); } - Reporter.Error.WriteLine(string.Format(LocalizableStrings.RequiredArgumentIsInvalid, "").Red()); + Reporter.Error.WriteLine(string.Format(CommonLocalizableStrings.RequiredArgumentIsInvalid, "").Red()); Reporter.Output.WriteLine(HelpText); return 1; } diff --git a/src/dotnet/MsbuildProject.cs b/src/dotnet/MsbuildProject.cs index 0d0f064732..c3574b8db3 100644 --- a/src/dotnet/MsbuildProject.cs +++ b/src/dotnet/MsbuildProject.cs @@ -41,13 +41,13 @@ public static MsbuildProject FromFile(string projectPath) { if (!File.Exists(projectPath)) { - throw new GracefulException(LocalizableStrings.ProjectDoesNotExist, projectPath); + throw new GracefulException(CommonLocalizableStrings.ProjectDoesNotExist, projectPath); } var project = TryOpenProject(projectPath); if (project == null) { - throw new GracefulException(LocalizableStrings.ProjectIsInvalid, projectPath); + throw new GracefulException(CommonLocalizableStrings.ProjectIsInvalid, projectPath); } return new MsbuildProject(project); @@ -62,36 +62,36 @@ public static MsbuildProject FromDirectory(string projectDirectory) } catch (ArgumentException) { - throw new GracefulException(LocalizableStrings.CouldNotFindProjectOrDirectory, projectDirectory); + throw new GracefulException(CommonLocalizableStrings.CouldNotFindProjectOrDirectory, projectDirectory); } if (!dir.Exists) { - throw new GracefulException(LocalizableStrings.CouldNotFindProjectOrDirectory, projectDirectory); + throw new GracefulException(CommonLocalizableStrings.CouldNotFindProjectOrDirectory, projectDirectory); } FileInfo[] files = dir.GetFiles("*proj"); if (files.Length == 0) { - throw new GracefulException(LocalizableStrings.CouldNotFindAnyProjectInDirectory, projectDirectory); + throw new GracefulException(CommonLocalizableStrings.CouldNotFindAnyProjectInDirectory, projectDirectory); } if (files.Length > 1) { - throw new GracefulException(LocalizableStrings.MoreThanOneProjectInDirectory, projectDirectory); + throw new GracefulException(CommonLocalizableStrings.MoreThanOneProjectInDirectory, projectDirectory); } FileInfo projectFile = files.First(); if (!projectFile.Exists) { - throw new GracefulException(LocalizableStrings.CouldNotFindAnyProjectInDirectory, projectDirectory); + throw new GracefulException(CommonLocalizableStrings.CouldNotFindAnyProjectInDirectory, projectDirectory); } var project = TryOpenProject(projectFile.FullName); if (project == null) { - throw new GracefulException(LocalizableStrings.FoundInvalidProject, projectFile.FullName); + throw new GracefulException(CommonLocalizableStrings.FoundInvalidProject, projectFile.FullName); } return new MsbuildProject(project); @@ -106,14 +106,14 @@ public int AddProjectToProjectReferences(string framework, IEnumerable r { if (Project.HasExistingItemWithCondition(framework, @ref)) { - Reporter.Output.WriteLine(string.Format(LocalizableStrings.ProjectAlreadyHasAreference, @ref)); + Reporter.Output.WriteLine(string.Format(CommonLocalizableStrings.ProjectAlreadyHasAreference, @ref)); continue; } numberOfAddedReferences++; itemGroup.AppendChild(Project.CreateItemElement(ProjectItemElementType, @ref)); - Reporter.Output.WriteLine(string.Format(LocalizableStrings.ReferenceAddedToTheProject, @ref)); + Reporter.Output.WriteLine(string.Format(CommonLocalizableStrings.ReferenceAddedToTheProject, @ref)); } return numberOfAddedReferences; @@ -157,7 +157,7 @@ public static void EnsureAllReferencesExist(List references) throw new GracefulException( string.Join( Environment.NewLine, - notExisting.Select((r) => string.Format(LocalizableStrings.ReferenceDoesNotExist, r)))); + notExisting.Select((r) => string.Format(CommonLocalizableStrings.ReferenceDoesNotExist, r)))); } } @@ -176,13 +176,13 @@ private int RemoveProjectToProjectReferenceAlternatives(string framework, string } numberOfRemovedRefs++; - Reporter.Output.WriteLine(string.Format(LocalizableStrings.ProjectReferenceRemoved, r)); + Reporter.Output.WriteLine(string.Format(CommonLocalizableStrings.ProjectReferenceRemoved, r)); } } if (numberOfRemovedRefs == 0) { - Reporter.Output.WriteLine(string.Format(LocalizableStrings.ProjectReferenceCouldNotBeFound, reference)); + Reporter.Output.WriteLine(string.Format(CommonLocalizableStrings.ProjectReferenceCouldNotBeFound, reference)); } return numberOfRemovedRefs; diff --git a/src/dotnet/commands/dotnet-add/dotnet-add-p2p/LocalizableStrings.cs b/src/dotnet/commands/dotnet-add/dotnet-add-p2p/LocalizableStrings.cs new file mode 100644 index 0000000000..e3dfd3a8a8 --- /dev/null +++ b/src/dotnet/commands/dotnet-add/dotnet-add-p2p/LocalizableStrings.cs @@ -0,0 +1,11 @@ +namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference +{ + internal class LocalizableStrings + { + public const string ReferenceIsInvalid = "Reference `{0}` is invalid."; + + public const string SpecifyAtLeastOneReferenceToAdd = "You must specify at least one reference to add. Please run dotnet add --help for more information."; + + public const string ProjectAlreadyHasAReference = "Project {0} already has a reference `{1}`."; + } +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-add-p2p/Program.cs b/src/dotnet/commands/dotnet-add/dotnet-add-p2p/Program.cs similarity index 96% rename from src/dotnet/commands/dotnet-add-p2p/Program.cs rename to src/dotnet/commands/dotnet-add/dotnet-add-p2p/Program.cs index c6ada41cc7..1639312664 100644 --- a/src/dotnet/commands/dotnet-add-p2p/Program.cs +++ b/src/dotnet/commands/dotnet-add/dotnet-add-p2p/Program.cs @@ -43,7 +43,7 @@ public static int Run(string[] args) app.OnExecute(() => { if (string.IsNullOrEmpty(projectArgument.Value)) { - throw new GracefulException(LocalizableStrings.RequiredArgumentNotPassed, ""); + throw new GracefulException(CommonLocalizableStrings.RequiredArgumentNotPassed, ""); } var msbuildProj = MsbuildProject.FromFileOrDirectory(projectArgument.Value); diff --git a/src/dotnet/commands/dotnet-remove/LocalizableStrings.cs b/src/dotnet/commands/dotnet-remove/LocalizableStrings.cs new file mode 100644 index 0000000000..040aa16c18 --- /dev/null +++ b/src/dotnet/commands/dotnet-remove/LocalizableStrings.cs @@ -0,0 +1,25 @@ +namespace Microsoft.DotNet.Tools.Remove +{ + internal class LocalizableStrings + { + public const string NetRemoveCommand = ".NET Remove Command"; + + public const string Usage = "Usage"; + + public const string Options = "Options"; + + public const string HelpDefinition = "Show help information"; + + public const string Arguments = "Arguments"; + + public const string ArgumentsObjectDefinition = "The object of the operation. If a project file is not specified, it defaults to the current directory."; + + public const string ArgumentsCommandDefinition = "Command to be executed on ."; + + public const string ArgsDefinition = "Any extra arguments passed to the command. Use `dotnet add --help` to get help about these arguments."; + + public const string Commands = "Commands"; + + public const string CommandP2PDefinition = "Remove project to project (p2p) reference from a project"; + } +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-remove/Program.cs b/src/dotnet/commands/dotnet-remove/Program.cs index 25cf646780..d994fbf765 100644 --- a/src/dotnet/commands/dotnet-remove/Program.cs +++ b/src/dotnet/commands/dotnet-remove/Program.cs @@ -16,22 +16,22 @@ namespace Microsoft.DotNet.Tools.Remove { public class RemoveCommand : DispatchCommand { - protected override string HelpText => @".NET Remove Command; + protected override string HelpText => $@"{LocalizableStrings.NetRemoveCommand}; -Usage: dotnet remove [options] [[--] ...]] +{LocalizableStrings.Usage}: dotnet remove [options] [[--] ...]] -Options: - -h|--help Show help information +{LocalizableStrings.Options}: + -h|--help {LocalizableStrings.HelpDefinition} -Arguments: - The object of the operation. If a project file is not specified, it defaults to the current directory. - Command to be executed on . +{LocalizableStrings.Arguments}: + {LocalizableStrings.ArgumentsObjectDefinition} + {LocalizableStrings.ArgumentsCommandDefinition} Args: - Any extra arguments passed to the command. Use `dotnet add --help` to get help about these arguments. + {LocalizableStrings.ArgsDefinition} -Commands: - p2p Remove project to project (p2p) reference from a project"; +{LocalizableStrings.Commands}: + p2p {LocalizableStrings.CommandP2PDefinition}"; protected override Dictionary> BuiltInCommands => new Dictionary> { diff --git a/src/dotnet/commands/dotnet-remove/dotnet-remove-p2p/LocalizableStrings.cs b/src/dotnet/commands/dotnet-remove/dotnet-remove-p2p/LocalizableStrings.cs new file mode 100644 index 0000000000..db39b5bf7d --- /dev/null +++ b/src/dotnet/commands/dotnet-remove/dotnet-remove-p2p/LocalizableStrings.cs @@ -0,0 +1,16 @@ +namespace Microsoft.DotNet.Tools.Remove.ProjectToProjectReference +{ + internal class LocalizableStrings + { + /// del p2p + public const string ReferenceNotFoundInTheProject = "Specified reference {0} does not exist in project {1}."; + + public const string ReferenceRemoved = "Reference `{0}` deleted from the project."; + + public const string SpecifyAtLeastOneReferenceToRemove = "You must specify at least one reference to delete. Please run dotnet delete --help for more information."; + + public const string ReferenceDeleted = "Reference `{0}` deleted."; + + public const string SpecifyAtLeastOneReferenceToDelete = "You must specify at least one reference to delete. Please run dotnet delete --help for more information."; + } +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-remove-p2p/Program.cs b/src/dotnet/commands/dotnet-remove/dotnet-remove-p2p/Program.cs similarity index 96% rename from src/dotnet/commands/dotnet-remove-p2p/Program.cs rename to src/dotnet/commands/dotnet-remove/dotnet-remove-p2p/Program.cs index 6e55512d80..a18b4830ac 100644 --- a/src/dotnet/commands/dotnet-remove-p2p/Program.cs +++ b/src/dotnet/commands/dotnet-remove/dotnet-remove-p2p/Program.cs @@ -38,7 +38,7 @@ public static int Run(string[] args) app.OnExecute(() => { if (string.IsNullOrEmpty(projectArgument.Value)) { - throw new GracefulException(LocalizableStrings.RequiredArgumentNotPassed, ""); + throw new GracefulException(CommonLocalizableStrings.RequiredArgumentNotPassed, ""); } var msbuildProj = MsbuildProject.FromFileOrDirectory(projectArgument.Value); diff --git a/test/dotnet-pack.Tests/PackTests.cs b/test/dotnet-pack.Tests/PackTests.cs index f9cd77139f..10e9cf3a68 100644 --- a/test/dotnet-pack.Tests/PackTests.cs +++ b/test/dotnet-pack.Tests/PackTests.cs @@ -14,8 +14,6 @@ namespace Microsoft.DotNet.Tools.Pack.Tests { public class PackTests : TestBase { - private readonly string _testProjectsRoot; - [Fact(Skip="https://github.com/dotnet/cli/issues/4488")] public void OutputsPackagesToConfigurationSubdirWhenOutputParameterIsNotPassed() {