diff --git a/OpenRA.Game/Translation.cs b/OpenRA.Game/Translation.cs index 9e3c11f1c6..eaa29573a2 100644 --- a/OpenRA.Game/Translation.cs +++ b/OpenRA.Game/Translation.cs @@ -20,6 +20,7 @@ using Linguini.Shared.Types.Bundle; using Linguini.Syntax.Parser; using Linguini.Syntax.Parser.Error; using OpenRA.FileSystem; +using OpenRA.Traits; namespace OpenRA { @@ -27,6 +28,7 @@ namespace OpenRA public sealed class TranslationReferenceAttribute : Attribute { public readonly string[] RequiredVariableNames; + public readonly LintDictionaryReference DictionaryReference; public TranslationReferenceAttribute() { } @@ -34,6 +36,11 @@ namespace OpenRA { RequiredVariableNames = requiredVariableNames; } + + public TranslationReferenceAttribute(LintDictionaryReference dictionaryReference = LintDictionaryReference.None) + { + DictionaryReference = dictionaryReference; + } } public class Translation diff --git a/OpenRA.Mods.Common/Lint/CheckTranslationReference.cs b/OpenRA.Mods.Common/Lint/CheckTranslationReference.cs index dd2aa59cde..e01c7948e4 100644 --- a/OpenRA.Mods.Common/Lint/CheckTranslationReference.cs +++ b/OpenRA.Mods.Common/Lint/CheckTranslationReference.cs @@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Lint if (translationReference == null) continue; - var keys = LintExts.GetFieldValues(traitInfo, field); + var keys = LintExts.GetFieldValues(traitInfo, field, translationReference.DictionaryReference); foreach (var key in keys) { if (referencedKeys.Contains(key)) @@ -103,12 +103,15 @@ namespace OpenRA.Mods.Common.Lint { foreach (var fieldInfo in modType.GetFields(Binding).Where(m => Utility.HasAttribute(m))) { - if (fieldInfo.FieldType != typeof(string)) - emitError($"Translation attribute on non string field {fieldInfo.Name}."); - if (fieldInfo.IsInitOnly) continue; + if (fieldInfo.FieldType != typeof(string)) + { + emitError($"Translation attribute on non string field {fieldInfo.Name}."); + continue; + } + var key = (string)fieldInfo.GetValue(string.Empty); if (referencedKeys.Contains(key)) continue;