Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically use in-game language for wiki pages #29401

Merged
merged 4 commits into from
Aug 13, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions osu.Game/Overlays/WikiOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Extensions;
using osu.Game.Localisation;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
Expand Down Expand Up @@ -38,11 +39,20 @@ public partial class WikiOverlay : OnlineOverlay<WikiHeader>

private WikiArticlePage articlePage;

private Bindable<Language> language;

public WikiOverlay()
: base(OverlayColourScheme.Orange, false)
{
}

[BackgroundDependencyLoader]
private void load(OsuGameBase game)
{
// Fetch current language on load for translated pages (if possible)
language = game.CurrentLanguage.GetBoundCopy();
smoogipoo marked this conversation as resolved.
Show resolved Hide resolved
}

public void ShowPage(string pagePath = INDEX_PATH)
{
path.Value = pagePath.Trim('/');
Expand Down Expand Up @@ -113,12 +123,13 @@ private void onPathChanged(ValueChangedEvent<string> e)
cancellationToken?.Cancel();
request?.Cancel();

// Language code + path, or just path1 + path2 in case
string[] values = e.NewValue.Split('/', 2);

if (values.Length > 1 && LanguageExtensions.TryParseCultureCode(values[0], out var language))
request = new GetWikiRequest(values[1], language);
if (values.Length > 1 && LanguageExtensions.TryParseCultureCode(values[0], out var lang))
request = new GetWikiRequest(values[1], lang);
else
request = new GetWikiRequest(e.NewValue);
request = new GetWikiRequest(e.NewValue, language.Value);

Loading.Show();

Expand Down