Expose mod.yaml content to localisation.

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.
This commit is contained in:
RoosterDragon
2024-09-23 19:58:33 +01:00
committed by Gustas
parent d1583e8587
commit bb17cfa179
36 changed files with 292 additions and 144 deletions

View File

@@ -11,6 +11,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using OpenRA.FileSystem;
using OpenRA.Widgets;
@@ -30,10 +31,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
readonly Dictionary<string, ModContent.ModSource> sources = new();
readonly Dictionary<string, ModContent.ModDownload> downloads = new();
readonly FluentBundle externalFluentBundle;
bool sourceAvailable;
[ObjectCreator.UseCtor]
public ModContentLogic(Widget widget, Manifest mod, ModContent content, Action onCancel)
public ModContentLogic(Widget widget, Manifest mod, ModContent content, Action onCancel, string translationFilePath)
{
this.content = content;
@@ -58,20 +61,25 @@ namespace OpenRA.Mods.Common.Widgets.Logic
modFileSystem.UnmountAll();
externalFluentBundle = new FluentBundle(Game.Settings.Player.Language, File.ReadAllText(translationFilePath), _ => { });
scrollPanel = panel.Get<ScrollPanelWidget>("PACKAGES");
template = scrollPanel.Get<ContainerWidget>("PACKAGE_TEMPLATE");
var headerTemplate = panel.Get<LabelWidget>("HEADER_TEMPLATE");
var headerLines = !string.IsNullOrEmpty(content.HeaderMessage) ? content.HeaderMessage.Replace("\\n", "\n").Split('\n') : Array.Empty<string>();
var headerLines =
!string.IsNullOrEmpty(content.HeaderMessage)
? externalFluentBundle.GetString(content.HeaderMessage)
: null;
var headerHeight = 0;
foreach (var l in headerLines)
if (headerLines != null)
{
var line = (LabelWidget)headerTemplate.Clone();
line.GetText = () => l;
line.Bounds.Y += headerHeight;
panel.AddChild(line);
var label = (LabelWidget)headerTemplate.Clone();
label.GetText = () => headerLines;
label.IncreaseHeightToFitCurrentText();
panel.AddChild(label);
headerHeight += headerTemplate.Bounds.Height;
headerHeight += label.Bounds.Height;
}
panel.Bounds.Height += headerHeight;
@@ -85,7 +93,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
sourceButton.OnClick = () => Ui.OpenWindow("SOURCE_INSTALL_PANEL", new WidgetArgs
{
{ "sources", sources },
{ "content", content }
{ "content", content },
{ "externalFluentBundle", externalFluentBundle },
});
var backButton = panel.Get<ButtonWidget>("BACK_BUTTON");
@@ -109,7 +118,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
var container = template.Clone();
var titleWidget = container.Get<LabelWidget>("TITLE");
var title = p.Value.Title;
var title = externalFluentBundle.GetString(p.Value.Title);
titleWidget.GetText = () => title;
var requiredWidget = container.Get<LabelWidget>("REQUIRED");