diff --git a/OpenRA.Mods.Common/UtilityCommands/ExtractChromeStrings.cs b/OpenRA.Mods.Common/UtilityCommands/ExtractChromeStrings.cs index 5038ff9e34..5431d70256 100644 --- a/OpenRA.Mods.Common/UtilityCommands/ExtractChromeStrings.cs +++ b/OpenRA.Mods.Common/UtilityCommands/ExtractChromeStrings.cs @@ -130,8 +130,13 @@ namespace OpenRA.Mods.Common.UtilityCommands groupedCandidates[newHash] = new List() { candidate }; } + var startWithNewline = File.Exists(fluentPath); + + // StreamWriter can't create new directories. + if (!startWithNewline) + Directory.CreateDirectory(Path.GetDirectoryName(fluentPath)); + // Write to translation files. - Directory.CreateDirectory(Path.GetDirectoryName(fluentPath)); using (var fluentWriter = new StreamWriter(fluentPath, append: true)) { 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) continue; + if (startWithNewline) + fluentWriter.WriteLine(); + else + startWithNewline = true; + fluentWriter.WriteLine("## " + string.Join(", ", chromeFilename)); // 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)); } - // Recurse. + // Recursive. foreach (var childNode in node.Value.Nodes) if (childNode.Key == "Children") foreach (var n in childNode.Value.Nodes)