Validate UI Language and fallback to English translations if invalid in config
This commit is contained in:
parent
5a7f42a63e
commit
caee398a95
|
@ -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') }
|
||||
]}
|
||||
/>
|
||||
</FormGroup>
|
||||
</FieldSet>
|
||||
|
|
|
@ -612,6 +612,7 @@
|
|||
"InteractiveSearchResultsFailedErrorMessage": "Search failed because its {message}. Try refreshing the series info and verify the necessary information is present before searching again.",
|
||||
"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",
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in New Issue