Finish translation of landing page

This commit is contained in:
jvyden 2022-07-26 16:44:19 -04:00
parent 51228b2ca1
commit 1e9f672d6c
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
7 changed files with 34 additions and 24 deletions

View file

@ -53,4 +53,12 @@
<value>You have {0} authentication attempts pending. Click here to view them.</value>
<comment>A greeting on the main page of the website.</comment>
</data>
<data name="newest_levels" xml:space="preserve">
<value>Newest Levels</value>
</data>
<data name="latest_team_picks" xml:space="preserve">
<value>Latest Team Picks</value>
</data>
</root>

View file

@ -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)
{

View file

@ -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);

View file

@ -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

View file

@ -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();
}
<h1>Welcome to <b>@ServerConfiguration.Instance.Customization.ServerName</b>!</h1>
<h1>@Model.Translate(LandingPageStrings.Welcome, ServerConfiguration.Instance.Customization.ServerName)</h1>
@if (Model.User != null)
{
<p>You are currently logged in as <b>@Model.User.Username</b>.</p>
if (ServerConfiguration.Instance.Authentication.UseExternalAuth && Model.AuthenticationAttemptsCount > 0)
<p>@Model.Translate(LandingPageStrings.LoggedInAs, Model.User.Username)</p>
if (ServerConfiguration.Instance.Authentication.UseExternalAuth && Model.PendingAuthAttempts > 0)
{
<p>
<b>You have @Model.AuthenticationAttemptsCount authentication attempts pending. Click <a href="/authentication">here</a> to view them.</b>
<b><a href="/authentication">@Model.Translate(LandingPageStrings.AuthAttemptsPending, Model.PendingAuthAttempts)</a></b>
</p>
}
}
@if (Model.PlayersOnlineCount == 1)
{
<p>There is 1 user currently online:</p>
<p>@Model.Translate(LandingPageStrings.UsersSingle)</p>
@foreach (User user in Model.PlayersOnline)
{
<a href="/user/@user.UserId" title="@user.Status.ToString()">@user.Username</a>
@ -34,11 +35,11 @@
else if (Model.PlayersOnlineCount == 0)
{
<p>There are no users online. Why not hop on?</p>
<p>@Model.Translate(LandingPageStrings.UsersNone)</p>
}
else
{
<p>There are currently @Model.PlayersOnlineCount users online:</p>
<p>@Model.Translate(LandingPageStrings.UsersMultiple, Model.PlayersOnlineCount)</p>
@foreach (User user in Model.PlayersOnline)
{
<a href="/user/@user.UserId" title="@user.Status.ToString()">@user.Username</a>
@ -50,7 +51,7 @@ else
<div class="@(isMobile ? "" : "ui center aligned grid")">
<div class="eight wide column">
<div class="ui pink segment">
<h1><i class="ribbon icon"></i>Latest Team Picks</h1>
<h1><i class="ribbon icon"></i>@Model.Translate(LandingPageStrings.LatestTeamPicks)</h1>
<div class="ui divider"></div>
<div class="ui left aligned segment">
@foreach (Slot slot in Model.LatestTeamPicks!) @* Can't reach a point where this is null *@
@ -67,7 +68,7 @@ else
}
<div class="eight wide column">
<div class="ui blue segment">
<h1><i class="certificate icon"></i>Newest Levels</h1>
<h1><i class="certificate icon"></i>@Model.Translate(LandingPageStrings.NewestLevels)</h1>
<div class="ui divider"></div>
<div class="ui left aligned segment">
@foreach (Slot slot in Model.NewestLevels!) @* Can't reach a point where this is null *@

View file

@ -15,7 +15,7 @@ public class LandingPage : BaseLayout
public LandingPage(Database database) : base(database)
{}
public int AuthenticationAttemptsCount;
public int PendingAuthAttempts;
public List<User> 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);

View file

@ -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<IRequestCultureFeature>();
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);
}