Don't crash Lua when the translation attempt fails.

This commit is contained in:
Matthias Mailänder
2022-09-02 17:23:55 +02:00
committed by Gustas
parent 0c47a0a710
commit 807e9b5496

View File

@@ -88,19 +88,19 @@ namespace OpenRA
public bool TryGetString(string key, out string value, IDictionary<string, object> arguments = null) public bool TryGetString(string key, out string value, IDictionary<string, object> arguments = null)
{ {
if (!HasMessage(key))
{
value = null;
return false;
}
var fluentArguments = new Dictionary<string, IFluentType>();
if (arguments != null)
foreach (var (k, v) in arguments)
fluentArguments.Add(k, v.ToFluentType());
try try
{ {
if (!HasMessage(key))
{
value = null;
return false;
}
var fluentArguments = new Dictionary<string, IFluentType>();
if (arguments != null)
foreach (var (k, v) in arguments)
fluentArguments.Add(k, v.ToFluentType());
var result = bundle.TryGetAttrMsg(key, fluentArguments, out var errors, out value); var result = bundle.TryGetAttrMsg(key, fluentArguments, out var errors, out value);
foreach (var error in errors) foreach (var error in errors)
Log.Write("debug", $"Translation of {key}: {error}"); Log.Write("debug", $"Translation of {key}: {error}");
@@ -109,7 +109,8 @@ namespace OpenRA
} }
catch (Exception e) catch (Exception e)
{ {
Log.Write("debug", $"Translation of {key}: {e}"); Log.Write("debug", $"Translation of {key} failed:");
Log.Write("debug", e);
value = null; value = null;
return false; return false;
} }