Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localization and nuspec #322

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions CommandLine.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
<tags>command line commandline argument option parser parsing library syntax shell</tags>
<dependencies>
<group targetFramework=".NETStandard1.5">
<dependency id="System.Collections" version="4.0.11-rc2-24027" />
<dependency id="System.Console" version="4.0.0-rc2-24027" />
<dependency id="System.Diagnostics.Debug" version="4.0.11-rc2-24027" />
<dependency id="System.Globalization" version="4.0.11-rc2-24027" />
<dependency id="System.IO" version="4.1.0-rc2-24027" />
<dependency id="System.Linq" version="4.1.0-rc2-24027" />
<dependency id="System.Linq.Expressions" version="4.0.11-rc2-24027" />
<dependency id="System.Reflection" version="4.1.0-rc2-24027" />
<dependency id="System.Reflection.Extensions" version="4.0.1-rc2-24027" />
<dependency id="System.Reflection.TypeExtensions" version="4.1.0-rc2-24027" />
<dependency id="System.Resources.ResourceManager" version="4.0.1-rc2-24027" />
<dependency id="System.Runtime" version="4.1.0-rc2-24027" />
<dependency id="System.Runtime.Extensions" version="4.1.0-rc2-24027" />
<dependency id="System.Collections" version="4.3.0" />
<dependency id="System.Console" version="4.3.0" />
<dependency id="System.Diagnostics.Debug" version="4.3.0" />
<dependency id="System.Globalization" version="4.3.0" />
<dependency id="System.IO" version="4.3.0" />
<dependency id="System.Linq" version="4.3.0" />
<dependency id="System.Linq.Expressions" version="4.3.0" />
<dependency id="System.Reflection" version="4.3.0" />
<dependency id="System.Reflection.Extensions" version="4.3.0" />
<dependency id="System.Reflection.TypeExtensions" version="4.3.0" />
<dependency id="System.Resources.ResourceManager" version="4.3.0" />
<dependency id="System.Runtime" version="4.3.0" />
<dependency id="System.Runtime.Extensions" version="4.3.0" />
</group>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dependency changes will probably conflict with upcoming netcore standard 2.0 adjustments (#307)

</dependencies>
</metadata>
Expand Down
19 changes: 7 additions & 12 deletions src/CommandLine/Text/HelpText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ public HelpText AddOptions<T>(ParserResult<T> result)

return AddOptionsImpl(
GetSpecificationsFromType(result.TypeInfo.Current),
SentenceBuilder.RequiredWord(),
MaximumDisplayWidth);
}

Expand All @@ -433,7 +432,6 @@ public HelpText AddVerbs(params Type[] types)

return AddOptionsImpl(
AdaptVerbsToSpecifications(types),
SentenceBuilder.RequiredWord(),
MaximumDisplayWidth);
}

Expand All @@ -449,7 +447,6 @@ public HelpText AddOptions<T>(int maximumLength, ParserResult<T> result)

return AddOptionsImpl(
GetSpecificationsFromType(result.TypeInfo.Current),
SentenceBuilder.RequiredWord(),
maximumLength);
}

Expand All @@ -467,7 +464,6 @@ public HelpText AddVerbs(int maximumLength, params Type[] types)

return AddOptionsImpl(
AdaptVerbsToSpecifications(types),
SentenceBuilder.RequiredWord(),
maximumLength);
}

Expand Down Expand Up @@ -720,7 +716,6 @@ private IEnumerable<Specification> AdaptVerbsToSpecifications(IEnumerable<Type>

private HelpText AddOptionsImpl(
IEnumerable<Specification> specifications,
string requiredWord,
int maximumLength)
{
var maxLength = GetMaxLength(specifications);
Expand All @@ -731,7 +726,7 @@ private HelpText AddOptionsImpl(

specifications.ForEach(
option =>
AddOption(requiredWord, maxLength, option, remainingSpace));
AddOption(maxLength, option, remainingSpace));

return this;
}
Expand Down Expand Up @@ -765,7 +760,7 @@ private HelpText AddPreOptionsLine(string value, int maximumLength)
return this;
}

private HelpText AddOption(string requiredWord, int maxLength, Specification specification, int widthOfHelpText)
private HelpText AddOption(int maxLength, Specification specification, int widthOfHelpText)
{
if (specification.Hidden)
return this;
Expand All @@ -784,13 +779,13 @@ private HelpText AddOption(string requiredWord, int maxLength, Specification spe
var optionHelpText = specification.HelpText;

if (addEnumValuesToHelpText && specification.EnumValues.Any())
optionHelpText += " Valid values: " + string.Join(", ", specification.EnumValues);
optionHelpText += " {0}: ".FormatInvariant(SentenceBuilder.ValidValuesPhrase()) + string.Join(", ", specification.EnumValues);

specification.DefaultValue.Do(
defaultValue => optionHelpText = "(Default: {0}) ".FormatInvariant(FormatDefaultValue(defaultValue)) + optionHelpText);
defaultValue => optionHelpText = "({0}: {1}) ".FormatInvariant(SentenceBuilder.DefaultWord(), FormatDefaultValue(defaultValue)) + optionHelpText);

if (specification.Required)
optionHelpText = "{0} ".FormatInvariant(requiredWord) + optionHelpText;
optionHelpText = "{0} ".FormatInvariant(SentenceBuilder.RequiredWord()) + optionHelpText;

if (!string.IsNullOrEmpty(optionHelpText))
{
Expand Down Expand Up @@ -860,8 +855,8 @@ private string AddValueName(int maxLength, ValueSpecification specification)
return new StringBuilder(maxLength)
.BimapIf(
specification.MetaName.Length > 0,
it => it.AppendFormat("{0} (pos. {1})", specification.MetaName, specification.Index),
it => it.AppendFormat("value pos. {0}", specification.Index))
it => it.AppendFormat("{0} ({1} {2})", specification.MetaName, SentenceBuilder.PositionWord(), specification.Index),
it => it.AppendFormat("{0} {1}", SentenceBuilder.ValuePositionPhrase(), specification.Index))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these localization changes dont actually fit the need.

Some languages might need the number in a different spot. French sometimes likes '1 de juen' instead of 'june 1' for example (thats a date but you should understand my point).

The strings might need to include numeric placeholders too... I feel like localization for now needs to be reconsidered and rearchitected in this lib.

.AppendFormatWhen(
specification.MetaValue.Length > 0, " {0}", specification.MetaValue)
.ToString();
Expand Down
40 changes: 40 additions & 0 deletions src/CommandLine/Text/SentenceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ public static SentenceBuilder Create()
/// </summary>
public abstract Func<string> RequiredWord { get; }

/// <summary>
/// Gets a delegate that returns the word 'Default'.
/// </summary>
public abstract Func<string> DefaultWord { get; }

/// <summary>
/// Gets a delegate that returns the word 'pos.'.
/// </summary>
public abstract Func<string> PositionWord { get; }

/// <summary>
/// Gets a delegate that returns the phrase 'value pos.'.
/// </summary>
public abstract Func<string> ValuePositionPhrase { get; }

/// <summary>
/// Gets a delegate that returns the phrase 'Valid values'.
/// </summary>
public abstract Func<string> ValidValuesPhrase { get; }

/// <summary>
/// Gets a delegate that returns that errors block heading text.
/// </summary>
Expand Down Expand Up @@ -74,6 +94,26 @@ public override Func<string> RequiredWord
get { return () => "Required."; }
}

public override Func<string> DefaultWord
{
get { return () => "Default"; }
}

public override Func<string> PositionWord
{
get { return () => "pos."; }
}

public override Func<string> ValuePositionPhrase
{
get { return () => "value pos."; }
}

public override Func<string> ValidValuesPhrase
{
get { return () => "Valid values"; }
}

public override Func<string> ErrorsHeadingText
{
get { return () => "ERROR(S):"; }
Expand Down