Remove magic ftl file naming.

This commit is contained in:
Paul Chote
2024-10-20 18:48:15 +01:00
committed by Gustas
parent 5a0c8439fc
commit c09d7cbdea
7 changed files with 54 additions and 86 deletions

View File

@@ -13,7 +13,6 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using Linguini.Bundle;
using Linguini.Bundle.Builder;
using Linguini.Shared.Types.Bundle;
@@ -53,37 +52,30 @@ namespace OpenRA
{
readonly Linguini.Bundle.FluentBundle bundle;
public FluentBundle(string language, string[] paths, IReadOnlyFileSystem fileSystem)
: this(language, paths, fileSystem, error => Log.Write("debug", error.Message)) { }
public FluentBundle(string culture, string[] paths, IReadOnlyFileSystem fileSystem)
: this(culture, paths, fileSystem, error => Log.Write("debug", error.Message)) { }
public FluentBundle(string language, string[] paths, IReadOnlyFileSystem fileSystem, string text)
: this(language, paths, fileSystem, text, error => Log.Write("debug", error.Message)) { }
public FluentBundle(string culture, string[] paths, IReadOnlyFileSystem fileSystem, string text)
: this(culture, paths, fileSystem, text, error => Log.Write("debug", error.Message)) { }
public FluentBundle(string language, string[] paths, IReadOnlyFileSystem fileSystem, Action<ParseError> onError)
: this(language, paths, fileSystem, null, onError) { }
public FluentBundle(string culture, string[] paths, IReadOnlyFileSystem fileSystem, Action<ParseError> onError)
: this(culture, paths, fileSystem, null, onError) { }
public FluentBundle(string language, string text, Action<ParseError> onError)
: this(language, null, null, text, onError) { }
public FluentBundle(string culture, string text, Action<ParseError> onError)
: this(culture, null, null, text, onError) { }
public FluentBundle(string language, string[] paths, IReadOnlyFileSystem fileSystem, string text, Action<ParseError> onError)
public FluentBundle(string culture, string[] paths, IReadOnlyFileSystem fileSystem, string text, Action<ParseError> onError)
{
bundle = LinguiniBuilder.Builder()
.CultureInfo(new CultureInfo(language))
.CultureInfo(new CultureInfo(culture))
.SkipResources()
.SetUseIsolating(false)
.UseConcurrent()
.UncheckedBuild();
if (paths != null && paths.Length > 0)
if (paths != null)
{
// 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.
var resolvedPaths = paths.Where(t => t.EndsWith("en.ftl", StringComparison.Ordinal)).ToList();
foreach (var t in paths)
if (t.EndsWith($"{language}.ftl", StringComparison.Ordinal))
resolvedPaths.Add(t);
foreach (var path in resolvedPaths.Distinct())
foreach (var path in paths)
{
var stream = fileSystem.Open(path);
using (var reader = new StreamReader(stream))

View File

@@ -26,7 +26,7 @@ namespace OpenRA
{
lock (SyncObject)
{
modFluentBundle = new FluentBundle(Game.Settings.Player.Language, modData.Manifest.Translations, fileSystem);
modFluentBundle = new FluentBundle(modData.Manifest.FluentCulture, modData.Manifest.Translations, fileSystem);
if (fileSystem is Map map && map.FluentMessageDefinitions != null)
{
var files = Array.Empty<string>();
@@ -44,7 +44,7 @@ namespace OpenRA
text = builder.ToString();
}
mapFluentBundle = new FluentBundle(Game.Settings.Player.Language, files, fileSystem, text);
mapFluentBundle = new FluentBundle(modData.Manifest.FluentCulture, files, fileSystem, text);
}
}
}

View File

@@ -83,10 +83,13 @@ namespace OpenRA
public readonly string[] SpriteFormats = Array.Empty<string>();
public readonly string[] PackageFormats = Array.Empty<string>();
public readonly string[] VideoFormats = Array.Empty<string>();
public readonly bool AllowUnusedTranslationsInExternalPackages = true;
public readonly int FontSheetSize = 512;
public readonly int CursorSheetSize = 512;
// TODO: This should be controlled by a user-selected translation bundle!
public readonly string FluentCulture = "en";
public readonly bool AllowUnusedTranslationsInExternalPackages = true;
readonly string[] reservedModuleNames =
{
"Include", "Metadata", "FileSystem", "MapFolders", "Rules",

View File

@@ -143,7 +143,7 @@ namespace OpenRA
text = builder.ToString();
}
FluentBundle = new FluentBundle(Game.Settings.Player.Language, files, fileSystem, text);
FluentBundle = new FluentBundle(modData.Manifest.FluentCulture, files, fileSystem, text);
}
else
FluentBundle = null;

View File

@@ -249,7 +249,6 @@ namespace OpenRA
public Color Color = Color.FromArgb(200, 32, 32);
public string LastServer = "localhost:1234";
public Color[] CustomColors = Array.Empty<Color>();
public string Language = "en";
}
public class GameSettings

View File

@@ -26,9 +26,6 @@ namespace OpenRA
if (Game.EngineVersion != null)
Log.Write("exception", $"OpenRA engine version {Game.EngineVersion}");
if (Game.Settings != null && Game.Settings.Player != null && Game.Settings.Player.Language != null)
Log.Write("exception", $"OpenRA Language: {Game.Settings.Player.Language}");
if (Game.ModData != null)
{
var manifest = Game.ModData.Manifest;