diff --git a/frontend/src/Settings/UI/UISettings.js b/frontend/src/Settings/UI/UISettings.js index d35c638ec..667cb44e1 100644 --- a/frontend/src/Settings/UI/UISettings.js +++ b/frontend/src/Settings/UI/UISettings.js @@ -223,6 +223,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 cede39010..c9ebdd562 100644 --- a/src/NzbDrone.Core/Localization/Core/en.json +++ b/src/NzbDrone.Core/Localization/Core/en.json @@ -432,6 +432,7 @@ "InstanceName": "Instance Name", "InstanceNameHelpText": "Instance name in tab and for Syslog app name", "Interval": "Interval", + "InvalidUILanguage": "Your UI is set to an invalid language, correct it and save your settings", "IsCalibreLibraryHelpText": "Use Calibre Content Server to manipulate library", "IsCutoffCutoff": "Cutoff", "IsCutoffUpgradeUntilThisQualityIsMetOrExceeded": "Upgrade until this quality is met or exceeded", diff --git a/src/NzbDrone.Core/Localization/LocalizationService.cs b/src/NzbDrone.Core/Localization/LocalizationService.cs index b62e9c661..f827d112c 100644 --- a/src/NzbDrone.Core/Localization/LocalizationService.cs +++ b/src/NzbDrone.Core/Localization/LocalizationService.cs @@ -99,7 +99,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()) diff --git a/src/Readarr.Api.V1/Config/UiConfigController.cs b/src/Readarr.Api.V1/Config/UiConfigController.cs index e427bfd59..501143ead 100644 --- a/src/Readarr.Api.V1/Config/UiConfigController.cs +++ b/src/Readarr.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.Languages; using NzbDrone.Http.REST.Attributes; using Readarr.Http; @@ -16,6 +18,17 @@ namespace Readarr.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]