Added language switcher to footer
This commit is contained in:
parent
d0b5d7bebc
commit
fc45a279de
|
@ -1,5 +1,10 @@
|
|||
@inherits LayoutComponentBase
|
||||
@using System.Globalization
|
||||
@using System.Net
|
||||
@using Microsoft.Extensions.Options
|
||||
@inherits LayoutComponentBase
|
||||
|
||||
@inject NavigationManager Navigation
|
||||
@inject IOptions<RequestLocalizationOptions> LocalizationOptions
|
||||
@inject IStringLocalizer<MainLayout> Localizer
|
||||
|
||||
<div class="drawer md:drawer-open drawer-end">
|
||||
|
@ -19,16 +24,32 @@
|
|||
<main class="flex-1 container mx-auto px-12 py-8">
|
||||
@Body
|
||||
</main>
|
||||
<footer class="flex flex-col md:flex-row items-center justify-center p-4 gap-y-3 bg-base-300 text-base-content">
|
||||
<footer class="flex flex-col md:flex-row items-center justify-center p-4 gap-y-3 gap-x-4 bg-base-300 text-base-content">
|
||||
<span class="flex-1 text-center md:text-left">
|
||||
Powered by
|
||||
<a class="link link-primary" target="_blank" href="https://github.com/miawinter98/Wave">Wave</a>
|
||||
</span>
|
||||
<div class="join w-full md:max-w-64">
|
||||
<button type="button" class="btn btn-secondary btn-sm no-animation join-item">
|
||||
<div class="join w-56">
|
||||
<button type="button" class="btn btn-sm btn-neutral btn-square no-animation join-item">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-6 h-6">
|
||||
<path d="M21.721 12.752a9.711 9.711 0 0 0-.945-5.003 12.754 12.754 0 0 1-4.339 2.708 18.991 18.991 0 0 1-.214 4.772 17.165 17.165 0 0 0 5.498-2.477ZM14.634 15.55a17.324 17.324 0 0 0 .332-4.647c-.952.227-1.945.347-2.966.347-1.021 0-2.014-.12-2.966-.347a17.515 17.515 0 0 0 .332 4.647 17.385 17.385 0 0 0 5.268 0ZM9.772 17.119a18.963 18.963 0 0 0 4.456 0A17.182 17.182 0 0 1 12 21.724a17.18 17.18 0 0 1-2.228-4.605ZM7.777 15.23a18.87 18.87 0 0 1-.214-4.774 12.753 12.753 0 0 1-4.34-2.708 9.711 9.711 0 0 0-.944 5.004 17.165 17.165 0 0 0 5.498 2.477ZM21.356 14.752a9.765 9.765 0 0 1-7.478 6.817 18.64 18.64 0 0 0 1.988-4.718 18.627 18.627 0 0 0 5.49-2.098ZM2.644 14.752c1.682.971 3.53 1.688 5.49 2.099a18.64 18.64 0 0 0 1.988 4.718 9.765 9.765 0 0 1-7.478-6.816ZM13.878 2.43a9.755 9.755 0 0 1 6.116 3.986 11.267 11.267 0 0 1-3.746 2.504 18.63 18.63 0 0 0-2.37-6.49ZM12 2.276a17.152 17.152 0 0 1 2.805 7.121c-.897.23-1.837.353-2.805.353-.968 0-1.908-.122-2.805-.353A17.151 17.151 0 0 1 12 2.276ZM10.122 2.43a18.629 18.629 0 0 0-2.37 6.49 11.266 11.266 0 0 1-3.746-2.504 9.754 9.754 0 0 1 6.116-3.985Z" />
|
||||
</svg>
|
||||
</button>
|
||||
<select class="select select-bordered select-sm md:text-center join-item min-w-0 flex-1"
|
||||
onchange="window.location = `/language/${this.value}?returnUrl=@WebUtility.UrlEncode("/" + Navigation.ToBaseRelativePath(Navigation.Uri))`">
|
||||
@foreach (var culture in LocalizationOptions.Value.SupportedCultures ?? new List<CultureInfo>()) {
|
||||
<option value="@culture"
|
||||
selected="@(CultureInfo.CurrentUICulture.Equals(culture))">
|
||||
@culture.NativeName
|
||||
</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div class="join w-56">
|
||||
<button type="button" class="btn btn-sm btn-neutral no-animation join-item">
|
||||
@Localizer["Theme_Label"]
|
||||
</button>
|
||||
<select data-choose-theme class="select select-bordered select-secondary select-sm join-item flex-1">
|
||||
<select data-choose-theme class="select select-bordered select-sm md:text-center join-item min-w-0 flex-1">
|
||||
<option value="">@Localizer["Theme_Default"]</option>
|
||||
<option value="wave-light">@Localizer["Theme_WaveLight"]</option>
|
||||
<option value="wave-dark">@Localizer["Theme_WaveDark"]</option>
|
||||
|
|
19
Wave/Controllers/LanguageController.cs
Normal file
19
Wave/Controllers/LanguageController.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using Microsoft.AspNetCore.Localization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Wave.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("/language")]
|
||||
public class LanguageController : ControllerBase {
|
||||
[HttpGet("{culture}")]
|
||||
public IActionResult SetLanguage(string culture, string returnUrl = "") {
|
||||
Response.Cookies.Append(
|
||||
CookieRequestCultureProvider.DefaultCookieName,
|
||||
CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(culture)),
|
||||
new CookieOptions { Expires = DateTimeOffset.UtcNow.AddYears(1) }
|
||||
);
|
||||
|
||||
return LocalRedirect(string.IsNullOrWhiteSpace(returnUrl) ? "/" : returnUrl);
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@
|
|||
using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Diagnostics.Metrics;
|
||||
using Microsoft.Extensions.Options;
|
||||
using StackExchange.Redis;
|
||||
|
@ -111,6 +112,17 @@
|
|||
|
||||
#endregion
|
||||
|
||||
|
||||
string[] cultures = ["en-US", "en-GB", "de-DE"];
|
||||
builder.Services.Configure<RequestLocalizationOptions>(options => {
|
||||
options.ApplyCurrentCultureToResponseHeaders = true;
|
||||
options.FallBackToParentCultures = true;
|
||||
options.FallBackToParentUICultures = true;
|
||||
options.SetDefaultCulture(cultures[0])
|
||||
.AddSupportedCultures(cultures)
|
||||
.AddSupportedUICultures(cultures);
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
|
@ -130,14 +142,7 @@
|
|||
|
||||
app.MapControllers();
|
||||
|
||||
string[] cultures = ["en-US", "en-GB", "de-DE"];
|
||||
app.UseRequestLocalization(new RequestLocalizationOptions {
|
||||
ApplyCurrentCultureToResponseHeaders = true,
|
||||
FallBackToParentCultures = true, FallBackToParentUICultures = true
|
||||
}
|
||||
.SetDefaultCulture(cultures[0])
|
||||
.AddSupportedCultures(cultures)
|
||||
.AddSupportedUICultures(cultures));
|
||||
app.UseRequestLocalization();
|
||||
|
||||
{
|
||||
using var scope = app.Services.CreateScope();
|
||||
|
|
2
Wave/wwwroot/css/main.min.css
vendored
2
Wave/wwwroot/css/main.min.css
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue