Mod metadata, load screens and mod content is all now sourced from ftl files, allowing these items to be translated. Translations are now initialized as part of ModData creation, as currently they are made available too late for the usage we need here. The "modcontent" mod learns a new parameter for "Content.TranslationFile" - this allows a mod to provide the path of a translation file to the mod which it can load. This allows mods such as ra, cnc, d2k, ts to own the translations for their ModContent, yet still make them accessible to the modcontent mod. CheckFluentReference learns to validate all these new fields to ensure translations have been set.
65 lines
2.0 KiB
C#
65 lines
2.0 KiB
C#
#region Copyright & License Information
|
|
/*
|
|
* Copyright (c) The OpenRA Developers and Contributors
|
|
* This file is part of OpenRA, which is free software. It is made
|
|
* available to you under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation, either version 3 of
|
|
* the License, or (at your option) any later version. For more
|
|
* information, see COPYING.
|
|
*/
|
|
#endregion
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using Linguini.Syntax.Ast;
|
|
using Linguini.Syntax.Parser;
|
|
using OpenRA.FileSystem;
|
|
|
|
namespace OpenRA.Mods.Common.Lint
|
|
{
|
|
sealed class CheckFluentSyntax : ILintPass, ILintMapPass
|
|
{
|
|
void ILintMapPass.Run(Action<string> emitError, Action<string> emitWarning, ModData modData, Map map)
|
|
{
|
|
if (map.TranslationDefinitions == null)
|
|
return;
|
|
|
|
Run(emitError, emitWarning, map, FieldLoader.GetValue<string[]>("value", map.TranslationDefinitions.Value));
|
|
}
|
|
|
|
void ILintPass.Run(Action<string> emitError, Action<string> emitWarning, ModData modData)
|
|
{
|
|
var allModTranslations = modData.Manifest.Translations.Append(modData.Manifest.Get<ModContent>().Translation);
|
|
Run(emitError, emitWarning, modData.DefaultFileSystem, allModTranslations);
|
|
}
|
|
|
|
static void Run(Action<string> emitError, Action<string> emitWarning, IReadOnlyFileSystem fileSystem, IEnumerable<string> paths)
|
|
{
|
|
foreach (var path in paths)
|
|
{
|
|
var stream = fileSystem.Open(path);
|
|
using (var reader = new StreamReader(stream))
|
|
{
|
|
var ids = new List<string>();
|
|
var parser = new LinguiniParser(reader);
|
|
var resource = parser.Parse();
|
|
foreach (var entry in resource.Entries)
|
|
{
|
|
if (entry is Junk junk)
|
|
emitError($"{junk.GetId()}: {junk.AsStr()} in {path} {junk.Content}.");
|
|
|
|
if (entry is AstMessage message)
|
|
{
|
|
if (ids.Contains(message.Id.Name.ToString()))
|
|
emitWarning($"Duplicate ID `{message.Id.Name}` in {path}.");
|
|
|
|
ids.Add(message.Id.Name.ToString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|