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;
|
||||||
using Linguini.Syntax.Parser.Error;
|
using Linguini.Syntax.Parser.Error;
|
||||||
using OpenRA.FileSystem;
|
using OpenRA.FileSystem;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA
|
namespace OpenRA
|
||||||
{
|
{
|
||||||
@@ -27,6 +28,7 @@ namespace OpenRA
|
|||||||
public sealed class TranslationReferenceAttribute : Attribute
|
public sealed class TranslationReferenceAttribute : Attribute
|
||||||
{
|
{
|
||||||
public readonly string[] RequiredVariableNames;
|
public readonly string[] RequiredVariableNames;
|
||||||
|
public readonly LintDictionaryReference DictionaryReference;
|
||||||
|
|
||||||
public TranslationReferenceAttribute() { }
|
public TranslationReferenceAttribute() { }
|
||||||
|
|
||||||
@@ -34,6 +36,11 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
RequiredVariableNames = requiredVariableNames;
|
RequiredVariableNames = requiredVariableNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TranslationReferenceAttribute(LintDictionaryReference dictionaryReference = LintDictionaryReference.None)
|
||||||
|
{
|
||||||
|
DictionaryReference = dictionaryReference;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Translation
|
public class Translation
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Lint
|
|||||||
if (translationReference == null)
|
if (translationReference == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var keys = LintExts.GetFieldValues(traitInfo, field);
|
var keys = LintExts.GetFieldValues(traitInfo, field, translationReference.DictionaryReference);
|
||||||
foreach (var key in keys)
|
foreach (var key in keys)
|
||||||
{
|
{
|
||||||
if (referencedKeys.Contains(key))
|
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)))
|
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)
|
if (fieldInfo.IsInitOnly)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (fieldInfo.FieldType != typeof(string))
|
||||||
|
{
|
||||||
|
emitError($"Translation attribute on non string field {fieldInfo.Name}.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var key = (string)fieldInfo.GetValue(string.Empty);
|
var key = (string)fieldInfo.GetValue(string.Empty);
|
||||||
if (referencedKeys.Contains(key))
|
if (referencedKeys.Contains(key))
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user