Fixed: Fallback to English translations if invalid UI language in config

(cherry picked from commit 4c7201741276eccaea2fb1f33daecc31e8b2d54e)
pull/1934/head
Stevie Robinson 10 months ago committed by Bogdan
parent fab4bd5ead
commit fc482d4808

@ -176,6 +176,13 @@ class UISettings extends Component {
helpTextWarning={translate('UILanguageHelpTextWarning')} helpTextWarning={translate('UILanguageHelpTextWarning')}
onChange={onInputChange} onChange={onInputChange}
{...settings.uiLanguage} {...settings.uiLanguage}
errors={
languages.some((language) => language.key === settings.uiLanguage.value) ?
settings.uiLanguage.errors :
[
...settings.uiLanguage.errors,
{ message: translate('InvalidUILanguage') }
]}
/> />
</FormGroup> </FormGroup>
</FieldSet> </FieldSet>

@ -294,6 +294,7 @@
"InstanceNameHelpText": "Instance name in tab and for Syslog app name", "InstanceNameHelpText": "Instance name in tab and for Syslog app name",
"InteractiveSearch": "Interactive Search", "InteractiveSearch": "Interactive Search",
"Interval": "Interval", "Interval": "Interval",
"InvalidUILanguage": "Your UI is set to an invalid language, correct it and save your settings",
"KeyboardShortcuts": "Keyboard Shortcuts", "KeyboardShortcuts": "Keyboard Shortcuts",
"Label": "Label", "Label": "Label",
"Language": "Language", "Language": "Language",

@ -1,7 +1,9 @@
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using FluentValidation;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Localization;
using NzbDrone.Http.REST.Attributes; using NzbDrone.Http.REST.Attributes;
using Prowlarr.Http; using Prowlarr.Http;
@ -12,10 +14,22 @@ namespace Prowlarr.Api.V1.Config
{ {
private readonly IConfigFileProvider _configFileProvider; private readonly IConfigFileProvider _configFileProvider;
public UiConfigController(IConfigFileProvider configFileProvider, IConfigService configService) public UiConfigController(IConfigFileProvider configFileProvider, IConfigService configService, ILocalizationService localizationService)
: base(configService) : base(configService)
{ {
_configFileProvider = configFileProvider; _configFileProvider = configFileProvider;
SharedValidator.RuleFor(c => c.UILanguage)
.NotEmpty()
.WithMessage("The UI Language value cannot be empty");
SharedValidator.RuleFor(c => c.UILanguage).Custom((value, context) =>
{
if (!localizationService.GetLocalizationOptions().Any(o => o.Value == value))
{
context.AddFailure("Invalid UI Language value");
}
});
} }
[RestPutById] [RestPutById]

Loading…
Cancel
Save