From 4c7201741276eccaea2fb1f33daecc31e8b2d54e 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 --- frontend/src/Settings/UI/UISettings.js | 7 +++++++ src/NzbDrone.Core/Localization/Core/en.json | 1 + .../Localization/LocalizationService.cs | 2 +- src/Sonarr.Api.V3/Config/UiConfigController.cs | 13 +++++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/frontend/src/Settings/UI/UISettings.js b/frontend/src/Settings/UI/UISettings.js index a9365c49a..beccce918 100644 --- a/frontend/src/Settings/UI/UISettings.js +++ b/frontend/src/Settings/UI/UISettings.js @@ -220,6 +220,13 @@ class UISettings extends Component { helpTextWarning={translate('BrowserReloadRequired')} 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 02f959b80..59522ac37 100644 --- a/src/NzbDrone.Core/Localization/Core/en.json +++ b/src/NzbDrone.Core/Localization/Core/en.json @@ -656,6 +656,7 @@ "InteractiveSearchSeason": "Interactive search for all episodes in this season", "Interval": "Interval", "InvalidFormat": "Invalid Format", + "InvalidUILanguage": "Your UI is set to an invalid language, correct it and save your settings", "KeyboardShortcuts": "Keyboard Shortcuts", "KeyboardShortcutsCloseModal": "Close Current Modal", "KeyboardShortcutsConfirmModal": "Accept Confirmation Modal", diff --git a/src/NzbDrone.Core/Localization/LocalizationService.cs b/src/NzbDrone.Core/Localization/LocalizationService.cs index 8633ea45c..d0c5c8eb7 100644 --- a/src/NzbDrone.Core/Localization/LocalizationService.cs +++ b/src/NzbDrone.Core/Localization/LocalizationService.cs @@ -87,7 +87,7 @@ namespace NzbDrone.Core.Localization public string GetLanguageIdentifier() { - 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/Sonarr.Api.V3/Config/UiConfigController.cs b/src/Sonarr.Api.V3/Config/UiConfigController.cs index 640637a58..8aa83588a 100644 --- a/src/Sonarr.Api.V3/Config/UiConfigController.cs +++ b/src/Sonarr.Api.V3/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 Sonarr.Http; using Sonarr.Http.REST.Attributes; @@ -16,6 +18,17 @@ namespace Sonarr.Api.V3.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]