Add localisation for WikiHeader

Co-authored-by: huoyaoyuan <huoyaoyuan@hotmail.com>
This commit is contained in:
kj415j45 2021-07-17 19:25:25 +08:00
parent 4b4c341fb8
commit ba9b51c12d
2 changed files with 43 additions and 10 deletions

View File

@ -0,0 +1,29 @@
// 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 osu.Framework.Localisation;
namespace osu.Game.Localisation
{
public static class WikiStrings
{
private const string prefix = @"osu.Game.Resources.Localisation.Wiki";
/// <summary>
/// "index"
/// </summary>
public static LocalisableString IndexPageString => new TranslatableString(getKey(@"index_page"), @"index");
/// <summary>
/// "wiki"
/// </summary>
public static LocalisableString HeaderTitle => new TranslatableString(getKey(@"header_title"), @"wiki");
/// <summary>
/// "knowledge base"
/// </summary>
public static LocalisableString HeaderDescription => new TranslatableString(getKey(@"header_description"), @"knowledge base");
private static string getKey(string key) => $"{prefix}:{key}";
}
}

View File

@ -5,14 +5,18 @@ using System;
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Game.Localisation;
using osu.Game.Online.API.Requests.Responses;
namespace osu.Game.Overlays.Wiki
{
public class WikiHeader : BreadcrumbControlOverlayHeader
{
private const string index_page_string = "index";
private const string index_path = "Main_Page";
public static LocalisableString IndexPageString => WikiStrings.IndexPageString;
public static LocalisableString HeaderTitle => WikiStrings.HeaderTitle;
public static LocalisableString HeaderDescription => WikiStrings.HeaderDescription;
public readonly Bindable<APIWikiPage> WikiPageData = new Bindable<APIWikiPage>();
@ -21,8 +25,8 @@ namespace osu.Game.Overlays.Wiki
public WikiHeader()
{
TabControl.AddItem(index_page_string);
Current.Value = index_page_string;
TabControl.AddItem(IndexPageString);
Current.Value = IndexPageString;
WikiPageData.BindValueChanged(onWikiPageChange);
Current.BindValueChanged(onCurrentChange);
@ -34,13 +38,13 @@ namespace osu.Game.Overlays.Wiki
return;
TabControl.Clear();
Current.Value = null;
Current.Value = string.Empty;
TabControl.AddItem(index_page_string);
TabControl.AddItem(IndexPageString);
if (e.NewValue.Path == index_path)
{
Current.Value = index_page_string;
Current.Value = IndexPageString;
return;
}
@ -51,12 +55,12 @@ namespace osu.Game.Overlays.Wiki
Current.Value = e.NewValue.Title;
}
private void onCurrentChange(ValueChangedEvent<string> e)
private void onCurrentChange(ValueChangedEvent<LocalisableString> e)
{
if (e.NewValue == TabControl.Items.LastOrDefault())
return;
if (e.NewValue == index_page_string)
if (e.NewValue == IndexPageString)
{
ShowIndexPage?.Invoke();
return;
@ -73,8 +77,8 @@ namespace osu.Game.Overlays.Wiki
{
public WikiHeaderTitle()
{
Title = "wiki";
Description = "knowledge base";
Title = HeaderTitle;
Description = HeaderDescription;
IconTexture = "Icons/Hexacons/wiki";
}
}