From 8894fdeaf9bf57df19039be4b00eab8d519b716f Mon Sep 17 00:00:00 2001 From: Gustas <37534529+PunkPun@users.noreply.github.com> Date: Sat, 29 Apr 2023 13:10:08 +0300 Subject: [PATCH] Add map translation parse error linting --- .../Lint/CheckTranslationSyntax.cs | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/OpenRA.Mods.Common/Lint/CheckTranslationSyntax.cs b/OpenRA.Mods.Common/Lint/CheckTranslationSyntax.cs index 814b65a770..fea4efedec 100644 --- a/OpenRA.Mods.Common/Lint/CheckTranslationSyntax.cs +++ b/OpenRA.Mods.Common/Lint/CheckTranslationSyntax.cs @@ -14,16 +14,30 @@ using System.Collections.Generic; using System.IO; using Linguini.Syntax.Ast; using Linguini.Syntax.Parser; +using OpenRA.FileSystem; namespace OpenRA.Mods.Common.Lint { - class CheckTranslationSyntax : ILintPass + class CheckTranslationSyntax : ILintPass, ILintMapPass { - public void Run(Action emitError, Action emitWarning, ModData modData) + void ILintMapPass.Run(Action emitError, Action emitWarning, ModData modData, Map map) { - foreach (var file in modData.Manifest.Translations) + if (map.TranslationDefinitions == null) + return; + + Run(emitError, emitWarning, map, FieldLoader.GetValue("value", map.TranslationDefinitions.Value)); + } + + void ILintPass.Run(Action emitError, Action emitWarning, ModData modData) + { + Run(emitError, emitWarning, modData.DefaultFileSystem, modData.Manifest.Translations); + } + + static void Run(Action emitError, Action emitWarning, IReadOnlyFileSystem fileSystem, string[] translations) + { + foreach (var file in translations) { - var stream = modData.DefaultFileSystem.Open(file); + var stream = fileSystem.Open(file); using (var reader = new StreamReader(stream)) { var ids = new List();