-
Notifications
You must be signed in to change notification settings - Fork 416
Expand file tree
/
Copy pathLocalizationResources.cs
More file actions
269 lines (228 loc) · 14.1 KB
/
LocalizationResources.cs
File metadata and controls
269 lines (228 loc) · 14.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using System.CommandLine.Parsing;
using System.IO;
using System.Linq;
namespace System.CommandLine
{
/// <summary>
/// Provides localizable strings for help and error messages.
/// </summary>
internal static class LocalizationResources
{
/// <summary>
/// Interpolates values into a localized string similar to Option '{0}' expects a single argument but {1} were provided.
/// </summary>
internal static string ExpectsOneArgument(OptionResult optionResult)
=> GetResourceString(Properties.Resources.OptionExpectsOneArgument, GetOptionName(optionResult), optionResult.Tokens.Count);
/// <summary>
/// Interpolates values into a localized string similar to Option '{0}' expects at most {1} arguments but {2} were provided.
/// </summary>
internal static string OptionArgumentsMaximumExceeded(OptionResult optionResult, int maximumOptionArgumentsAllowed)
=> OptionArgumentsMaximumExceeded(GetOptionName(optionResult), maximumOptionArgumentsAllowed, optionResult.Tokens.Count);
/// <summary>
/// Interpolates values into a localized string similar to Option '{0}' expects at most {1} arguments but {2} were provided.
/// </summary>
internal static string OptionArgumentsMaximumExceeded(string optionName, int maximumOptionArgumentsAllowed, int foundTokenCount)
=> GetResourceString(Properties.Resources.OptionArgumentsMaximumExceeded, optionName, maximumOptionArgumentsAllowed, foundTokenCount);
/// <summary>
/// Interpolates values into a localized string similar to Directory does not exist: {0}.
/// </summary>
internal static string DirectoryDoesNotExist(string path) =>
GetResourceString(Properties.Resources.DirectoryDoesNotExist, path);
/// <summary>
/// Interpolates values into a localized string similar to File does not exist: {0}.
/// </summary>
internal static string FileDoesNotExist(string filePath) =>
GetResourceString(Properties.Resources.FileDoesNotExist, filePath);
/// <summary>
/// Interpolates values into a localized string similar to File or directory does not exist: {0}.
/// </summary>
internal static string FileOrDirectoryDoesNotExist(string path) =>
GetResourceString(Properties.Resources.FileOrDirectoryDoesNotExist, path);
/// <summary>
/// Interpolates values into a localized string similar to Character not allowed in a path: {0}.
/// </summary>
internal static string InvalidCharactersInPath(char invalidChar) =>
GetResourceString(Properties.Resources.InvalidCharactersInPath, invalidChar);
/// <summary>
/// Interpolates values into a localized string similar to Character not allowed in a file name: {0}.
/// </summary>
internal static string InvalidCharactersInFileName(char invalidChar) =>
GetResourceString(Properties.Resources.InvalidCharactersInFileName, invalidChar);
/// <summary>
/// Interpolates values into a localized string similar to Required argument missing for command: {0}.
/// </summary>
internal static string RequiredArgumentMissing(ArgumentResult argumentResult) =>
argumentResult.Parent is CommandResult commandResult
? GetResourceString(Properties.Resources.CommandRequiredArgumentMissing, commandResult.IdentifierToken.Value)
: RequiredArgumentMissing((OptionResult)argumentResult.Parent!);
/// <summary>
/// Interpolates values into a localized string similar to Required argument missing for option: {0}.
/// </summary>
internal static string RequiredArgumentMissing(OptionResult optionResult) =>
GetResourceString(Properties.Resources.OptionRequiredArgumentMissing, GetOptionName(optionResult));
/// <summary>
/// Interpolates values into a localized string similar to Required command was not provided.
/// </summary>
internal static string RequiredCommandWasNotProvided() =>
GetResourceString(Properties.Resources.RequiredCommandWasNotProvided);
/// <summary>
/// Interpolates values into a localized string similar to Option '{0}' is required.
/// </summary>
internal static string RequiredOptionWasNotProvided(string longestAliasWithPrefix) =>
GetResourceString(Properties.Resources.RequiredOptionWasNotProvided, longestAliasWithPrefix);
/// <summary>
/// Interpolates values into a localized string similar to Argument '{0}' not recognized. Must be one of:{1}.
/// </summary>
internal static string UnrecognizedArgument(string unrecognizedArg, IReadOnlyCollection<string> allowedValues) =>
GetResourceString(Properties.Resources.UnrecognizedArgument, unrecognizedArg, $"\n\t{string.Join("\n\t", allowedValues.Select(v => $"'{v}'"))}");
/// <summary>
/// Interpolates values into a localized string similar to Unrecognized command or argument '{0}'.
/// </summary>
internal static string UnrecognizedCommandOrArgument(string arg) =>
GetResourceString(Properties.Resources.UnrecognizedCommandOrArgument, arg);
/// <summary>
/// Interpolates values into a localized string similar to Response file not found '{0}'.
/// </summary>
internal static string ResponseFileNotFound(string filePath) =>
GetResourceString(Properties.Resources.ResponseFileNotFound, filePath);
/// <summary>
/// Interpolates values into a localized string similar to Error reading response file '{0}': {1}.
/// </summary>
internal static string ErrorReadingResponseFile(string filePath, IOException e) =>
GetResourceString(Properties.Resources.ErrorReadingResponseFile, filePath, e.Message);
/// <summary>
/// Interpolates values into a localized string similar to Show help and usage information.
/// </summary>
internal static string HelpOptionDescription() =>
GetResourceString(Properties.Resources.HelpOptionDescription);
/// <summary>
/// Interpolates values into a localized string similar to Usage:.
/// </summary>
internal static string HelpUsageTitle() =>
GetResourceString(Properties.Resources.HelpUsageTitle);
/// <summary>
/// Interpolates values into a localized string similar to Description:.
/// </summary>
internal static string HelpDescriptionTitle() =>
GetResourceString(Properties.Resources.HelpDescriptionTitle);
/// <summary>
/// Interpolates values into a localized string similar to [options].
/// </summary>
internal static string HelpUsageOptions() =>
GetResourceString(Properties.Resources.HelpUsageOptions);
/// <summary>
/// Interpolates values into a localized string similar to [command].
/// </summary>
internal static string HelpUsageCommand() =>
GetResourceString(Properties.Resources.HelpUsageCommand);
/// <summary>
/// Interpolates values into a localized string similar to [[--] <additional arguments>...]].
/// </summary>
internal static string HelpUsageAdditionalArguments() =>
GetResourceString(Properties.Resources.HelpUsageAdditionalArguments);
/// <summary>
/// Interpolates values into a localized string similar to Arguments:.
/// </summary>
internal static string HelpArgumentsTitle() =>
GetResourceString(Properties.Resources.HelpArgumentsTitle);
/// <summary>
/// Interpolates values into a localized string similar to Options:.
/// </summary>
internal static string HelpOptionsTitle() =>
GetResourceString(Properties.Resources.HelpOptionsTitle);
/// <summary>
/// Interpolates values into a localized string similar to (REQUIRED).
/// </summary>
internal static string HelpOptionsRequiredLabel() =>
GetResourceString(Properties.Resources.HelpOptionsRequiredLabel);
/// <summary>
/// Interpolates values into a localized string similar to default.
/// </summary>
internal static string HelpArgumentDefaultValueLabel() =>
GetResourceString(Properties.Resources.HelpArgumentDefaultValueLabel);
/// <summary>
/// Interpolates values into a localized string similar to Commands:.
/// </summary>
internal static string HelpCommandsTitle() =>
GetResourceString(Properties.Resources.HelpCommandsTitle);
/// <summary>
/// Interpolates values into a localized string similar to Additional Arguments:.
/// </summary>
internal static string HelpAdditionalArgumentsTitle() =>
GetResourceString(Properties.Resources.HelpAdditionalArgumentsTitle);
/// <summary>
/// Interpolates values into a localized string similar to Arguments passed to the application that is being run..
/// </summary>
internal static string HelpAdditionalArgumentsDescription() =>
GetResourceString(Properties.Resources.HelpAdditionalArgumentsDescription);
/// <summary>
/// Interpolates values into a localized string similar to '{0}' was not matched. Did you mean one of the following?.
/// </summary>
internal static string SuggestionsTokenNotMatched(string token)
=> GetResourceString(Properties.Resources.SuggestionsTokenNotMatched, token);
/// <summary>
/// Interpolates values into a localized string similar to Show version information.
/// </summary>
internal static string VersionOptionDescription()
=> GetResourceString(Properties.Resources.VersionOptionDescription);
/// <summary>
/// Interpolates values into a localized string similar to {0} option cannot be combined with other arguments..
/// </summary>
internal static string VersionOptionCannotBeCombinedWithOtherArguments(string optionAlias)
=> GetResourceString(Properties.Resources.VersionOptionCannotBeCombinedWithOtherArguments, optionAlias);
/// <summary>
/// Interpolates values into a localized string similar to Unhandled exception: .
/// </summary>
internal static string ExceptionHandlerHeader()
=> GetResourceString(Properties.Resources.ExceptionHandlerHeader);
/// <summary>
/// Interpolates values into a localized string similar to Cannot parse argument '{0}' as expected type {1}..
/// </summary>
internal static string ArgumentConversionCannotParse(string value, Type expectedType)
=> GetResourceString(Properties.Resources.ArgumentConversionCannotParse, value, expectedType);
/// <summary>
/// Interpolates values into a localized string similar to Cannot parse argument '{0}' for command '{1}' as expected type {2}..
/// </summary>
internal static string ArgumentConversionCannotParseForCommand(string value, string commandAlias, Type expectedType)
=> GetResourceString(Properties.Resources.ArgumentConversionCannotParseForCommand, value, commandAlias, expectedType);
/// <summary>
/// Interpolates values into a localized string similar to Cannot parse argument '{0}' for command '{1}' as expected type {2}..
/// </summary>
internal static string ArgumentConversionCannotParseForCommand(string value, string commandAlias, Type expectedType, IEnumerable<string> completions)
=> GetResourceString(Properties.Resources.ArgumentConversionCannotParseForCommand_Completions,
value, commandAlias, expectedType, Environment.NewLine + string.Join(Environment.NewLine, completions));
/// <summary>
/// Interpolates values into a localized string similar to Cannot parse argument '{0}' for option '{1}' as expected type {2}..
/// </summary>
internal static string ArgumentConversionCannotParseForOption(string value, string optionAlias, Type expectedType)
=> GetResourceString(Properties.Resources.ArgumentConversionCannotParseForOption, value, optionAlias, expectedType);
/// <summary>
/// Interpolates values into a localized string similar to Cannot parse argument '{0}' for option '{1}' as expected type {2}..
/// </summary>
internal static string ArgumentConversionCannotParseForOption(string value, string optionAlias, Type expectedType, IEnumerable<string> completions)
=> GetResourceString(Properties.Resources.ArgumentConversionCannotParseForOption_Completions,
value, optionAlias, expectedType, Environment.NewLine + string.Join(Environment.NewLine, completions));
/// <summary>
/// Interpolates values into a localized string.
/// </summary>
/// <param name="resourceString">The string template into which values will be interpolated.</param>
/// <param name="formatArguments">The values to interpolate.</param>
/// <returns>The final string after interpolation.</returns>
private static string GetResourceString(string resourceString, params object[] formatArguments)
{
if (resourceString is null)
{
return string.Empty;
}
if (formatArguments.Length > 0)
{
return string.Format(resourceString, formatArguments);
}
return resourceString;
}
private static string GetOptionName(OptionResult optionResult) => optionResult.IdentifierToken?.Value ?? optionResult.Option.Name;
}
}