Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
Localize changes for dotnet-remove (#4900)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
vsccarl authored and Piotr Puszkiewicz committed Dec 5, 2016
1 parent e3cfe1d commit dc3d88c
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -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.";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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.";
Expand All @@ -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.";
Expand Down
4 changes: 2 additions & 2 deletions src/dotnet/DispatchCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public int Run(string[] args)
}
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);
return 1;
}
Expand All @@ -52,7 +52,7 @@ public int Run(string[] 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);
return 1;
}
Expand Down
26 changes: 13 additions & 13 deletions src/dotnet/MsbuildProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -106,14 +106,14 @@ public int AddProjectToProjectReferences(string framework, IEnumerable<string> 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;
Expand Down Expand Up @@ -157,7 +157,7 @@ public static void EnsureAllReferencesExist(List<string> references)
throw new GracefulException(
string.Join(
Environment.NewLine,
notExisting.Select((r) => string.Format(LocalizableStrings.ReferenceDoesNotExist, r))));
notExisting.Select((r) => string.Format(CommonLocalizableStrings.ReferenceDoesNotExist, r))));
}
}

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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}`.";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static int Run(string[] args)
app.OnExecute(() => {
if (string.IsNullOrEmpty(projectArgument.Value))
{
throw new GracefulException(LocalizableStrings.RequiredArgumentNotPassed, "<Project>");
throw new GracefulException(CommonLocalizableStrings.RequiredArgumentNotPassed, "<Project>");
}

var msbuildProj = MsbuildProject.FromFileOrDirectory(projectArgument.Value);
Expand Down
25 changes: 25 additions & 0 deletions src/dotnet/commands/dotnet-remove/LocalizableStrings.cs
Original file line number Diff line number Diff line change
@@ -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";
}
}
20 changes: 10 additions & 10 deletions src/dotnet/commands/dotnet-remove/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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] <object> <command> [[--] <arg>...]]
{LocalizableStrings.Usage}: dotnet remove [options] <object> <command> [[--] <arg>...]]
Options:
-h|--help Show help information
{LocalizableStrings.Options}:
-h|--help {LocalizableStrings.HelpDefinition}
Arguments:
<object> The object of the operation. If a project file is not specified, it defaults to the current directory.
<command> Command to be executed on <object>.
{LocalizableStrings.Arguments}:
<object> {LocalizableStrings.ArgumentsObjectDefinition}
<command> {LocalizableStrings.ArgumentsCommandDefinition}
Args:
Any extra arguments passed to the command. Use `dotnet add <command> --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<string, Func<string[], int>> BuiltInCommands => new Dictionary<string, Func<string[], int>>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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.";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static int Run(string[] args)
app.OnExecute(() => {
if (string.IsNullOrEmpty(projectArgument.Value))
{
throw new GracefulException(LocalizableStrings.RequiredArgumentNotPassed, "<Project>");
throw new GracefulException(CommonLocalizableStrings.RequiredArgumentNotPassed, "<Project>");
}

var msbuildProj = MsbuildProject.FromFileOrDirectory(projectArgument.Value);
Expand Down
2 changes: 0 additions & 2 deletions test/dotnet-pack.Tests/PackTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit dc3d88c

Please sign in to comment.