Ability to change culture
This commit is contained in:
parent
c4d1b16abb
commit
75556070d6
|
@ -17,6 +17,7 @@
|
|||
<PackageReleaseNotes>https://github.com/oqtane/oqtane.framework/releases/tag/v2.0.0</PackageReleaseNotes>
|
||||
<RootNamespace>Oqtane</RootNamespace>
|
||||
<IsPackable>true</IsPackable>
|
||||
<BlazorWebAssemblyLoadAllGlobalizationData>true</BlazorWebAssemblyLoadAllGlobalizationData>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
|
@ -10,6 +11,7 @@ using System.Threading.Tasks;
|
|||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.JSInterop;
|
||||
using Oqtane.Modules;
|
||||
using Oqtane.Providers;
|
||||
using Oqtane.Services;
|
||||
|
@ -89,6 +91,14 @@ namespace Oqtane.Client
|
|||
}
|
||||
|
||||
var host = builder.Build();
|
||||
var jsRuntime = host.Services.GetRequiredService<IJSRuntime>();
|
||||
var culture = await jsRuntime.InvokeAsync<string>("oqtaneCulture.get");
|
||||
if (culture != null)
|
||||
{
|
||||
var cultureInfo = CultureInfo.GetCultureInfo(culture);
|
||||
CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
|
||||
CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
|
||||
}
|
||||
|
||||
ServiceActivator.Configure(host.Services);
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
@inherits ThemeControlBase
|
||||
@using System.Globalization
|
||||
@inject ILocalizationService LocalizationService
|
||||
@inject NavigationManager NavigationManager
|
||||
|
||||
@if (_supportedCultures != null)
|
||||
{
|
||||
|
@ -12,7 +13,7 @@
|
|||
<div class="dropdown-menu" aria-labelledby="btnCultures">
|
||||
@foreach (var culture in _supportedCultures)
|
||||
{
|
||||
<a class="dropdown-item @(_selectedCulture == culture ? "active" : String.Empty)" href="#">@CultureInfo.GetCultureInfo(culture).DisplayName</a>
|
||||
<a class="dropdown-item @(_selectedCulture == culture ? "active" : String.Empty)" href="#" @onclick="@(async () => await SetCultureAsync(culture))">@CultureInfo.GetCultureInfo(culture).DisplayName</a>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -24,7 +25,14 @@
|
|||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
_selectedCulture = await JSRuntime.InvokeAsync<string>("oqtaneCulture.get");
|
||||
_selectedCulture = _selectedCulture = await JSRuntime.InvokeAsync<string>("oqtaneCulture.get");
|
||||
_supportedCultures = await LocalizationService.GetSupportedCultures();
|
||||
}
|
||||
|
||||
private async Task SetCultureAsync(string culture)
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync("oqtaneCulture.set", culture);
|
||||
|
||||
NavigationManager.NavigateTo(NavigationManager.Uri, forceLoad: true);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user