diff --git a/ProjectLighthouse.Localization/LandingPage.resx b/ProjectLighthouse.Localization/LandingPage.resx index b277bcf8..287660e3 100644 --- a/ProjectLighthouse.Localization/LandingPage.resx +++ b/ProjectLighthouse.Localization/LandingPage.resx @@ -53,4 +53,12 @@ You have {0} authentication attempts pending. Click here to view them. A greeting on the main page of the website. + + + Newest Levels + + + + Latest Team Picks + \ No newline at end of file diff --git a/ProjectLighthouse.Localization/LocalizationManager.cs b/ProjectLighthouse.Localization/LocalizationManager.cs index 4b2d2660..6f63cf8a 100644 --- a/ProjectLighthouse.Localization/LocalizationManager.cs +++ b/ProjectLighthouse.Localization/LocalizationManager.cs @@ -7,7 +7,7 @@ namespace LBPUnion.ProjectLighthouse.Localization; public static class LocalizationManager { private static readonly string namespaceStr = typeof(LocalizationManager).Namespace ?? ""; - public const string DefaultLang = "en-US"; + public const string DefaultLang = "ja-JP"; public static string GetLocalizedString(TranslationAreas translationArea, string language, string key) { diff --git a/ProjectLighthouse.Localization/StringLists/LandingPageStrings.cs b/ProjectLighthouse.Localization/StringLists/LandingPageStrings.cs index 6a0b58d8..7ec962e8 100644 --- a/ProjectLighthouse.Localization/StringLists/LandingPageStrings.cs +++ b/ProjectLighthouse.Localization/StringLists/LandingPageStrings.cs @@ -9,6 +9,9 @@ public static class LandingPageStrings public static readonly TranslatableString UsersSingle = create("users_single"); public static readonly TranslatableString UsersMultiple = create("users_multiple"); + public static readonly TranslatableString LatestTeamPicks = create("latest_team_picks"); + public static readonly TranslatableString NewestLevels = create("newest_levels"); + public static readonly TranslatableString AuthAttemptsPending = create("authAttemptsPending"); private static TranslatableString create(string key) => new(TranslationAreas.LandingPage, key); diff --git a/ProjectLighthouse.Localization/TranslatableString.cs b/ProjectLighthouse.Localization/TranslatableString.cs index 89530be6..633a5eb4 100644 --- a/ProjectLighthouse.Localization/TranslatableString.cs +++ b/ProjectLighthouse.Localization/TranslatableString.cs @@ -13,6 +13,8 @@ public class TranslatableString public string Translate(string language) => LocalizationManager.GetLocalizedString(this.Area, language, this.Key); + public string Translate(string language, params object?[] format) => string.Format(LocalizationManager.GetLocalizedString(this.Area, language, this.Key), format); + // CS0809 is a warning about obsolete methods overriding non-obsoleted methods. // That works against what we're trying to do here, so we disable the warning here. #pragma warning disable CS0809 diff --git a/ProjectLighthouse.Servers.Website/Pages/LandingPage.cshtml b/ProjectLighthouse.Servers.Website/Pages/LandingPage.cshtml index c881ae1e..60dbddf0 100644 --- a/ProjectLighthouse.Servers.Website/Pages/LandingPage.cshtml +++ b/ProjectLighthouse.Servers.Website/Pages/LandingPage.cshtml @@ -3,6 +3,7 @@ @using LBPUnion.ProjectLighthouse.Extensions @using LBPUnion.ProjectLighthouse.PlayerData.Profiles @using LBPUnion.ProjectLighthouse.Levels +@using LBPUnion.ProjectLighthouse.Localization.StringLists @model LBPUnion.ProjectLighthouse.Servers.Website.Pages.LandingPage @{ @@ -10,22 +11,22 @@ Model.ShowTitleInPage = false; bool isMobile = this.Request.IsMobile(); } -

Welcome to @ServerConfiguration.Instance.Customization.ServerName!

+

@Model.Translate(LandingPageStrings.Welcome, ServerConfiguration.Instance.Customization.ServerName)

@if (Model.User != null) { -

You are currently logged in as @Model.User.Username.

- if (ServerConfiguration.Instance.Authentication.UseExternalAuth && Model.AuthenticationAttemptsCount > 0) +

@Model.Translate(LandingPageStrings.LoggedInAs, Model.User.Username)

+ if (ServerConfiguration.Instance.Authentication.UseExternalAuth && Model.PendingAuthAttempts > 0) {

- You have @Model.AuthenticationAttemptsCount authentication attempts pending. Click here to view them. + @Model.Translate(LandingPageStrings.AuthAttemptsPending, Model.PendingAuthAttempts)

} } @if (Model.PlayersOnlineCount == 1) { -

There is 1 user currently online:

+

@Model.Translate(LandingPageStrings.UsersSingle)

@foreach (User user in Model.PlayersOnline) { @user.Username @@ -34,11 +35,11 @@ else if (Model.PlayersOnlineCount == 0) { -

There are no users online. Why not hop on?

+

@Model.Translate(LandingPageStrings.UsersNone)

} else { -

There are currently @Model.PlayersOnlineCount users online:

+

@Model.Translate(LandingPageStrings.UsersMultiple, Model.PlayersOnlineCount)

@foreach (User user in Model.PlayersOnline) { @user.Username @@ -50,7 +51,7 @@ else
-

Latest Team Picks

+

@Model.Translate(LandingPageStrings.LatestTeamPicks)

@foreach (Slot slot in Model.LatestTeamPicks!) @* Can't reach a point where this is null *@ @@ -67,7 +68,7 @@ else }
-

Newest Levels

+

@Model.Translate(LandingPageStrings.NewestLevels)

@foreach (Slot slot in Model.NewestLevels!) @* Can't reach a point where this is null *@ diff --git a/ProjectLighthouse.Servers.Website/Pages/LandingPage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/LandingPage.cshtml.cs index 20b13dbc..fecee91b 100644 --- a/ProjectLighthouse.Servers.Website/Pages/LandingPage.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/LandingPage.cshtml.cs @@ -15,7 +15,7 @@ public class LandingPage : BaseLayout public LandingPage(Database database) : base(database) {} - public int AuthenticationAttemptsCount; + public int PendingAuthAttempts; public List PlayersOnline = new(); public int PlayersOnlineCount; @@ -32,7 +32,7 @@ public class LandingPage : BaseLayout this.PlayersOnlineCount = await StatisticsHelper.RecentMatches(); if (user != null) - this.AuthenticationAttemptsCount = await this.Database.AuthenticationAttempts.Include + this.PendingAuthAttempts = await this.Database.AuthenticationAttempts.Include (a => a.GameToken) .CountAsync(a => a.GameToken.UserId == user.UserId); diff --git a/ProjectLighthouse.Servers.Website/Pages/Layouts/BaseLayout.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/Layouts/BaseLayout.cshtml.cs index 9ea0510f..c8c8e882 100644 --- a/ProjectLighthouse.Servers.Website/Pages/Layouts/BaseLayout.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/Layouts/BaseLayout.cshtml.cs @@ -45,19 +45,15 @@ public class BaseLayout : PageModel set => this.user = value; } - public string Translate(TranslatableString translatableString) + private string getLanguage() { - string lang; + return "da-DK"; IRequestCultureFeature? requestCulture = Request.HttpContext.Features.Get(); - - if (requestCulture == null) lang = LocalizationManager.DefaultLang; - else - { - lang = requestCulture.RequestCulture.UICulture.Name; - } - - Console.WriteLine(lang); - - return translatableString.Translate(lang); + + if (requestCulture == null) return LocalizationManager.DefaultLang; + return requestCulture.RequestCulture.UICulture.Name; } + + public string Translate(TranslatableString translatableString) => translatableString.Translate(this.getLanguage()); + public string Translate(TranslatableString translatableString, params object?[] format) => translatableString.Translate(this.getLanguage(), format); } \ No newline at end of file