Add support for translating trait rules.
This commit is contained in:
committed by
Gustas
parent
e251377f7c
commit
aefa49a831
@@ -16,6 +16,7 @@ using System.Linq;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Linguini.Syntax.Ast;
|
using Linguini.Syntax.Ast;
|
||||||
using Linguini.Syntax.Parser;
|
using Linguini.Syntax.Parser;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Lint
|
namespace OpenRA.Mods.Common.Lint
|
||||||
{
|
{
|
||||||
@@ -27,11 +28,36 @@ namespace OpenRA.Mods.Common.Lint
|
|||||||
readonly Dictionary<string, string[]> referencedVariablesPerKey = new Dictionary<string, string[]>();
|
readonly Dictionary<string, string[]> referencedVariablesPerKey = new Dictionary<string, string[]>();
|
||||||
readonly List<string> variableReferences = new List<string>();
|
readonly List<string> variableReferences = new List<string>();
|
||||||
|
|
||||||
public void Run(Action<string> emitError, Action<string> emitWarning, ModData modData)
|
void ILintPass.Run(Action<string> emitError, Action<string> emitWarning, ModData modData)
|
||||||
{
|
{
|
||||||
|
// TODO: Check all available languages
|
||||||
var language = "en";
|
var language = "en";
|
||||||
|
Console.WriteLine($"Testing translation: {language}");
|
||||||
var translation = new Translation(language, modData.Manifest.Translations, modData.DefaultFileSystem);
|
var translation = new Translation(language, modData.Manifest.Translations, modData.DefaultFileSystem);
|
||||||
|
|
||||||
|
foreach (var actorInfo in modData.DefaultRules.Actors)
|
||||||
|
{
|
||||||
|
foreach (var traitInfo in actorInfo.Value.TraitInfos<TraitInfo>())
|
||||||
|
{
|
||||||
|
var fields = traitInfo.GetType().GetFields();
|
||||||
|
foreach (var field in fields)
|
||||||
|
{
|
||||||
|
var translationReference = field.GetCustomAttributes<TranslationReferenceAttribute>(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 modType in modData.ObjectCreator.GetTypes())
|
||||||
{
|
{
|
||||||
foreach (var fieldInfo in modType.GetFields(Binding).Where(m => m.HasAttribute<TranslationReferenceAttribute>()))
|
foreach (var fieldInfo in modType.GetFields(Binding).Where(m => m.HasAttribute<TranslationReferenceAttribute>()))
|
||||||
@@ -39,6 +65,9 @@ namespace OpenRA.Mods.Common.Lint
|
|||||||
if (fieldInfo.FieldType != typeof(string))
|
if (fieldInfo.FieldType != typeof(string))
|
||||||
emitError($"Translation attribute on non string field {fieldInfo.Name}.");
|
emitError($"Translation attribute on non string field {fieldInfo.Name}.");
|
||||||
|
|
||||||
|
if (fieldInfo.IsInitOnly)
|
||||||
|
continue;
|
||||||
|
|
||||||
var key = (string)fieldInfo.GetValue(string.Empty);
|
var key = (string)fieldInfo.GetValue(string.Empty);
|
||||||
if (!translation.HasMessage(key))
|
if (!translation.HasMessage(key))
|
||||||
emitError($"{key} not present in {language} translation.");
|
emitError($"{key} not present in {language} translation.");
|
||||||
|
|||||||
Reference in New Issue
Block a user