diff --git a/OpenRA.Mods.Common/Lint/CheckTranslationReference.cs b/OpenRA.Mods.Common/Lint/CheckTranslationReference.cs index 272d51a829..f4526823d1 100644 --- a/OpenRA.Mods.Common/Lint/CheckTranslationReference.cs +++ b/OpenRA.Mods.Common/Lint/CheckTranslationReference.cs @@ -16,6 +16,7 @@ using System.Linq; using System.Reflection; using Linguini.Syntax.Ast; using Linguini.Syntax.Parser; +using OpenRA.Traits; namespace OpenRA.Mods.Common.Lint { @@ -27,11 +28,36 @@ namespace OpenRA.Mods.Common.Lint readonly Dictionary referencedVariablesPerKey = new Dictionary(); readonly List variableReferences = new List(); - public void Run(Action emitError, Action emitWarning, ModData modData) + void ILintPass.Run(Action emitError, Action emitWarning, ModData modData) { + // TODO: Check all available languages var language = "en"; + Console.WriteLine($"Testing translation: {language}"); var translation = new Translation(language, modData.Manifest.Translations, modData.DefaultFileSystem); + foreach (var actorInfo in modData.DefaultRules.Actors) + { + foreach (var traitInfo in actorInfo.Value.TraitInfos()) + { + var fields = traitInfo.GetType().GetFields(); + foreach (var field in fields) + { + var translationReference = field.GetCustomAttributes(true).FirstOrDefault(); + if (translationReference == null) + continue; + + var keys = LintExts.GetFieldValues(traitInfo, field); + foreach (var key in keys) + { + if (!translation.HasMessage(key)) + emitError($"{key} not present in {language} translation."); + + referencedKeys.Add(key); + } + } + } + } + foreach (var modType in modData.ObjectCreator.GetTypes()) { foreach (var fieldInfo in modType.GetFields(Binding).Where(m => m.HasAttribute())) @@ -39,6 +65,9 @@ namespace OpenRA.Mods.Common.Lint if (fieldInfo.FieldType != typeof(string)) emitError($"Translation attribute on non string field {fieldInfo.Name}."); + if (fieldInfo.IsInitOnly) + continue; + var key = (string)fieldInfo.GetValue(string.Empty); if (!translation.HasMessage(key)) emitError($"{key} not present in {language} translation.");