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

(cherry picked from commit 4c7201741276eccaea2fb1f33daecc31e8b2d54e)

Close #9112
pull/9123/head
Stevie Robinson 2 years ago committed by Bogdan
parent 14b9dd77af
commit 093bb94e42

@ -248,6 +248,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>

@ -531,6 +531,7 @@
"InteractiveSearchResultsFailedErrorMessage": "Search failed because its {message}. Try refreshing the movie info and verify the necessary information is present before searching again.", "InteractiveSearchResultsFailedErrorMessage": "Search failed because its {message}. Try refreshing the movie info and verify the necessary information is present before searching again.",
"Interval": "Interval", "Interval": "Interval",
"InvalidFormat": "Invalid Format", "InvalidFormat": "Invalid Format",
"InvalidUILanguage": "Your UI is set to an invalid language, correct it and save your settings",
"KeepAndUnmonitorMovie": "Keep and Unmonitor Movie", "KeepAndUnmonitorMovie": "Keep and Unmonitor Movie",
"KeyboardShortcuts": "Keyboard Shortcuts", "KeyboardShortcuts": "Keyboard Shortcuts",
"Language": "Language", "Language": "Language",

@ -87,7 +87,7 @@ namespace NzbDrone.Core.Localization
public string GetLanguageIdentifier() 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; var language = isoLanguage.TwoLetterCode;
if (isoLanguage.CountryCode.IsNotNullOrWhiteSpace()) if (isoLanguage.CountryCode.IsNotNullOrWhiteSpace())

@ -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.Languages;
using Radarr.Http; using Radarr.Http;
using Radarr.Http.REST.Attributes; using Radarr.Http.REST.Attributes;
@ -16,6 +18,18 @@ namespace Radarr.Api.V3.Config
: base(configService) : base(configService)
{ {
_configFileProvider = configFileProvider; _configFileProvider = configFileProvider;
SharedValidator.RuleFor(c => c.UILanguage).Custom((value, context) =>
{
if (!Language.All.Any(o => o.Id == value))
{
context.AddFailure("Invalid UI Language ID");
}
});
SharedValidator.RuleFor(c => c.UILanguage)
.GreaterThanOrEqualTo(1)
.WithMessage("The UI Language value cannot be less than 1");
} }
[RestPutById] [RestPutById]

Loading…
Cancel
Save