diff --git a/frontend/src/Settings/UI/UISettings.js b/frontend/src/Settings/UI/UISettings.js index f6219406f..902b922f9 100644 --- a/frontend/src/Settings/UI/UISettings.js +++ b/frontend/src/Settings/UI/UISettings.js @@ -268,6 +268,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/Lidarr.Api.V1/Config/UiConfigController.cs b/src/Lidarr.Api.V1/Config/UiConfigController.cs index 9aa47004b..8a28843be 100644 --- a/src/Lidarr.Api.V1/Config/UiConfigController.cs +++ b/src/Lidarr.Api.V1/Config/UiConfigController.cs @@ -1,9 +1,11 @@ using System.Linq; using System.Reflection; +using FluentValidation; using Lidarr.Http; using Lidarr.Http.REST.Attributes; using Microsoft.AspNetCore.Mvc; using NzbDrone.Core.Configuration; +using NzbDrone.Core.Languages; namespace Lidarr.Api.V1.Config { @@ -16,6 +18,17 @@ namespace Lidarr.Api.V1.Config : base(configService) { _configFileProvider = configFileProvider; + SharedValidator.RuleFor(c => c.UILanguage).Custom((value, context) => + { + if (!Language.All.Any(o => o.Id == value)) + { + context.AddFailure("Invalid UI Language value"); + } + }); + + SharedValidator.RuleFor(c => c.UILanguage) + .GreaterThanOrEqualTo(1) + .WithMessage("The UI Language value cannot be less than 1"); } [RestPutById] diff --git a/src/NzbDrone.Core/Localization/Core/en.json b/src/NzbDrone.Core/Localization/Core/en.json index 05f4a994b..40125a77e 100644 --- a/src/NzbDrone.Core/Localization/Core/en.json +++ b/src/NzbDrone.Core/Localization/Core/en.json @@ -480,6 +480,7 @@ "InteractiveImport": "Interactive Import", "InteractiveSearch": "Interactive Search", "Interval": "Interval", + "InvalidUILanguage": "Your UI is set to an invalid language, correct it and save your settings", "IsCutoffCutoff": "Cutoff", "IsCutoffUpgradeUntilThisQualityIsMetOrExceeded": "Upgrade until this quality is met or exceeded", "IsExpandedHideAlbums": "Hide albums", diff --git a/src/NzbDrone.Core/Localization/LocalizationService.cs b/src/NzbDrone.Core/Localization/LocalizationService.cs index 38a2c0a69..115ca3f52 100644 --- a/src/NzbDrone.Core/Localization/LocalizationService.cs +++ b/src/NzbDrone.Core/Localization/LocalizationService.cs @@ -86,7 +86,7 @@ namespace NzbDrone.Core.Localization private string GetSetLanguageFileName() { - var isoLanguage = IsoLanguages.Get((Language)_configService.UILanguage); + var isoLanguage = IsoLanguages.Get((Language)_configService.UILanguage) ?? IsoLanguages.Get(Language.English); var language = isoLanguage.TwoLetterCode; if (isoLanguage.CountryCode.IsNotNullOrWhiteSpace())