mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-18 21:35:51 -04:00
Translate fields on the backend
(cherry picked from commit 48b12f5b00429a7cd218d23f0544641b0da62a06)
This commit is contained in:
@@ -3,11 +3,13 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using DryIoc;
|
||||
using NzbDrone.Common.EnsureThat;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Reflection;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.Localization;
|
||||
|
||||
namespace Radarr.Http.ClientSchema
|
||||
{
|
||||
@@ -15,6 +17,12 @@ namespace Radarr.Http.ClientSchema
|
||||
{
|
||||
private const string PRIVATE_VALUE = "********";
|
||||
private static Dictionary<Type, FieldMapping[]> _mappings = new Dictionary<Type, FieldMapping[]>();
|
||||
private static ILocalizationService _localizationService;
|
||||
|
||||
public static void Initialize(IContainer container)
|
||||
{
|
||||
_localizationService = container.Resolve<ILocalizationService>();
|
||||
}
|
||||
|
||||
public static List<Field> ToSchema(object model)
|
||||
{
|
||||
@@ -107,13 +115,27 @@ namespace Radarr.Http.ClientSchema
|
||||
if (propertyInfo.PropertyType.IsSimpleType())
|
||||
{
|
||||
var fieldAttribute = property.Item2;
|
||||
|
||||
var label = fieldAttribute.Label.IsNotNullOrWhiteSpace()
|
||||
? _localizationService.GetLocalizedString(fieldAttribute.Label,
|
||||
GetTokens(type, fieldAttribute.Label, TokenField.Label))
|
||||
: fieldAttribute.Label;
|
||||
var helpText = fieldAttribute.HelpText.IsNotNullOrWhiteSpace()
|
||||
? _localizationService.GetLocalizedString(fieldAttribute.HelpText,
|
||||
GetTokens(type, fieldAttribute.Label, TokenField.HelpText))
|
||||
: fieldAttribute.HelpText;
|
||||
var helpTextWarning = fieldAttribute.HelpTextWarning.IsNotNullOrWhiteSpace()
|
||||
? _localizationService.GetLocalizedString(fieldAttribute.HelpTextWarning,
|
||||
GetTokens(type, fieldAttribute.Label, TokenField.HelpTextWarning))
|
||||
: fieldAttribute.HelpTextWarning;
|
||||
|
||||
var field = new Field
|
||||
{
|
||||
Name = prefix + GetCamelCaseName(propertyInfo.Name),
|
||||
Label = fieldAttribute.Label,
|
||||
Label = label,
|
||||
Unit = fieldAttribute.Unit,
|
||||
HelpText = fieldAttribute.HelpText,
|
||||
HelpTextWarning = fieldAttribute.HelpTextWarning,
|
||||
HelpText = helpText,
|
||||
HelpTextWarning = helpTextWarning,
|
||||
HelpLink = fieldAttribute.HelpLink,
|
||||
Order = fieldAttribute.Order,
|
||||
Advanced = fieldAttribute.Advanced,
|
||||
@@ -173,6 +195,24 @@ namespace Radarr.Http.ClientSchema
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private static Dictionary<string, object> GetTokens(Type type, string label, TokenField field)
|
||||
{
|
||||
var tokens = new Dictionary<string, object>();
|
||||
|
||||
foreach (var propertyInfo in type.GetProperties())
|
||||
{
|
||||
foreach (var attribute in propertyInfo.GetCustomAttributes(true))
|
||||
{
|
||||
if (attribute is FieldTokenAttribute fieldTokenAttribute && fieldTokenAttribute.Field == field && fieldTokenAttribute.Label == label)
|
||||
{
|
||||
tokens.Add(fieldTokenAttribute.Token, fieldTokenAttribute.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tokens;
|
||||
}
|
||||
|
||||
private static List<SelectOption> GetSelectOptions(Type selectOptions)
|
||||
{
|
||||
if (selectOptions.IsEnum)
|
||||
|
||||
Reference in New Issue
Block a user