Skip to content

Commit 0cf52e6

Browse files
committed
refactor: Misc fixes in Stride.Core.Translation.Extractor project
1 parent fa5791f commit 0cf52e6

5 files changed

Lines changed: 22 additions & 34 deletions

File tree

sources/tools/Stride.Core.Translation.Extractor/Exporters/ResxExporter.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

sources/tools/Stride.Core.Translation.Extractor/Extractors/CSharpExtractor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ internal class CSharpExtractor : ExtractorBase
3434
private const RegexOptions PatternOptions = RegexOptions.Compiled | RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline;
3535

3636
private readonly (string, Regex)[] patterns =
37-
{
37+
[
3838
(nameof(ITranslationProvider.GetString), new Regex($@"{nameof(ITranslationProvider.GetString)}\s*\(\s*{CSharpStringPattern}", PatternOptions)),
3939
(nameof(ITranslationProvider.GetString), new Regex($@"{nameof(Tr._)}\s*\(\s*{CSharpStringPattern}", PatternOptions)),
4040
(nameof(ITranslationProvider.GetParticularString), new Regex($@"{nameof(ITranslationProvider.GetParticularString)}\s*\(\s*{CSharpStringPattern}\s*,\s*{CSharpStringPattern}", PatternOptions)),
@@ -43,8 +43,8 @@ private readonly (string, Regex)[] patterns =
4343
(nameof(ITranslationProvider.GetPluralString), new Regex($@"{nameof(Tr._n)}\s*\(\s*{CSharpStringPattern}\s*,\s*{CSharpStringPattern}", PatternOptions)),
4444
(nameof(ITranslationProvider.GetParticularPluralString), new Regex($@"{nameof(ITranslationProvider.GetParticularPluralString)}\s*\(\s*{CSharpStringPattern}\s*,\s*{CSharpStringPattern}\s*,\s*{CSharpStringPattern}", PatternOptions)),
4545
(nameof(ITranslationProvider.GetParticularPluralString), new Regex($@"{nameof(Tr._pn)}\s*\(\s*{CSharpStringPattern}\s*,\s*{CSharpStringPattern}\s*,\s*{CSharpStringPattern}", PatternOptions)),
46-
(nameof(TranslationAttribute), new Regex($@"Translation\({CSharpStringPattern}(?:\s*,\s*{CSharpStringPattern})?(?:\s*,\s*{nameof(TranslationAttribute.Context)}\s*\=\s*{CSharpStringPattern})?", PatternOptions)),
47-
};
46+
(nameof(TranslationAttribute), new Regex($@"Translation\({CSharpStringPattern}(?:\s*,\s*{CSharpStringPattern})?(?:\s*,\s*{nameof(TranslationAttribute.Context)}\s*\=\s*{CSharpStringPattern})?", PatternOptions))
47+
];
4848

4949
public CSharpExtractor([NotNull] ICollection<UFile> inputFiles)
5050
: base(inputFiles, ".cs")

sources/tools/Stride.Core.Translation.Extractor/Extractors/XamlExtractor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected override IEnumerable<Message> ExtractMessagesFromFile(UFile file)
2828
catch (XamlException ex)
2929
{
3030
Console.Error.WriteLine($"{file.ToOSPath()}: {ex.Message}");
31-
return Enumerable.Empty<Message>();
31+
return [];
3232
}
3333
}
3434

sources/tools/Stride.Core.Translation.Extractor/Options.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ internal class Options
1414
/// <summary>
1515
/// Patterns to exclude from the list of inputs.
1616
/// </summary>
17-
public List<string> Excludes { get; } = new List<string>();
17+
public List<string> Excludes { get; } = [];
1818

1919
/// <summary>
2020
/// Directories to search for input files.
2121
/// </summary>
22-
public List<string> InputDirs { get; } = new List<string>();
22+
public List<string> InputDirs { get; } = [];
2323

2424
/// <summary>
25-
/// Patterns or input filnames to extract the messages from.
25+
/// Patterns or input file names to extract the messages from.
2626
/// </summary>
27-
public List<string> InputFiles { get; } = new List<string>();
27+
public List<string> InputFiles { get; } = [];
2828

2929
/// <summary>
3030
/// Name of generated catalog file.

sources/tools/Stride.Core.Translation.Extractor/Program.cs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,23 @@ namespace Stride.Core.Translation.Extractor
1616
{
1717
internal static class Program
1818
{
19-
private static readonly LongOpt[] LOpts = {
20-
new LongOpt("directory", Argument.Required, null, 'D'),
21-
new LongOpt("recursive", Argument.No, null, 'r'),
22-
new LongOpt("exclude", Argument.Required, null, 'x'),
23-
new LongOpt("domain-name", Argument.Required, null, 'd'),
24-
new LongOpt("backup", Argument.No, null, 'b'),
25-
new LongOpt("output", Argument.Required, null, 'o'),
26-
new LongOpt("merge", Argument.No, null, 'm'),
27-
new LongOpt("preserve-comments", Argument.No, null, 'C'),
28-
new LongOpt("verbose", Argument.No, null, 'v'),
29-
new LongOpt("help", Argument.No, null, 'h'),
30-
};
19+
private static readonly LongOpt[] LOpts =
20+
[
21+
new("directory", Argument.Required, null, 'D'),
22+
new("recursive", Argument.No, null, 'r'),
23+
new("exclude", Argument.Required, null, 'x'),
24+
new("domain-name", Argument.Required, null, 'd'),
25+
new("backup", Argument.No, null, 'b'),
26+
new("output", Argument.Required, null, 'o'),
27+
new("merge", Argument.No, null, 'm'),
28+
new("preserve-comments", Argument.No, null, 'C'),
29+
new("verbose", Argument.No, null, 'v'),
30+
new("help", Argument.No, null, 'h')
31+
];
3132
private static readonly string SOpts = "-:D:rx:d:bo:mCvh";
3233

3334
private static int Main([NotNull] string[] args)
3435
{
35-
#if DEBUG
36-
// Allow to attach debugger
37-
Console.ReadLine();
38-
#endif // DEBUG
3936
if (args.Length == 0)
4037
{
4138
ShowUsage();
@@ -66,7 +63,7 @@ private static int Main([NotNull] string[] args)
6663
TranslationManager.Instance.RegisterProvider(new GettextTranslationProvider());
6764

6865
// Compute the list of input files
69-
ISet<UFile> inputFiles = new HashSet<UFile>();
66+
HashSet<UFile> inputFiles = [];
7067
var re = options.Excludes.Count > 0 ? new Regex(string.Join("|", options.Excludes.Select(x => Regex.Escape(x).Replace(@"\*", @".*")))) : null;
7168
foreach (var path in options.InputDirs)
7269
{

0 commit comments

Comments
 (0)