Add a Fluent based translation system.

This commit is contained in:
Matthias Mailänder
2021-04-24 12:39:06 +02:00
committed by teinarss
parent f1a9a5180d
commit 1f01d0b6b1
8 changed files with 169 additions and 1 deletions

View File

@@ -21,6 +21,7 @@ using OpenRA.Graphics;
using OpenRA.Primitives;
using OpenRA.Support;
using OpenRA.Traits;
using OpenRA.Widgets;
namespace OpenRA
{
@@ -164,6 +165,7 @@ namespace OpenRA
new MapField("Bounds"),
new MapField("Visibility"),
new MapField("Categories"),
new MapField("Translations", required: false),
new MapField("LockPreview", required: false, ignoreIfValue: "False"),
new MapField("Players", "PlayerDefinitions"),
new MapField("Actors", "ActorDefinitions"),
@@ -189,6 +191,7 @@ namespace OpenRA
public Rectangle Bounds;
public MapVisibility Visibility = MapVisibility.Lobby;
public string[] Categories = { "Conquest" };
public string[] Translations;
public int2 MapSize { get; private set; }
@@ -246,6 +249,8 @@ namespace OpenRA
CellLayer<List<MPos>> inverseCellProjection;
CellLayer<byte> projectedHeight;
internal Translation Translation;
public static string ComputeUID(IReadOnlyPackage package)
{
// UID is calculated by taking an SHA1 of the yaml and binary data
@@ -418,6 +423,8 @@ namespace OpenRA
Rules.Sequences.Preload();
Translation = new Translation(Game.Settings.Player.Language, Translations, this);
var tl = new MPos(0, 0).ToCPos(this);
var br = new MPos(MapSize.X - 1, MapSize.Y - 1).ToCPos(this);
AllCells = new CellRegion(Grid.Type, tl, br);
@@ -1307,5 +1314,13 @@ namespace OpenRA
return false;
}
public string Translate(string key, IDictionary<string, object> args = null, string attribute = null)
{
if (Translation.GetFormattedMessage(key, args, attribute) == key)
return Ui.Translate(key, args, attribute);
return Translation.GetFormattedMessage(key, args, attribute);
}
}
}