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
This commit is contained in:
Scott Carlton 2016-12-04 21:33:43 -08:00 committed by Piotr Puszkiewicz
parent e3cfe1d13d
commit dc3d88c587
10 changed files with 83 additions and 44 deletions

View file

@ -1,6 +1,6 @@
namespace Microsoft.DotNet.Tools namespace Microsoft.DotNet.Tools
{ {
internal class LocalizableStrings internal class CommonLocalizableStrings
{ {
public const string CouldNotFindAnyProjectInDirectory = "Could not find any project in `{0}`."; 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."; public const string MoreThanOneProjectInDirectory = "Found more than one project in `{0}`. Please specify which one to use.";
@ -29,6 +29,9 @@
public const string Library = "Library"; public const string Library = "Library";
public const string Program = "Program"; public const string Program = "Program";
public const string Application = "Application"; 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 // Verbs
public const string Add = "Add"; public const string Add = "Add";
@ -112,13 +115,6 @@
public const string SolutionDoesNotExist = "Specified solution file {0} does not exist, or there is no solution file in the directory."; 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}."; 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 /// add package
public const string PackageReferenceDoesNotExist = "Package reference `{0}` does not exist."; public const string PackageReferenceDoesNotExist = "Package reference `{0}` does not exist.";
public const string PackageReferenceIsInvalid = "Package reference `{0}` is invalid."; public const string PackageReferenceIsInvalid = "Package reference `{0}` is invalid.";
@ -134,13 +130,6 @@
public const string ProjectAddedToTheSolution = "Project `{0}` added to the solution."; public const string ProjectAddedToTheSolution = "Project `{0}` added to the solution.";
public const string SolutionAlreadyHasAProject = "Solution {0} already contains project {1}."; 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 /// del pkg
public const string PackageReferenceNotFoundInTheProject = "Package reference `{0}` could not be found in the project."; public const string PackageReferenceNotFoundInTheProject = "Package reference `{0}` could not be found in the project.";
public const string PackageReferenceRemoved = "Reference `{0}` deleted from the project."; public const string PackageReferenceRemoved = "Reference `{0}` deleted from the project.";

View file

@ -34,7 +34,7 @@ namespace Microsoft.DotNet.Tools
} }
else if (args.Length == 1) else if (args.Length == 1)
{ {
Reporter.Error.WriteLine(string.Format(LocalizableStrings.RequiredArgumentNotPassed, "<command>").Red()); Reporter.Error.WriteLine(string.Format(CommonLocalizableStrings.RequiredArgumentNotPassed, "<command>").Red());
Reporter.Output.WriteLine(HelpText); Reporter.Output.WriteLine(HelpText);
return 1; return 1;
} }
@ -52,7 +52,7 @@ namespace Microsoft.DotNet.Tools
return builtin(args); return builtin(args);
} }
Reporter.Error.WriteLine(string.Format(LocalizableStrings.RequiredArgumentIsInvalid, "<command>").Red()); Reporter.Error.WriteLine(string.Format(CommonLocalizableStrings.RequiredArgumentIsInvalid, "<command>").Red());
Reporter.Output.WriteLine(HelpText); Reporter.Output.WriteLine(HelpText);
return 1; return 1;
} }

View file

@ -41,13 +41,13 @@ namespace Microsoft.DotNet.Tools
{ {
if (!File.Exists(projectPath)) if (!File.Exists(projectPath))
{ {
throw new GracefulException(LocalizableStrings.ProjectDoesNotExist, projectPath); throw new GracefulException(CommonLocalizableStrings.ProjectDoesNotExist, projectPath);
} }
var project = TryOpenProject(projectPath); var project = TryOpenProject(projectPath);
if (project == null) if (project == null)
{ {
throw new GracefulException(LocalizableStrings.ProjectIsInvalid, projectPath); throw new GracefulException(CommonLocalizableStrings.ProjectIsInvalid, projectPath);
} }
return new MsbuildProject(project); return new MsbuildProject(project);
@ -62,36 +62,36 @@ namespace Microsoft.DotNet.Tools
} }
catch (ArgumentException) catch (ArgumentException)
{ {
throw new GracefulException(LocalizableStrings.CouldNotFindProjectOrDirectory, projectDirectory); throw new GracefulException(CommonLocalizableStrings.CouldNotFindProjectOrDirectory, projectDirectory);
} }
if (!dir.Exists) if (!dir.Exists)
{ {
throw new GracefulException(LocalizableStrings.CouldNotFindProjectOrDirectory, projectDirectory); throw new GracefulException(CommonLocalizableStrings.CouldNotFindProjectOrDirectory, projectDirectory);
} }
FileInfo[] files = dir.GetFiles("*proj"); FileInfo[] files = dir.GetFiles("*proj");
if (files.Length == 0) if (files.Length == 0)
{ {
throw new GracefulException(LocalizableStrings.CouldNotFindAnyProjectInDirectory, projectDirectory); throw new GracefulException(CommonLocalizableStrings.CouldNotFindAnyProjectInDirectory, projectDirectory);
} }
if (files.Length > 1) if (files.Length > 1)
{ {
throw new GracefulException(LocalizableStrings.MoreThanOneProjectInDirectory, projectDirectory); throw new GracefulException(CommonLocalizableStrings.MoreThanOneProjectInDirectory, projectDirectory);
} }
FileInfo projectFile = files.First(); FileInfo projectFile = files.First();
if (!projectFile.Exists) if (!projectFile.Exists)
{ {
throw new GracefulException(LocalizableStrings.CouldNotFindAnyProjectInDirectory, projectDirectory); throw new GracefulException(CommonLocalizableStrings.CouldNotFindAnyProjectInDirectory, projectDirectory);
} }
var project = TryOpenProject(projectFile.FullName); var project = TryOpenProject(projectFile.FullName);
if (project == null) if (project == null)
{ {
throw new GracefulException(LocalizableStrings.FoundInvalidProject, projectFile.FullName); throw new GracefulException(CommonLocalizableStrings.FoundInvalidProject, projectFile.FullName);
} }
return new MsbuildProject(project); return new MsbuildProject(project);
@ -106,14 +106,14 @@ namespace Microsoft.DotNet.Tools
{ {
if (Project.HasExistingItemWithCondition(framework, @ref)) if (Project.HasExistingItemWithCondition(framework, @ref))
{ {
Reporter.Output.WriteLine(string.Format(LocalizableStrings.ProjectAlreadyHasAreference, @ref)); Reporter.Output.WriteLine(string.Format(CommonLocalizableStrings.ProjectAlreadyHasAreference, @ref));
continue; continue;
} }
numberOfAddedReferences++; numberOfAddedReferences++;
itemGroup.AppendChild(Project.CreateItemElement(ProjectItemElementType, @ref)); itemGroup.AppendChild(Project.CreateItemElement(ProjectItemElementType, @ref));
Reporter.Output.WriteLine(string.Format(LocalizableStrings.ReferenceAddedToTheProject, @ref)); Reporter.Output.WriteLine(string.Format(CommonLocalizableStrings.ReferenceAddedToTheProject, @ref));
} }
return numberOfAddedReferences; return numberOfAddedReferences;
@ -157,7 +157,7 @@ namespace Microsoft.DotNet.Tools
throw new GracefulException( throw new GracefulException(
string.Join( string.Join(
Environment.NewLine, Environment.NewLine,
notExisting.Select((r) => string.Format(LocalizableStrings.ReferenceDoesNotExist, r)))); notExisting.Select((r) => string.Format(CommonLocalizableStrings.ReferenceDoesNotExist, r))));
} }
} }
@ -176,13 +176,13 @@ namespace Microsoft.DotNet.Tools
} }
numberOfRemovedRefs++; numberOfRemovedRefs++;
Reporter.Output.WriteLine(string.Format(LocalizableStrings.ProjectReferenceRemoved, r)); Reporter.Output.WriteLine(string.Format(CommonLocalizableStrings.ProjectReferenceRemoved, r));
} }
} }
if (numberOfRemovedRefs == 0) if (numberOfRemovedRefs == 0)
{ {
Reporter.Output.WriteLine(string.Format(LocalizableStrings.ProjectReferenceCouldNotBeFound, reference)); Reporter.Output.WriteLine(string.Format(CommonLocalizableStrings.ProjectReferenceCouldNotBeFound, reference));
} }
return numberOfRemovedRefs; return numberOfRemovedRefs;

View file

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

View file

@ -43,7 +43,7 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference
app.OnExecute(() => { app.OnExecute(() => {
if (string.IsNullOrEmpty(projectArgument.Value)) if (string.IsNullOrEmpty(projectArgument.Value))
{ {
throw new GracefulException(LocalizableStrings.RequiredArgumentNotPassed, "<Project>"); throw new GracefulException(CommonLocalizableStrings.RequiredArgumentNotPassed, "<Project>");
} }
var msbuildProj = MsbuildProject.FromFileOrDirectory(projectArgument.Value); var msbuildProj = MsbuildProject.FromFileOrDirectory(projectArgument.Value);

View file

@ -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 <object>.";
public const string ArgsDefinition = "Any extra arguments passed to the command. Use `dotnet add <command> --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";
}
}

View file

@ -16,22 +16,22 @@ namespace Microsoft.DotNet.Tools.Remove
{ {
public class RemoveCommand : DispatchCommand public class RemoveCommand : DispatchCommand
{ {
protected override string HelpText => @".NET Remove Command; protected override string HelpText => $@"{LocalizableStrings.NetRemoveCommand};
Usage: dotnet remove [options] <object> <command> [[--] <arg>...]] {LocalizableStrings.Usage}: dotnet remove [options] <object> <command> [[--] <arg>...]]
Options: {LocalizableStrings.Options}:
-h|--help Show help information -h|--help {LocalizableStrings.HelpDefinition}
Arguments: {LocalizableStrings.Arguments}:
<object> The object of the operation. If a project file is not specified, it defaults to the current directory. <object> {LocalizableStrings.ArgumentsObjectDefinition}
<command> Command to be executed on <object>. <command> {LocalizableStrings.ArgumentsCommandDefinition}
Args: Args:
Any extra arguments passed to the command. Use `dotnet add <command> --help` to get help about these arguments. {LocalizableStrings.ArgsDefinition}
Commands: {LocalizableStrings.Commands}:
p2p Remove project to project (p2p) reference from a project"; p2p {LocalizableStrings.CommandP2PDefinition}";
protected override Dictionary<string, Func<string[], int>> BuiltInCommands => new Dictionary<string, Func<string[], int>> protected override Dictionary<string, Func<string[], int>> BuiltInCommands => new Dictionary<string, Func<string[], int>>
{ {

View file

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

View file

@ -38,7 +38,7 @@ namespace Microsoft.DotNet.Tools.Remove.ProjectToProjectReference
app.OnExecute(() => { app.OnExecute(() => {
if (string.IsNullOrEmpty(projectArgument.Value)) if (string.IsNullOrEmpty(projectArgument.Value))
{ {
throw new GracefulException(LocalizableStrings.RequiredArgumentNotPassed, "<Project>"); throw new GracefulException(CommonLocalizableStrings.RequiredArgumentNotPassed, "<Project>");
} }
var msbuildProj = MsbuildProject.FromFileOrDirectory(projectArgument.Value); var msbuildProj = MsbuildProject.FromFileOrDirectory(projectArgument.Value);

View file

@ -14,8 +14,6 @@ namespace Microsoft.DotNet.Tools.Pack.Tests
{ {
public class PackTests : TestBase public class PackTests : TestBase
{ {
private readonly string _testProjectsRoot;
[Fact(Skip="https://github.com/dotnet/cli/issues/4488")] [Fact(Skip="https://github.com/dotnet/cli/issues/4488")]
public void OutputsPackagesToConfigurationSubdirWhenOutputParameterIsNotPassed() public void OutputsPackagesToConfigurationSubdirWhenOutputParameterIsNotPassed()
{ {