Add translation arguments to the Lua API.
This commit is contained in:
committed by
Gustas
parent
5d118e2634
commit
b62cf7ee9a
@@ -9,6 +9,8 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Eluant;
|
||||||
using OpenRA.Mods.Common.Widgets;
|
using OpenRA.Mods.Common.Widgets;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
using OpenRA.Scripting;
|
using OpenRA.Scripting;
|
||||||
@@ -32,8 +34,26 @@ namespace OpenRA.Mods.Common.Scripting.Global
|
|||||||
luaLabel.GetColor = () => c;
|
luaLabel.GetColor = () => c;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Translate(string text)
|
public string Translate(string text, LuaTable table = null)
|
||||||
{
|
{
|
||||||
|
if (table != null)
|
||||||
|
{
|
||||||
|
var argumentDictionary = new Dictionary<string, object>();
|
||||||
|
foreach (var kv in table)
|
||||||
|
{
|
||||||
|
using (kv.Key)
|
||||||
|
using (kv.Value)
|
||||||
|
{
|
||||||
|
if (!kv.Key.TryGetClrValue(out string variable) || !kv.Value.TryGetClrValue(out object value))
|
||||||
|
throw new LuaException($"Translation arguments requires a table of [\"string\"]=value pairs. Received {kv.Key.WrappedClrType().Name},{kv.Value.WrappedClrType().Name}");
|
||||||
|
|
||||||
|
argumentDictionary.Add(variable, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Context.World.Map.Translate(text, argumentDictionary);
|
||||||
|
}
|
||||||
|
|
||||||
return Context.World.Map.Translate(text);
|
return Context.World.Map.Translate(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user