Cleanup of GetLocalised and router
This commit is contained in:
@@ -50,16 +50,18 @@ namespace Core.Routers
|
||||
var pmcData = _profileHelper.GetPmcProfile(sessionID);
|
||||
|
||||
var eventRouter = _itemEventRouters.FirstOrDefault((r) => r.CanHandle(body.Action));
|
||||
if (eventRouter is not null)
|
||||
if (eventRouter is null)
|
||||
{
|
||||
_logger.Debug("event: ${ body.Action}");
|
||||
await eventRouter.HandleItemEvent(body.Action, pmcData, body, sessionID, output);
|
||||
if (output.Warnings.Count > 0) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
_logger.Error(_localisationService.GetText("event-unhandled_event", body.Action));
|
||||
_logger.WriteToLogFile(body);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
_logger.Debug("event: ${ body.Action}");
|
||||
await eventRouter.HandleItemEvent(body.Action, pmcData, body, sessionID, output);
|
||||
if (output.Warnings.Count > 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -169,9 +169,9 @@ public class SptHttpListener : IHttpListener
|
||||
var output = _router.GetResponse(req, sessionID, body, out var deserializedObject);
|
||||
/* route doesn't exist or response is not properly set up */
|
||||
if (string.IsNullOrEmpty(output)) {
|
||||
_logger.Error(_localisationService.GetText("unhandled_response", req.Path));
|
||||
_logger.Error(_localisationService.GetText("unhandled_response", req.Path.ToString()));
|
||||
_logger.Info(_jsonUtil.Serialize(deserializedObject));
|
||||
output = _httpResponseUtil.GetBody<object?>(null, 404, $"UNHANDLED RESPONSE: {req.Path}");
|
||||
output = _httpResponseUtil.GetBody<object?>(null, 404, $"UNHANDLED RESPONSE: {req.Path.ToString()}");
|
||||
}
|
||||
/* TODO: REQUEST LOGGER
|
||||
if (ProgramStatics.ENTRY_TYPE !== EntryType.RELEASE) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Core.Utils;
|
||||
using Core.Utils;
|
||||
using Core.Utils.Extensions;
|
||||
|
||||
namespace Core.Services;
|
||||
@@ -84,26 +84,33 @@ public class I18nService
|
||||
return value;
|
||||
}
|
||||
|
||||
public string GetLocalised<T>(string key)
|
||||
{
|
||||
return GetLocalised(key);
|
||||
}
|
||||
|
||||
public string GetLocalised(string key, object? args)
|
||||
{
|
||||
var rawLocalizedString = GetLocalised(key);
|
||||
if (args == null)
|
||||
{
|
||||
return rawLocalizedString;
|
||||
if (args is string value)
|
||||
{
|
||||
return rawLocalizedString.Replace("%s", value);
|
||||
}
|
||||
else
|
||||
|
||||
foreach (var propertyInfo in args.GetType().GetProperties())
|
||||
{
|
||||
foreach (var propertyInfo in args.GetType().GetProperties())
|
||||
var localizedName = $"{{{{{propertyInfo.GetJsonName()}}}}}";
|
||||
if (rawLocalizedString.Contains(localizedName))
|
||||
{
|
||||
var localizedName = $"{{{{{propertyInfo.GetJsonName()}}}}}";
|
||||
if (rawLocalizedString.Contains(localizedName))
|
||||
{
|
||||
rawLocalizedString.Replace(localizedName, propertyInfo.GetValue(args, null)?.ToString() ?? string.Empty);
|
||||
}
|
||||
rawLocalizedString.Replace(localizedName, propertyInfo.GetValue(args, null)?.ToString() ?? string.Empty);
|
||||
}
|
||||
return rawLocalizedString;
|
||||
}
|
||||
return rawLocalizedString;
|
||||
}
|
||||
|
||||
public string GetLocalised<T>(string key, T value) where T : IConvertible
|
||||
{
|
||||
var rawLocalizedString = GetLocalised(key);
|
||||
return rawLocalizedString.Replace("%s", value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Core.Utils;
|
||||
using Core.Utils;
|
||||
using Core.Annotations;
|
||||
using Core.Models.Utils;
|
||||
using Core.Servers;
|
||||
@@ -40,7 +40,14 @@ public class LocalisationService
|
||||
|
||||
public string GetText(string key, object? args = null)
|
||||
{
|
||||
return _i18nService.GetLocalised(key, args);
|
||||
return args is null
|
||||
? _i18nService.GetLocalised(key)
|
||||
: _i18nService.GetLocalised(key, args);
|
||||
}
|
||||
|
||||
public string GetText<T>(string key, T value) where T :IConvertible
|
||||
{
|
||||
return _i18nService.GetLocalised(key, value);
|
||||
}
|
||||
|
||||
public ICollection<string> GetKeys()
|
||||
|
||||
Reference in New Issue
Block a user