Allow localisation of dictionary values.
This commit is contained in:
committed by
Gustas
parent
55ff0ac1f4
commit
af6330b1bd
@@ -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
|
||||
|
||||
@@ -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<TranslationReferenceAttribute>(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;
|
||||
|
||||
Reference in New Issue
Block a user