From fc482d4808ddca4a9db7cb9099c263b34d351075 Mon Sep 17 00:00:00 2001 From: Stevie Robinson Date: Fri, 1 Sep 2023 02:47:38 +0200 Subject: [PATCH] Fixed: Fallback to English translations if invalid UI language in config (cherry picked from commit 4c7201741276eccaea2fb1f33daecc31e8b2d54e) --- frontend/src/Settings/UI/UISettings.js | 7 +++++++ src/NzbDrone.Core/Localization/Core/en.json | 1 + src/Prowlarr.Api.V1/Config/UiConfigController.cs | 16 +++++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/frontend/src/Settings/UI/UISettings.js b/frontend/src/Settings/UI/UISettings.js index cfb7c04f6..caa013db3 100644 --- a/frontend/src/Settings/UI/UISettings.js +++ b/frontend/src/Settings/UI/UISettings.js @@ -176,6 +176,13 @@ class UISettings extends Component { helpTextWarning={translate('UILanguageHelpTextWarning')} onChange={onInputChange} {...settings.uiLanguage} + errors={ + languages.some((language) => language.key === settings.uiLanguage.value) ? + settings.uiLanguage.errors : + [ + ...settings.uiLanguage.errors, + { message: translate('InvalidUILanguage') } + ]} /> diff --git a/src/NzbDrone.Core/Localization/Core/en.json b/src/NzbDrone.Core/Localization/Core/en.json index 2c2bcd6fa..2b4176417 100644 --- a/src/NzbDrone.Core/Localization/Core/en.json +++ b/src/NzbDrone.Core/Localization/Core/en.json @@ -294,6 +294,7 @@ "InstanceNameHelpText": "Instance name in tab and for Syslog app name", "InteractiveSearch": "Interactive Search", "Interval": "Interval", + "InvalidUILanguage": "Your UI is set to an invalid language, correct it and save your settings", "KeyboardShortcuts": "Keyboard Shortcuts", "Label": "Label", "Language": "Language", diff --git a/src/Prowlarr.Api.V1/Config/UiConfigController.cs b/src/Prowlarr.Api.V1/Config/UiConfigController.cs index e6ddb073a..a22852863 100644 --- a/src/Prowlarr.Api.V1/Config/UiConfigController.cs +++ b/src/Prowlarr.Api.V1/Config/UiConfigController.cs @@ -1,7 +1,9 @@ using System.Linq; using System.Reflection; +using FluentValidation; using Microsoft.AspNetCore.Mvc; using NzbDrone.Core.Configuration; +using NzbDrone.Core.Localization; using NzbDrone.Http.REST.Attributes; using Prowlarr.Http; @@ -12,10 +14,22 @@ namespace Prowlarr.Api.V1.Config { private readonly IConfigFileProvider _configFileProvider; - public UiConfigController(IConfigFileProvider configFileProvider, IConfigService configService) + public UiConfigController(IConfigFileProvider configFileProvider, IConfigService configService, ILocalizationService localizationService) : base(configService) { _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]