Match better newline format

This commit is contained in:
Gustas
2023-11-16 14:03:11 +02:00
committed by Matthias Mailänder
parent 6386e96134
commit 4b7036be0f

View File

@@ -130,8 +130,13 @@ namespace OpenRA.Mods.Common.UtilityCommands
groupedCandidates[newHash] = new List<TranslationCandidate>() { candidate }; groupedCandidates[newHash] = new List<TranslationCandidate>() { candidate };
} }
var startWithNewline = File.Exists(fluentPath);
// StreamWriter can't create new directories.
if (!startWithNewline)
Directory.CreateDirectory(Path.GetDirectoryName(fluentPath));
// Write to translation files. // Write to translation files.
Directory.CreateDirectory(Path.GetDirectoryName(fluentPath));
using (var fluentWriter = new StreamWriter(fluentPath, append: true)) using (var fluentWriter = new StreamWriter(fluentPath, append: true))
{ {
foreach (var (chromeFilename, candidates) in groupedCandidates.OrderBy(t => string.Join(',', t.Key))) foreach (var (chromeFilename, candidates) in groupedCandidates.OrderBy(t => string.Join(',', t.Key)))
@@ -139,6 +144,11 @@ namespace OpenRA.Mods.Common.UtilityCommands
if (candidates.Count == 0) if (candidates.Count == 0)
continue; continue;
if (startWithNewline)
fluentWriter.WriteLine();
else
startWithNewline = true;
fluentWriter.WriteLine("## " + string.Join(", ", chromeFilename)); fluentWriter.WriteLine("## " + string.Join(", ", chromeFilename));
// Pushing blocks of translations to string first allows for fancier formatting. // Pushing blocks of translations to string first allows for fancier formatting.
@@ -185,7 +195,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
} }
} }
fluentWriter.WriteLine(build.Trim('\n') + '\n'); fluentWriter.WriteLine(build.Trim('\n'));
} }
} }
@@ -304,7 +314,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
translations.Add(new TranslationCandidate(translationKey, childType, translationValue.Trim().Trim('\n'), childNode)); translations.Add(new TranslationCandidate(translationKey, childType, translationValue.Trim().Trim('\n'), childNode));
} }
// Recurse. // Recursive.
foreach (var childNode in node.Value.Nodes) foreach (var childNode in node.Value.Nodes)
if (childNode.Key == "Children") if (childNode.Key == "Children")
foreach (var n in childNode.Value.Nodes) foreach (var n in childNode.Value.Nodes)