diff --git a/TaikoWebUI/Components/ChooseSongNameLanguage.razor b/TaikoWebUI/Components/ChooseSongNameLanguage.razor new file mode 100644 index 0000000..c320ab6 --- /dev/null +++ b/TaikoWebUI/Components/ChooseSongNameLanguage.razor @@ -0,0 +1,54 @@ +@using Blazored.LocalStorage +@using Microsoft.Extensions.Options +@using TaikoWebUI.Settings +@inject NavigationManager NavigationManager +@inject IOptions Settings +@inject ILocalStorageService LocalStorage + + + @Localizer["Song Name Language"] + + @foreach (var culture in supportedCultures) + { + @culture.Value + } + + +@code { + private readonly Dictionary supportedCultures = new(); + + protected override async Task OnInitializedAsync() + { + await base.OnInitializedAsync(); + foreach (var language in Settings.Value.SupportedLanguages) + { + supportedCultures.Add(new CultureInfo(language.CultureCode), language.DisplayName); + } + + if (supportedCultures.Count == 0) + { + supportedCultures.Add(new CultureInfo("en-US"), "English"); + } + + var currentSongNameLanguage = await LocalStorage.GetItemAsync("songNameLanguage"); + + if (string.IsNullOrEmpty(currentSongNameLanguage)) + { + await LocalStorage.SetItemAsync("songNameLanguage", "en-US"); + } + } + + private async Task RequestCultureChange(CultureInfo newCulture) + { + var currentSongNameLanguage = await LocalStorage.GetItemAsync("songNameLanguage"); + + if (currentSongNameLanguage == newCulture.Name) + { + return; + } + + await LocalStorage.SetItemAsync("songNameLanguage", newCulture.Name); + + NavigationManager.NavigateTo(NavigationManager.Uri, forceLoad: true); + } +} \ No newline at end of file diff --git a/TaikoWebUI/Components/ChooseLanguage.razor b/TaikoWebUI/Components/ChooseUILanguage.razor similarity index 57% rename from TaikoWebUI/Components/ChooseLanguage.razor rename to TaikoWebUI/Components/ChooseUILanguage.razor index 7762dab..92a38d8 100644 --- a/TaikoWebUI/Components/ChooseLanguage.razor +++ b/TaikoWebUI/Components/ChooseUILanguage.razor @@ -1,31 +1,32 @@ -@using System.Globalization; -@using Microsoft.Extensions.Options +@using Microsoft.Extensions.Options @using TaikoWebUI.Settings @inject NavigationManager NavigationManager -@inject IJSRuntime JSRuntime +@inject IJSRuntime JsRuntime @inject IOptions Settings - - @foreach (var culture in SupportedCultures) + + @Localizer["UI Language"] + + @foreach (var culture in supportedCultures) { @culture.Value } @code { - public Dictionary SupportedCultures = new(); + private Dictionary supportedCultures = new(); protected override void OnInitialized() { base.OnInitialized(); foreach (var language in Settings.Value.SupportedLanguages) { - SupportedCultures.Add(new CultureInfo(language.CultureCode), language.DisplayName); + supportedCultures.Add(new CultureInfo(language.CultureCode), language.DisplayName); } - if (SupportedCultures.Count == 0) + if (supportedCultures.Count == 0) { - SupportedCultures.Add(new CultureInfo("en-US"), "English"); + supportedCultures.Add(new CultureInfo("en-US"), "English"); } } @@ -36,9 +37,8 @@ return; } - var js = (IJSInProcessRuntime)JSRuntime; + var js = (IJSInProcessRuntime)JsRuntime; js.InvokeVoid("blazorCulture.set", newCulture.Name); NavigationManager.NavigateTo(NavigationManager.Uri, forceLoad: true); } - } diff --git a/TaikoWebUI/Components/MainLayout.razor b/TaikoWebUI/Components/MainLayout.razor index 0cb2fc6..c22dc60 100644 --- a/TaikoWebUI/Components/MainLayout.razor +++ b/TaikoWebUI/Components/MainLayout.razor @@ -1,6 +1,5 @@ @inherits LayoutComponentBase @inject Blazored.LocalStorage.ILocalStorageService LocalStorage -@inject HttpClient Client @inject AuthService AuthService @@ -11,9 +10,10 @@ - + - + + diff --git a/TaikoWebUI/Localization/LocalizationResource.Designer.cs b/TaikoWebUI/Localization/LocalizationResource.Designer.cs index 387d60f..83a4c0a 100644 --- a/TaikoWebUI/Localization/LocalizationResource.Designer.cs +++ b/TaikoWebUI/Localization/LocalizationResource.Designer.cs @@ -752,6 +752,15 @@ namespace TaikoWebUI.Localization { } } + /// + /// Looks up a localized string similar to . + /// + internal static string Song_Name_Language { + get { + return ResourceManager.GetString("Song Name Language", resourceCulture); + } + } + /// /// Looks up a localized string similar to . /// @@ -824,6 +833,15 @@ namespace TaikoWebUI.Localization { } } + /// + /// Looks up a localized string similar to . + /// + internal static string UI_Language { + get { + return ResourceManager.GetString("UI Language", resourceCulture); + } + } + /// /// Looks up a localized string similar to . /// diff --git a/TaikoWebUI/Localization/LocalizationResource.en-US.resx b/TaikoWebUI/Localization/LocalizationResource.en-US.resx index 21627d0..968e69d 100644 --- a/TaikoWebUI/Localization/LocalizationResource.en-US.resx +++ b/TaikoWebUI/Localization/LocalizationResource.en-US.resx @@ -594,4 +594,10 @@ Rows Per Page: + + UI Lang + + + Song Lang + \ No newline at end of file diff --git a/TaikoWebUI/Localization/LocalizationResource.ja.resx b/TaikoWebUI/Localization/LocalizationResource.ja.resx index 3767034..f8a30b9 100644 --- a/TaikoWebUI/Localization/LocalizationResource.ja.resx +++ b/TaikoWebUI/Localization/LocalizationResource.ja.resx @@ -594,4 +594,10 @@ 1ページ当たりの行数 + + UI言語 + + + 曲名言語 + \ No newline at end of file diff --git a/TaikoWebUI/Localization/LocalizationResource.resx b/TaikoWebUI/Localization/LocalizationResource.resx index ade4ce2..b7964fe 100644 --- a/TaikoWebUI/Localization/LocalizationResource.resx +++ b/TaikoWebUI/Localization/LocalizationResource.resx @@ -390,4 +390,10 @@ + + + + + + \ No newline at end of file diff --git a/TaikoWebUI/Localization/LocalizationResource.zh-Hans.resx b/TaikoWebUI/Localization/LocalizationResource.zh-Hans.resx index dd459a5..2e7260c 100644 --- a/TaikoWebUI/Localization/LocalizationResource.zh-Hans.resx +++ b/TaikoWebUI/Localization/LocalizationResource.zh-Hans.resx @@ -591,4 +591,10 @@ 每页行数 + + 界面语言 + + + 曲名语言 + \ No newline at end of file diff --git a/TaikoWebUI/Localization/LocalizationResource.zh-Hant.resx b/TaikoWebUI/Localization/LocalizationResource.zh-Hant.resx index 6546b94..19632c1 100644 --- a/TaikoWebUI/Localization/LocalizationResource.zh-Hant.resx +++ b/TaikoWebUI/Localization/LocalizationResource.zh-Hant.resx @@ -591,4 +591,10 @@ 每頁行數 + + 界面語言 + + + 曲名語言 + \ No newline at end of file diff --git a/TaikoWebUI/Pages/DaniDojo.razor b/TaikoWebUI/Pages/DaniDojo.razor index 7cc0b03..3681494 100644 --- a/TaikoWebUI/Pages/DaniDojo.razor +++ b/TaikoWebUI/Pages/DaniDojo.razor @@ -1,8 +1,11 @@ -@inject IGameDataService GameDataService +@using Blazored.LocalStorage + +@inject IGameDataService GameDataService @inject HttpClient Client @inject AuthService AuthService @inject IJSRuntime JsRuntime @inject NavigationManager NavigationManager +@inject ILocalStorageService LocalStorage @page "/Users/{baid:int}/DaniDojo" @@ -148,12 +151,12 @@ else - @GameDataService.GetMusicNameBySongId(musicDetailDictionary, danDataOdaiSong.SongNo, @CurrentLanguage) - @GameDataService.GetMusicArtistBySongId(musicDetailDictionary, danDataOdaiSong.SongNo, @CurrentLanguage) + @GameDataService.GetMusicNameBySongId(musicDetailDictionary, danDataOdaiSong.SongNo, SongNameLanguage) + @GameDataService.GetMusicArtistBySongId(musicDetailDictionary, danDataOdaiSong.SongNo, SongNameLanguage) - @if (bestDataMap.TryGetValue(danId, out var danBestData)) + @if (_bestDataMap.TryGetValue(danId, out var danBestData)) { if (danBestData.DanBestStageDataList.Count > index) { @@ -218,7 +221,7 @@ else } @Localizer["Result"] - @if (bestDataMap.TryGetValue(danId, out var danBestData)) + @if (_bestDataMap.TryGetValue(danId, out var danBestData)) { if (danBestData.SoulGaugeTotal >= redRequirement) { barClass = "bar-pass-red"; @@ -288,7 +291,7 @@ else } @Localizer["Result"] - @if (bestDataMap.TryGetValue(danId, out var danBestData)) + @if (_bestDataMap.TryGetValue(danId, out var danBestData)) { var bestData = GetAllBestFromData((DanConditionType)border.OdaiType, danBestData); @@ -381,7 +384,7 @@ else @Localizer["Result"] - @if (bestDataMap.TryGetValue(danId, out var danBestData) && (danBestData.DanBestStageDataList.Count > songNumber)) + @if (_bestDataMap.TryGetValue(danId, out var danBestData) && (danBestData.DanBestStageDataList.Count > songNumber)) { var bestData = GetSongBestFromData((DanConditionType)border.OdaiType, danBestData, songNumber); if ((DanConditionType)border.OdaiType is DanConditionType.BadCount or DanConditionType.OkCount) diff --git a/TaikoWebUI/Pages/DaniDojo.razor.cs b/TaikoWebUI/Pages/DaniDojo.razor.cs index 6a69f03..530a567 100644 --- a/TaikoWebUI/Pages/DaniDojo.razor.cs +++ b/TaikoWebUI/Pages/DaniDojo.razor.cs @@ -6,12 +6,13 @@ public partial class DaniDojo { [Parameter] public int Baid { get; set; } - public string CurrentLanguage { get; set; } = "ja"; + + private string? SongNameLanguage { get; set; } private DanBestDataResponse? response; private UserSetting? userSetting; - private static Dictionary bestDataMap = new(); + private static Dictionary _bestDataMap = new(); private Dictionary musicDetailDictionary = new(); private readonly List breadcrumbs = new(); @@ -29,9 +30,9 @@ public partial class DaniDojo response.ThrowIfNull(); response.DanBestDataList.ForEach(data => data.DanBestStageDataList .Sort((stageData, otherStageData) => stageData.SongNumber.CompareTo(otherStageData.SongNumber))); - bestDataMap = response.DanBestDataList.ToDictionary(data => data.DanId); + _bestDataMap = response.DanBestDataList.ToDictionary(data => data.DanId); - CurrentLanguage = await JsRuntime.InvokeAsync("blazorCulture.get"); + SongNameLanguage = await LocalStorage.GetItemAsync("songNameLanguage"); userSetting = await Client.GetFromJsonAsync($"api/UserSettings/{Baid}"); @@ -176,12 +177,12 @@ public partial class DaniDojo string icon; const string notClearIcon = ""; - if (!bestDataMap.ContainsKey(danId)) + if (!_bestDataMap.ContainsKey(danId)) { return notClearIcon; } - var state = bestDataMap[danId].ClearState; + var state = _bestDataMap[danId].ClearState; icon = state is DanClearState.NotClear ? notClearIcon : $""; @@ -190,7 +191,7 @@ public partial class DaniDojo private DanClearState GetDanResultState(uint danId) { - return bestDataMap.ContainsKey(danId) ? bestDataMap[danId].ClearState : DanClearState.NotClear; + return _bestDataMap.ContainsKey(danId) ? _bestDataMap[danId].ClearState : DanClearState.NotClear; } private static uint GetSoulGauge(DanData data, bool isGold) @@ -217,36 +218,36 @@ public partial class DaniDojo private static long GetTotalScore(uint danId) { - return bestDataMap.ContainsKey(danId) ? bestDataMap[danId].DanBestStageDataList.Sum(stageData => stageData.HighScore) : 0; + return _bestDataMap.ContainsKey(danId) ? _bestDataMap[danId].DanBestStageDataList.Sum(stageData => stageData.HighScore) : 0; } private static long GetTotalGoodHits(uint danId) { - return bestDataMap.ContainsKey(danId) ? bestDataMap[danId].DanBestStageDataList.Sum(stageData => stageData.GoodCount) : 0; + return _bestDataMap.ContainsKey(danId) ? _bestDataMap[danId].DanBestStageDataList.Sum(stageData => stageData.GoodCount) : 0; } private static long GetTotalOkHits(uint danId) { - return bestDataMap.ContainsKey(danId) ? bestDataMap[danId].DanBestStageDataList.Sum(stageData => stageData.OkCount) : 0; + return _bestDataMap.ContainsKey(danId) ? _bestDataMap[danId].DanBestStageDataList.Sum(stageData => stageData.OkCount) : 0; } private static long GetTotalBadHits(uint danId) { - return bestDataMap.ContainsKey(danId) ? bestDataMap[danId].DanBestStageDataList.Sum(stageData => stageData.BadCount) : 0; + return _bestDataMap.ContainsKey(danId) ? _bestDataMap[danId].DanBestStageDataList.Sum(stageData => stageData.BadCount) : 0; } private static long GetTotalDrumrollHits(uint danId) { - return bestDataMap.ContainsKey(danId) ? bestDataMap[danId].DanBestStageDataList.Sum(stageData => stageData.DrumrollCount) : 0; + return _bestDataMap.ContainsKey(danId) ? _bestDataMap[danId].DanBestStageDataList.Sum(stageData => stageData.DrumrollCount) : 0; } private static long GetTotalMaxCombo(uint danId) { - return bestDataMap.ContainsKey(danId) ? bestDataMap[danId].DanBestStageDataList.Sum(stageData => stageData.ComboCount) : 0; + return _bestDataMap.ContainsKey(danId) ? _bestDataMap[danId].DanBestStageDataList.Sum(stageData => stageData.ComboCount) : 0; } private static long GetTotalHits(uint danId) { - return bestDataMap.ContainsKey(danId) ? bestDataMap[danId].DanBestStageDataList.Sum(stageData => stageData.TotalHitCount) : 0; + return _bestDataMap.ContainsKey(danId) ? _bestDataMap[danId].DanBestStageDataList.Sum(stageData => stageData.TotalHitCount) : 0; } } \ No newline at end of file diff --git a/TaikoWebUI/Pages/HighScores.razor b/TaikoWebUI/Pages/HighScores.razor index f673278..b020942 100644 --- a/TaikoWebUI/Pages/HighScores.razor +++ b/TaikoWebUI/Pages/HighScores.razor @@ -1,10 +1,10 @@ -@inject IGameDataService GameDataService +@using TaikoWebUI.Utilities; + +@inject IGameDataService GameDataService @inject HttpClient Client @inject AuthService AuthService -@inject IJSRuntime JsRuntime @inject NavigationManager NavigationManager @inject Blazored.LocalStorage.ILocalStorageService LocalStorage -@using TaikoWebUI.Utilities; @page "/Users/{baid:int}/HighScores" diff --git a/TaikoWebUI/Pages/HighScores.razor.cs b/TaikoWebUI/Pages/HighScores.razor.cs index 5ad5351..7a2ceac 100644 --- a/TaikoWebUI/Pages/HighScores.razor.cs +++ b/TaikoWebUI/Pages/HighScores.razor.cs @@ -1,6 +1,4 @@ -using Microsoft.JSInterop; - -namespace TaikoWebUI.Pages; +namespace TaikoWebUI.Pages; public partial class HighScores { @@ -29,15 +27,15 @@ public partial class HighScores userSetting = await Client.GetFromJsonAsync($"api/UserSettings/{Baid}"); - var language = await JsRuntime.InvokeAsync("blazorCulture.get"); + var songNameLanguage = await LocalStorage.GetItemAsync("songNameLanguage"); musicDetailDictionary = await GameDataService.GetMusicDetailDictionary(); response.SongBestData.ForEach(data => { var songId = data.SongId; data.Genre = GameDataService.GetMusicGenreBySongId(musicDetailDictionary, songId); - data.MusicName = GameDataService.GetMusicNameBySongId(musicDetailDictionary, songId, string.IsNullOrEmpty(language) ? "ja" : language); - data.MusicArtist = GameDataService.GetMusicArtistBySongId(musicDetailDictionary, songId, string.IsNullOrEmpty(language) ? "ja" : language); + data.MusicName = GameDataService.GetMusicNameBySongId(musicDetailDictionary, songId, string.IsNullOrEmpty(songNameLanguage) ? "ja" : songNameLanguage); + data.MusicArtist = GameDataService.GetMusicArtistBySongId(musicDetailDictionary, songId, string.IsNullOrEmpty(songNameLanguage) ? "ja" : songNameLanguage); }); songBestDataMap = response.SongBestData.GroupBy(data => data.Difficulty) diff --git a/TaikoWebUI/Pages/PlayHistory.razor b/TaikoWebUI/Pages/PlayHistory.razor index 7938a9d..2f67919 100644 --- a/TaikoWebUI/Pages/PlayHistory.razor +++ b/TaikoWebUI/Pages/PlayHistory.razor @@ -1,8 +1,11 @@ +@using Blazored.LocalStorage + @inject IGameDataService GameDataService @inject HttpClient Client @inject AuthService AuthService @inject IJSRuntime JsRuntime @inject NavigationManager NavigationManager +@inject ILocalStorageService LocalStorage @page "/Users/{baid:int}/PlayHistory" diff --git a/TaikoWebUI/Pages/PlayHistory.razor.cs b/TaikoWebUI/Pages/PlayHistory.razor.cs index 1bcb070..c0d29a1 100644 --- a/TaikoWebUI/Pages/PlayHistory.razor.cs +++ b/TaikoWebUI/Pages/PlayHistory.razor.cs @@ -12,7 +12,7 @@ public partial class PlayHistory private string Search { get; set; } = string.Empty; - private string? currentLanguage; + private string? songNameLanguage; private SongHistoryResponse? response; @@ -35,7 +35,7 @@ public partial class PlayHistory response = await Client.GetFromJsonAsync($"api/PlayHistory/{(uint)Baid}"); response.ThrowIfNull(); - currentLanguage = await JsRuntime.InvokeAsync("blazorCulture.get"); + songNameLanguage = await LocalStorage.GetItemAsync("songNameLanguage"); musicDetailDictionary = await GameDataService.GetMusicDetailDictionary(); @@ -43,8 +43,8 @@ public partial class PlayHistory { var songId = data.SongId; data.Genre = GameDataService.GetMusicGenreBySongId(musicDetailDictionary, songId); - data.MusicName = GameDataService.GetMusicNameBySongId(musicDetailDictionary, songId, string.IsNullOrEmpty(currentLanguage) ? "ja" : currentLanguage); - data.MusicArtist = GameDataService.GetMusicArtistBySongId(musicDetailDictionary, songId, string.IsNullOrEmpty(currentLanguage) ? "ja" : currentLanguage); + data.MusicName = GameDataService.GetMusicNameBySongId(musicDetailDictionary, songId, string.IsNullOrEmpty(songNameLanguage) ? "ja" : songNameLanguage); + data.MusicArtist = GameDataService.GetMusicArtistBySongId(musicDetailDictionary, songId, string.IsNullOrEmpty(songNameLanguage) ? "ja" : songNameLanguage); data.Stars = GameDataService.GetMusicStarLevel(musicDetailDictionary, songId, data.Difficulty); data.ShowDetails = false; }); @@ -140,7 +140,7 @@ public partial class PlayHistory return true; } - var language = currentLanguage ?? "ja"; + var language = songNameLanguage ?? "ja"; if (songHistoryDataList[0].PlayTime .ToString("dddd d MMMM yyyy - HH:mm", CultureInfo.CreateSpecificCulture(language)) diff --git a/TaikoWebUI/Pages/Song.razor b/TaikoWebUI/Pages/Song.razor index df4f2be..86ba546 100644 --- a/TaikoWebUI/Pages/Song.razor +++ b/TaikoWebUI/Pages/Song.razor @@ -1,12 +1,13 @@ @page "/Users/{baid:int}/Songs/{songId:int}" +@using Blazored.LocalStorage +@using TaikoWebUI.Components.Song + @inject IGameDataService GameDataService @inject HttpClient Client @inject AuthService AuthService @inject NavigationManager NavigationManager -@inject IJSRuntime JsRuntime - -@using TaikoWebUI.Components.Song; +@inject ILocalStorageService LocalStorage @if (AuthService.LoginRequired && (!AuthService.IsLoggedIn || (AuthService.GetLoggedInBaid() != Baid && !AuthService.IsAdmin))) { diff --git a/TaikoWebUI/Pages/Song.razor.cs b/TaikoWebUI/Pages/Song.razor.cs index db314bc..c447a6a 100644 --- a/TaikoWebUI/Pages/Song.razor.cs +++ b/TaikoWebUI/Pages/Song.razor.cs @@ -1,65 +1,62 @@ -using Microsoft.JSInterop; +namespace TaikoWebUI.Pages; -namespace TaikoWebUI.Pages +public partial class Song { - public partial class Song + [Parameter] + public int SongId { get; set; } + + [Parameter] + public int Baid { get; set; } + + private UserSetting? userSetting; + private SongHistoryResponse? response; + private List? songHistoryData; + private readonly List breadcrumbs = new(); + + private string songTitle = string.Empty; + private string songArtist = string.Empty; + + protected override async Task OnInitializedAsync() { - [Parameter] - public int SongId { get; set; } - - [Parameter] - public int Baid { get; set; } - - private UserSetting? userSetting; - private SongHistoryResponse? response; - private List? songHistoryData; - private readonly List breadcrumbs = new(); - - private string songTitle = string.Empty; - private string songArtist = string.Empty; - - protected override async Task OnInitializedAsync() + await base.OnInitializedAsync(); + + if (AuthService.LoginRequired && !AuthService.IsLoggedIn) { - await base.OnInitializedAsync(); - - if (AuthService.LoginRequired && !AuthService.IsLoggedIn) - { - await AuthService.LoginWithAuthToken(); - } - - response = await Client.GetFromJsonAsync($"api/PlayHistory/{(uint)Baid}"); - response.ThrowIfNull(); - // Get all song best data with SongId - songHistoryData = response.SongHistoryData.Where(data => data.SongId == (uint)SongId).ToList(); - - // Get user settings - userSetting = await Client.GetFromJsonAsync($"api/UserSettings/{Baid}"); - - var musicDetailDictionary = await GameDataService.GetMusicDetailDictionary(); - - // Get song title and artist - var language = await JsRuntime.InvokeAsync("blazorCulture.get"); - songTitle = GameDataService.GetMusicNameBySongId(musicDetailDictionary, (uint)SongId, string.IsNullOrEmpty(language) ? "ja" : language); - songArtist = GameDataService.GetMusicArtistBySongId(musicDetailDictionary, (uint)SongId, string.IsNullOrEmpty(language) ? "ja" : language); - - // Breadcrumbs - var formattedSongTitle = songTitle; - if (formattedSongTitle.Length > 20) - { - formattedSongTitle = string.Concat(formattedSongTitle.AsSpan(0, 20), "..."); - } - - if (AuthService.IsLoggedIn && !AuthService.IsAdmin) - { - breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/")); - } - else - { - breadcrumbs.Add(new BreadcrumbItem(Localizer["Users"], href: "/Users")); - }; - breadcrumbs.Add(new BreadcrumbItem($"{userSetting?.MyDonName}", href: null, disabled: true)); - breadcrumbs.Add(new BreadcrumbItem(Localizer["Song List"], href: $"/Users/{Baid}/Songs", disabled: false)); - breadcrumbs.Add(new BreadcrumbItem(formattedSongTitle, href: $"/Users/{Baid}/Songs/{SongId}", disabled: false)); + await AuthService.LoginWithAuthToken(); } + + response = await Client.GetFromJsonAsync($"api/PlayHistory/{(uint)Baid}"); + response.ThrowIfNull(); + // Get all song best data with SongId + songHistoryData = response.SongHistoryData.Where(data => data.SongId == (uint)SongId).ToList(); + + // Get user settings + userSetting = await Client.GetFromJsonAsync($"api/UserSettings/{Baid}"); + + var musicDetailDictionary = await GameDataService.GetMusicDetailDictionary(); + + // Get song title and artist + var songNameLanguage = await LocalStorage.GetItemAsync("songNameLanguage"); + songTitle = GameDataService.GetMusicNameBySongId(musicDetailDictionary, (uint)SongId, string.IsNullOrEmpty(songNameLanguage) ? "ja" : songNameLanguage); + songArtist = GameDataService.GetMusicArtistBySongId(musicDetailDictionary, (uint)SongId, string.IsNullOrEmpty(songNameLanguage) ? "ja" : songNameLanguage); + + // Breadcrumbs + var formattedSongTitle = songTitle; + if (formattedSongTitle.Length > 20) + { + formattedSongTitle = string.Concat(formattedSongTitle.AsSpan(0, 20), "..."); + } + + if (AuthService.IsLoggedIn && !AuthService.IsAdmin) + { + breadcrumbs.Add(new BreadcrumbItem(Localizer["Dashboard"], href: "/")); + } + else + { + breadcrumbs.Add(new BreadcrumbItem(Localizer["Users"], href: "/Users")); + }; + breadcrumbs.Add(new BreadcrumbItem($"{userSetting?.MyDonName}", href: null, disabled: true)); + breadcrumbs.Add(new BreadcrumbItem(Localizer["Song List"], href: $"/Users/{Baid}/Songs", disabled: false)); + breadcrumbs.Add(new BreadcrumbItem(formattedSongTitle, href: $"/Users/{Baid}/Songs/{SongId}", disabled: false)); } -} +} \ No newline at end of file diff --git a/TaikoWebUI/Pages/SongList.razor b/TaikoWebUI/Pages/SongList.razor index ab9395e..8d14ab1 100644 --- a/TaikoWebUI/Pages/SongList.razor +++ b/TaikoWebUI/Pages/SongList.razor @@ -1,9 +1,11 @@ -@inject IGameDataService GameDataService +@using Blazored.LocalStorage +@using TaikoWebUI.Utilities; + +@inject IGameDataService GameDataService @inject HttpClient Client @inject AuthService AuthService -@inject IJSRuntime JsRuntime +@inject ILocalStorageService LocalStorage @inject NavigationManager NavigationManager -@using TaikoWebUI.Utilities; @page "/Users/{baid:int}/Songs" @@ -55,7 +57,7 @@ - + @Localizer["Song Title / Artist"] @@ -82,10 +84,10 @@ diff --git a/TaikoWebUI/Pages/SongList.razor.cs b/TaikoWebUI/Pages/SongList.razor.cs index 0231183..b866e80 100644 --- a/TaikoWebUI/Pages/SongList.razor.cs +++ b/TaikoWebUI/Pages/SongList.razor.cs @@ -1,6 +1,4 @@ -using Microsoft.JSInterop; - -namespace TaikoWebUI.Pages; +namespace TaikoWebUI.Pages; public partial class SongList { @@ -9,7 +7,7 @@ public partial class SongList private string Search { get; set; } = string.Empty; private string GenreFilter { get; set; } = string.Empty; - private string CurrentLanguage { get; set; } = "ja"; + private string? SongNameLanguage { get; set; } private SongBestResponse? response; private UserSetting? userSetting; @@ -33,7 +31,9 @@ public partial class SongList userSetting = await Client.GetFromJsonAsync($"api/UserSettings/{Baid}"); musicDetailDictionary = await GameDataService.GetMusicDetailDictionary(); - CurrentLanguage = await JsRuntime.InvokeAsync("blazorCulture.get"); + SongNameLanguage = await LocalStorage.GetItemAsync("songNameLanguage"); + + Console.WriteLine("Language: " + SongNameLanguage); if (AuthService.IsLoggedIn && !AuthService.IsAdmin) {