Skip to content

Commit

Permalink
Fixed: Fallback to English translations if invalid UI language in config
Browse files Browse the repository at this point in the history
  • Loading branch information
stevietv authored Sep 1, 2023
1 parent c123596 commit 4c72017
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
7 changes: 7 additions & 0 deletions frontend/src/Settings/UI/UISettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions src/NzbDrone.Core/Localization/Core/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/NzbDrone.Core/Localization/LocalizationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public string GetLocalizedString(string phrase, string language)

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())
Expand Down
13 changes: 13 additions & 0 deletions src/Sonarr.Api.V3/Config/UiConfigController.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -16,6 +18,17 @@ public UiConfigController(IConfigFileProvider configFileProvider, IConfigService
: 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]
Expand Down

0 comments on commit 4c72017

Please sign in to comment.