Add support for game translation
This commit is contained in:
@@ -96,6 +96,9 @@ namespace OpenRA.GameRules
|
||||
public int BatchSize = 8192;
|
||||
public int NumTempBuffers = 8;
|
||||
public int SheetSize = 2048;
|
||||
|
||||
public string Language = "english";
|
||||
public string DefaultLanguage = "english";
|
||||
}
|
||||
|
||||
public class SoundSettings
|
||||
|
||||
@@ -99,6 +99,7 @@ namespace OpenRA
|
||||
[FieldLoader.Ignore] public List<MiniYamlNode> Weapons = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore] public List<MiniYamlNode> Voices = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore] public List<MiniYamlNode> Notifications = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore] public List<MiniYamlNode> Translations = new List<MiniYamlNode>();
|
||||
|
||||
// Binary map data
|
||||
[FieldLoader.Ignore] public byte TileFormat = 1;
|
||||
@@ -191,6 +192,7 @@ namespace OpenRA
|
||||
Weapons = MiniYaml.NodesOrEmpty(yaml, "Weapons");
|
||||
Voices = MiniYaml.NodesOrEmpty(yaml, "Voices");
|
||||
Notifications = MiniYaml.NodesOrEmpty(yaml, "Notifications");
|
||||
Translations = MiniYaml.NodesOrEmpty(yaml, "Translations");
|
||||
|
||||
CustomTerrain = new string[MapSize.X, MapSize.Y];
|
||||
|
||||
@@ -247,6 +249,7 @@ namespace OpenRA
|
||||
root.Add(new MiniYamlNode("Weapons", null, Weapons));
|
||||
root.Add(new MiniYamlNode("Voices", null, Voices));
|
||||
root.Add(new MiniYamlNode("Notifications", null, Notifications));
|
||||
root.Add(new MiniYamlNode("Translations", null, Translations));
|
||||
|
||||
var entries = new Dictionary<string, byte[]>();
|
||||
entries.Add("map.bin", SaveBinaryData());
|
||||
|
||||
@@ -44,6 +44,7 @@ namespace OpenRA
|
||||
|
||||
public ModData(params string[] mods)
|
||||
{
|
||||
Languages = new string[0];
|
||||
Manifest = new Manifest(mods);
|
||||
ObjectCreator = new ObjectCreator(Manifest);
|
||||
LoadScreen = ObjectCreator.CreateObject<ILoadScreen>(Manifest.LoadScreen.Value);
|
||||
@@ -71,6 +72,47 @@ namespace OpenRA
|
||||
CursorProvider.Initialize(Manifest.Cursors);
|
||||
}
|
||||
|
||||
public IEnumerable<string> Languages { get; private set; }
|
||||
|
||||
void LoadTranslations(Map map)
|
||||
{
|
||||
var selectedTranslations = new Dictionary<string, string>();
|
||||
var defaultTranslations = new Dictionary<string, string>();
|
||||
|
||||
if (!Manifest.Translations.Any())
|
||||
{
|
||||
Languages = new string[0];
|
||||
FieldLoader.Translations = new Dictionary<string, string>();
|
||||
return;
|
||||
}
|
||||
|
||||
var yaml = Manifest.Translations.Select(MiniYaml.FromFile).Aggregate(MiniYaml.MergeLiberal);
|
||||
Languages = yaml.Select(t => t.Key).ToArray();
|
||||
|
||||
yaml = MiniYaml.MergeLiberal(map.Translations, yaml);
|
||||
|
||||
foreach (var y in yaml)
|
||||
{
|
||||
if (y.Key == Game.Settings.Graphics.Language)
|
||||
selectedTranslations = y.Value.NodesDict.ToDictionary(x => x.Key, x => x.Value.Value ?? "");
|
||||
if (y.Key == Game.Settings.Graphics.DefaultLanguage)
|
||||
defaultTranslations = y.Value.NodesDict.ToDictionary(x => x.Key, x => x.Value.Value ?? "");
|
||||
}
|
||||
|
||||
var translations = new Dictionary<string, string>();
|
||||
foreach (var tkv in defaultTranslations.Concat(selectedTranslations))
|
||||
{
|
||||
if (translations.ContainsKey(tkv.Key))
|
||||
continue;
|
||||
if (selectedTranslations.ContainsKey(tkv.Key))
|
||||
translations.Add(tkv.Key, selectedTranslations[tkv.Key]);
|
||||
else
|
||||
translations.Add(tkv.Key, tkv.Value);
|
||||
}
|
||||
|
||||
FieldLoader.Translations = translations;
|
||||
}
|
||||
|
||||
public Map PrepareMap(string uid)
|
||||
{
|
||||
LoadScreen.Display();
|
||||
@@ -78,6 +120,8 @@ namespace OpenRA
|
||||
throw new InvalidDataException("Invalid map uid: {0}".F(uid));
|
||||
var map = new Map(AvailableMaps[uid].Path);
|
||||
|
||||
LoadTranslations(map);
|
||||
|
||||
// Reinit all our assets
|
||||
InitializeLoaders();
|
||||
FileSystem.LoadFromManifest(Manifest);
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace OpenRA.Widgets
|
||||
set { GetKey = _ => value; }
|
||||
}
|
||||
|
||||
public string Text = "";
|
||||
[Translate] public string Text = "";
|
||||
public bool Depressed = false;
|
||||
public int VisualHeight = ChromeMetrics.Get<int>("ButtonDepth");
|
||||
public string Font = ChromeMetrics.Get<string>("ButtonFont");
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
@@ -19,7 +20,7 @@ namespace OpenRA.Widgets
|
||||
|
||||
public class LabelWidget : Widget
|
||||
{
|
||||
public string Text = null;
|
||||
[Translate] public string Text = null;
|
||||
public TextAlign Align = TextAlign.Left;
|
||||
public TextVAlign VAlign = TextVAlign.Middle;
|
||||
public string Font = "Regular";
|
||||
|
||||
Reference in New Issue
Block a user