Add LanguageSwitcher component
This commit is contained in:
parent
c67e893b6e
commit
c4d1b16abb
|
@ -5,15 +5,15 @@ using System.IO.Compression;
|
|||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.Loader;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Oqtane.Modules;
|
||||
using Oqtane.Providers;
|
||||
using Oqtane.Shared;
|
||||
using Oqtane.Services;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Client
|
||||
{
|
||||
|
@ -62,6 +62,7 @@ namespace Oqtane.Client
|
|||
builder.Services.AddScoped<ISiteTemplateService, SiteTemplateService>();
|
||||
builder.Services.AddScoped<ISqlService, SqlService>();
|
||||
builder.Services.AddScoped<ISystemService, SystemService>();
|
||||
builder.Services.AddScoped<ILocalizationService, LocalizationService>();
|
||||
|
||||
await LoadClientAssemblies(httpClient);
|
||||
|
||||
|
|
|
@ -198,6 +198,8 @@
|
|||
</div>
|
||||
}
|
||||
|
||||
<LanguageSwitcher />
|
||||
|
||||
@if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, PageState.Page.Permissions) || (PageState.Page.IsPersonalizable && PageState.User != null))
|
||||
{
|
||||
if (PageState.EditMode)
|
||||
|
|
30
Oqtane.Client/Themes/Controls/LanguageSwitcher.razor
Normal file
30
Oqtane.Client/Themes/Controls/LanguageSwitcher.razor
Normal file
|
@ -0,0 +1,30 @@
|
|||
@namespace Oqtane.Themes.Controls
|
||||
@inherits ThemeControlBase
|
||||
@using System.Globalization
|
||||
@inject ILocalizationService LocalizationService
|
||||
|
||||
@if (_supportedCultures != null)
|
||||
{
|
||||
<div class="btn-group" role="group">
|
||||
<button id="btnCultures" type="button" class="btn btn-outline-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<span class="oi oi-globe"></span>
|
||||
</button>
|
||||
<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>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@code{
|
||||
private string _selectedCulture;
|
||||
private string[] _supportedCultures;
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
_selectedCulture = await JSRuntime.InvokeAsync<string>("oqtaneCulture.get");
|
||||
_supportedCultures = await LocalizationService.GetSupportedCultures();
|
||||
}
|
||||
}
|
|
@ -48,6 +48,12 @@
|
|||
@if (Configuration.GetSection("Runtime").Value == "WebAssembly")
|
||||
{
|
||||
<script src="_framework/blazor.webassembly.js"></script>
|
||||
<script>
|
||||
window.oqtaneCulture = {
|
||||
get: () => window.localStorage['OqtaneCulture'],
|
||||
set: (value) => window.localStorage['OqtaneCulture'] = value
|
||||
};
|
||||
</script>
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -127,6 +127,7 @@ namespace Oqtane
|
|||
services.AddScoped<ISiteTemplateService, SiteTemplateService>();
|
||||
services.AddScoped<ISqlService, SqlService>();
|
||||
services.AddScoped<ISystemService, SystemService>();
|
||||
services.AddScoped<ILocalizationService, LocalizationService>();
|
||||
|
||||
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user