Fix parsing of Language when using default system locale

This commit is contained in:
Susko3
2022-11-10 22:56:24 +01:00
parent 86862b1f29
commit 5b1e39abd5
3 changed files with 38 additions and 15 deletions

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
#nullable disable
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Configuration;
@ -16,15 +14,17 @@ namespace osu.Game.Overlays.Settings.Sections.General
{
public class LanguageSettings : SettingsSubsection
{
private SettingsDropdown<Language> languageSelection;
private Bindable<string> frameworkLocale;
private SettingsDropdown<Language> languageSelection = null!;
private Bindable<string> frameworkLocale = null!;
private IBindable<LocalisationParameters> localisationParameters = null!;
protected override LocalisableString Header => GeneralSettingsStrings.LanguageHeader;
[BackgroundDependencyLoader]
private void load(FrameworkConfigManager frameworkConfig, OsuConfigManager config)
private void load(FrameworkConfigManager frameworkConfig, OsuConfigManager config, LocalisationManager localisation)
{
frameworkLocale = frameworkConfig.GetBindable<string>(FrameworkSetting.Locale);
localisationParameters = localisation.CurrentParameters.GetBoundCopy();
Children = new Drawable[]
{
@ -44,12 +44,8 @@ namespace osu.Game.Overlays.Settings.Sections.General
},
};
frameworkLocale.BindValueChanged(locale =>
{
if (!LanguageExtensions.TryParseCultureCode(locale.NewValue, out var language))
language = Language.en;
languageSelection.Current.Value = language;
}, true);
localisationParameters.BindValueChanged(p
=> languageSelection.Current.Value = LanguageExtensions.GetLanguageFor(frameworkLocale.Value, p.NewValue), true);
languageSelection.Current.BindValueChanged(val => frameworkLocale.Value = val.NewValue.ToCultureCode());
}