mirror of
https://github.com/ppy/osu.git
synced 2025-03-15 17:47:18 +08:00
Add basic language switching ability
This commit is contained in:
parent
e227c076e5
commit
623eae1576
57
osu.Game/Localisation/ResourceManagerLocalisationStore.cs
Normal file
57
osu.Game/Localisation/ResourceManagerLocalisationStore.cs
Normal file
@ -0,0 +1,57 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Resources;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Localisation;
|
||||
|
||||
namespace osu.Game.Localisation
|
||||
{
|
||||
public class ResourceManagerLocalisationStore : ILocalisationStore
|
||||
{
|
||||
private readonly Dictionary<string, ResourceManager> resourceManagers = new Dictionary<string, ResourceManager>();
|
||||
|
||||
public ResourceManagerLocalisationStore(string cultureCode)
|
||||
{
|
||||
EffectiveCulture = new CultureInfo(cultureCode);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
public string Get(string lookup)
|
||||
{
|
||||
var split = lookup.Split(':');
|
||||
|
||||
string ns = split[0];
|
||||
string key = split[1];
|
||||
|
||||
if (!resourceManagers.TryGetValue(ns, out var manager))
|
||||
resourceManagers[ns] = manager = new ResourceManager(ns, GetType().Assembly);
|
||||
|
||||
return manager.GetString(key, EffectiveCulture);
|
||||
}
|
||||
|
||||
public Task<string> GetAsync(string lookup)
|
||||
{
|
||||
return Task.FromResult(Get(lookup));
|
||||
}
|
||||
|
||||
public Stream GetStream(string name)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetAvailableResources()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public CultureInfo EffectiveCulture { get; }
|
||||
}
|
||||
}
|
@ -51,6 +51,7 @@ using osu.Game.Utils;
|
||||
using LogLevel = osu.Framework.Logging.LogLevel;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.IO;
|
||||
using osu.Game.Localisation;
|
||||
|
||||
namespace osu.Game
|
||||
{
|
||||
@ -541,6 +542,12 @@ namespace osu.Game
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
foreach (var language in Enum.GetValues(typeof(Language)).OfType<Language>())
|
||||
{
|
||||
var cultureCode = language.ToString();
|
||||
Localisation.AddLanguage(cultureCode, new ResourceManagerLocalisationStore(cultureCode));
|
||||
}
|
||||
|
||||
// The next time this is updated is in UpdateAfterChildren, which occurs too late and results
|
||||
// in the cursor being shown for a few frames during the intro.
|
||||
// This prevents the cursor from showing until we have a screen with CursorVisible = true
|
||||
|
@ -1,27 +1,45 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Localisation;
|
||||
|
||||
namespace osu.Game.Overlays.Settings.Sections.General
|
||||
{
|
||||
public class LanguageSettings : SettingsSubsection
|
||||
{
|
||||
private SettingsDropdown<Language> languageSelection;
|
||||
private Bindable<string> frameworkLocale;
|
||||
|
||||
protected override string Header => "Language";
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(FrameworkConfigManager frameworkConfig)
|
||||
{
|
||||
frameworkLocale = frameworkConfig.GetBindable<string>(FrameworkSetting.Locale);
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
languageSelection = new SettingsEnumDropdown<Language>
|
||||
{
|
||||
LabelText = "Language",
|
||||
},
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = "Prefer metadata in original language",
|
||||
Current = frameworkConfig.GetBindable<bool>(FrameworkSetting.ShowUnicode)
|
||||
},
|
||||
};
|
||||
|
||||
if (!Enum.TryParse<Language>(frameworkLocale.Value, out var locale))
|
||||
locale = Language.en;
|
||||
languageSelection.Current.Value = locale;
|
||||
|
||||
languageSelection.Current.BindValueChanged(val => frameworkLocale.Value = val.NewValue.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user