mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 00:40:09 +09:00
Fix parsing of Language
when using default system locale
This commit is contained in:
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using osu.Framework.Configuration;
|
||||||
|
using osu.Framework.Localisation;
|
||||||
using osu.Game.Localisation;
|
using osu.Game.Localisation;
|
||||||
|
|
||||||
namespace osu.Game.Extensions
|
namespace osu.Game.Extensions
|
||||||
@ -29,5 +31,28 @@ namespace osu.Game.Extensions
|
|||||||
/// <returns>Whether the parsing succeeded.</returns>
|
/// <returns>Whether the parsing succeeded.</returns>
|
||||||
public static bool TryParseCultureCode(string cultureCode, out Language language)
|
public static bool TryParseCultureCode(string cultureCode, out Language language)
|
||||||
=> Enum.TryParse(cultureCode.Replace("-", "_"), out language);
|
=> Enum.TryParse(cultureCode.Replace("-", "_"), out language);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Parses the <see cref="Language"/> that is specified in <paramref name="frameworkLocale"/>,
|
||||||
|
/// or if that is not valid, the language of the current <see cref="ResourceManagerLocalisationStore"/> as exposed by <paramref name="localisationParameters"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="frameworkLocale">The current <see cref="FrameworkSetting.Locale"/>.</param>
|
||||||
|
/// <param name="localisationParameters">The current <see cref="LocalisationParameters"/> of the <see cref="LocalisationManager"/>.</param>
|
||||||
|
/// <returns>The parsed language.</returns>
|
||||||
|
public static Language GetLanguageFor(string frameworkLocale, LocalisationParameters localisationParameters)
|
||||||
|
{
|
||||||
|
// the usual case when the user has changed the language
|
||||||
|
if (TryParseCultureCode(frameworkLocale, out var language))
|
||||||
|
return language;
|
||||||
|
|
||||||
|
if (localisationParameters.Store != null)
|
||||||
|
{
|
||||||
|
// startup case, locale not explicitly set, or the set language was removed in an update
|
||||||
|
if (TryParseCultureCode(localisationParameters.Store.EffectiveCulture.Name, out language))
|
||||||
|
return language;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Language.en;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,11 +63,12 @@ namespace osu.Game.Overlays.FirstRunSetup
|
|||||||
private class LanguageSelectionFlow : FillFlowContainer
|
private class LanguageSelectionFlow : FillFlowContainer
|
||||||
{
|
{
|
||||||
private Bindable<string> frameworkLocale = null!;
|
private Bindable<string> frameworkLocale = null!;
|
||||||
|
private IBindable<LocalisationParameters> localisationParameters = null!;
|
||||||
|
|
||||||
private ScheduledDelegate? updateSelectedDelegate;
|
private ScheduledDelegate? updateSelectedDelegate;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(FrameworkConfigManager frameworkConfig)
|
private void load(FrameworkConfigManager frameworkConfig, LocalisationManager localisation)
|
||||||
{
|
{
|
||||||
Direction = FillDirection.Full;
|
Direction = FillDirection.Full;
|
||||||
Spacing = new Vector2(5);
|
Spacing = new Vector2(5);
|
||||||
@ -80,10 +81,11 @@ namespace osu.Game.Overlays.FirstRunSetup
|
|||||||
});
|
});
|
||||||
|
|
||||||
frameworkLocale = frameworkConfig.GetBindable<string>(FrameworkSetting.Locale);
|
frameworkLocale = frameworkConfig.GetBindable<string>(FrameworkSetting.Locale);
|
||||||
frameworkLocale.BindValueChanged(locale =>
|
|
||||||
|
localisationParameters = localisation.CurrentParameters.GetBoundCopy();
|
||||||
|
localisationParameters.BindValueChanged(p =>
|
||||||
{
|
{
|
||||||
if (!LanguageExtensions.TryParseCultureCode(locale.NewValue, out var language))
|
var language = LanguageExtensions.GetLanguageFor(frameworkLocale.Value, p.NewValue);
|
||||||
language = Language.en;
|
|
||||||
|
|
||||||
// Changing language may cause a short period of blocking the UI thread while the new glyphs are loaded.
|
// Changing language may cause a short period of blocking the UI thread while the new glyphs are loaded.
|
||||||
// Scheduling ensures the button animation plays smoothly after any blocking operation completes.
|
// Scheduling ensures the button animation plays smoothly after any blocking operation completes.
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Configuration;
|
using osu.Framework.Configuration;
|
||||||
@ -16,15 +14,17 @@ namespace osu.Game.Overlays.Settings.Sections.General
|
|||||||
{
|
{
|
||||||
public class LanguageSettings : SettingsSubsection
|
public class LanguageSettings : SettingsSubsection
|
||||||
{
|
{
|
||||||
private SettingsDropdown<Language> languageSelection;
|
private SettingsDropdown<Language> languageSelection = null!;
|
||||||
private Bindable<string> frameworkLocale;
|
private Bindable<string> frameworkLocale = null!;
|
||||||
|
private IBindable<LocalisationParameters> localisationParameters = null!;
|
||||||
|
|
||||||
protected override LocalisableString Header => GeneralSettingsStrings.LanguageHeader;
|
protected override LocalisableString Header => GeneralSettingsStrings.LanguageHeader;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(FrameworkConfigManager frameworkConfig, OsuConfigManager config)
|
private void load(FrameworkConfigManager frameworkConfig, OsuConfigManager config, LocalisationManager localisation)
|
||||||
{
|
{
|
||||||
frameworkLocale = frameworkConfig.GetBindable<string>(FrameworkSetting.Locale);
|
frameworkLocale = frameworkConfig.GetBindable<string>(FrameworkSetting.Locale);
|
||||||
|
localisationParameters = localisation.CurrentParameters.GetBoundCopy();
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
@ -44,12 +44,8 @@ namespace osu.Game.Overlays.Settings.Sections.General
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
frameworkLocale.BindValueChanged(locale =>
|
localisationParameters.BindValueChanged(p
|
||||||
{
|
=> languageSelection.Current.Value = LanguageExtensions.GetLanguageFor(frameworkLocale.Value, p.NewValue), true);
|
||||||
if (!LanguageExtensions.TryParseCultureCode(locale.NewValue, out var language))
|
|
||||||
language = Language.en;
|
|
||||||
languageSelection.Current.Value = language;
|
|
||||||
}, true);
|
|
||||||
|
|
||||||
languageSelection.Current.BindValueChanged(val => frameworkLocale.Value = val.NewValue.ToCultureCode());
|
languageSelection.Current.BindValueChanged(val => frameworkLocale.Value = val.NewValue.ToCultureCode());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user