Report linguini parse errors
Reports duplicate keys
This commit is contained in:
committed by
Matthias Mailänder
parent
bf66068557
commit
a9a7777293
@@ -18,6 +18,7 @@ using Linguini.Bundle;
|
|||||||
using Linguini.Bundle.Builder;
|
using Linguini.Bundle.Builder;
|
||||||
using Linguini.Shared.Types.Bundle;
|
using Linguini.Shared.Types.Bundle;
|
||||||
using Linguini.Syntax.Parser;
|
using Linguini.Syntax.Parser;
|
||||||
|
using Linguini.Syntax.Parser.Error;
|
||||||
using OpenRA.FileSystem;
|
using OpenRA.FileSystem;
|
||||||
|
|
||||||
namespace OpenRA
|
namespace OpenRA
|
||||||
@@ -40,6 +41,9 @@ namespace OpenRA
|
|||||||
readonly FluentBundle bundle;
|
readonly FluentBundle bundle;
|
||||||
|
|
||||||
public Translation(string language, string[] translations, IReadOnlyFileSystem fileSystem)
|
public Translation(string language, string[] translations, IReadOnlyFileSystem fileSystem)
|
||||||
|
: this(language, translations, fileSystem, error => Log.Write("debug", error.ToString())) { }
|
||||||
|
|
||||||
|
public Translation(string language, string[] translations, IReadOnlyFileSystem fileSystem, Action<ParseError> onError)
|
||||||
{
|
{
|
||||||
if (translations == null || translations.Length == 0)
|
if (translations == null || translations.Length == 0)
|
||||||
return;
|
return;
|
||||||
@@ -51,10 +55,10 @@ namespace OpenRA
|
|||||||
.UseConcurrent()
|
.UseConcurrent()
|
||||||
.UncheckedBuild();
|
.UncheckedBuild();
|
||||||
|
|
||||||
ParseTranslations(language, translations, fileSystem);
|
ParseTranslations(language, translations, fileSystem, onError);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParseTranslations(string language, string[] translations, IReadOnlyFileSystem fileSystem)
|
void ParseTranslations(string language, string[] translations, IReadOnlyFileSystem fileSystem, Action<ParseError> onError)
|
||||||
{
|
{
|
||||||
// Always load english strings to provide a fallback for missing translations.
|
// Always load english strings to provide a fallback for missing translations.
|
||||||
// It is important to load the english files first so the chosen language's files can override them.
|
// It is important to load the english files first so the chosen language's files can override them.
|
||||||
@@ -71,7 +75,7 @@ namespace OpenRA
|
|||||||
var parser = new LinguiniParser(reader);
|
var parser = new LinguiniParser(reader);
|
||||||
var resource = parser.Parse();
|
var resource = parser.Parse();
|
||||||
foreach (var error in resource.Errors)
|
foreach (var error in resource.Errors)
|
||||||
Log.Write("debug", error.ToString());
|
onError(error);
|
||||||
|
|
||||||
bundle.AddResourceOverriding(resource);
|
bundle.AddResourceOverriding(resource);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,8 +62,8 @@ namespace OpenRA.Mods.Common.Lint
|
|||||||
|
|
||||||
// TODO: Check all available languages.
|
// TODO: Check all available languages.
|
||||||
var language = "en";
|
var language = "en";
|
||||||
var modTranslation = new Translation(language, modData.Manifest.Translations, modData.DefaultFileSystem);
|
var modTranslation = new Translation(language, modData.Manifest.Translations, modData.DefaultFileSystem, _ => { });
|
||||||
var mapTranslation = new Translation(language, FieldLoader.GetValue<string[]>("value", map.TranslationDefinitions.Value), map);
|
var mapTranslation = new Translation(language, FieldLoader.GetValue<string[]>("value", map.TranslationDefinitions.Value), map, error => emitError(error.ToString()));
|
||||||
|
|
||||||
TestTraits(map.Rules, key =>
|
TestTraits(map.Rules, key =>
|
||||||
{
|
{
|
||||||
@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Lint
|
|||||||
// TODO: Check all available languages.
|
// TODO: Check all available languages.
|
||||||
var language = "en";
|
var language = "en";
|
||||||
Console.WriteLine($"Testing translation: {language}");
|
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, error => emitError(error.ToString()));
|
||||||
|
|
||||||
TestTraits(modData.DefaultRules, key =>
|
TestTraits(modData.DefaultRules, key =>
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user