Add LanguageSwitcher component

This commit is contained in:
hishamco 2020-12-02 01:52:46 +03:00
parent c67e893b6e
commit c4d1b16abb
5 changed files with 42 additions and 2 deletions

View File

@ -5,15 +5,15 @@ using System.IO.Compression;
using System.Linq; using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks;
using System.Runtime.Loader; using System.Runtime.Loader;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Oqtane.Modules; using Oqtane.Modules;
using Oqtane.Providers; using Oqtane.Providers;
using Oqtane.Shared;
using Oqtane.Services; using Oqtane.Services;
using Oqtane.Shared;
namespace Oqtane.Client namespace Oqtane.Client
{ {
@ -62,6 +62,7 @@ namespace Oqtane.Client
builder.Services.AddScoped<ISiteTemplateService, SiteTemplateService>(); builder.Services.AddScoped<ISiteTemplateService, SiteTemplateService>();
builder.Services.AddScoped<ISqlService, SqlService>(); builder.Services.AddScoped<ISqlService, SqlService>();
builder.Services.AddScoped<ISystemService, SystemService>(); builder.Services.AddScoped<ISystemService, SystemService>();
builder.Services.AddScoped<ILocalizationService, LocalizationService>();
await LoadClientAssemblies(httpClient); await LoadClientAssemblies(httpClient);

View File

@ -198,6 +198,8 @@
</div> </div>
} }
<LanguageSwitcher />
@if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, PageState.Page.Permissions) || (PageState.Page.IsPersonalizable && PageState.User != null)) @if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, PageState.Page.Permissions) || (PageState.Page.IsPersonalizable && PageState.User != null))
{ {
if (PageState.EditMode) if (PageState.EditMode)

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

View File

@ -48,6 +48,12 @@
@if (Configuration.GetSection("Runtime").Value == "WebAssembly") @if (Configuration.GetSection("Runtime").Value == "WebAssembly")
{ {
<script src="_framework/blazor.webassembly.js"></script> <script src="_framework/blazor.webassembly.js"></script>
<script>
window.oqtaneCulture = {
get: () => window.localStorage['OqtaneCulture'],
set: (value) => window.localStorage['OqtaneCulture'] = value
};
</script>
} }
else else
{ {

View File

@ -127,6 +127,7 @@ namespace Oqtane
services.AddScoped<ISiteTemplateService, SiteTemplateService>(); services.AddScoped<ISiteTemplateService, SiteTemplateService>();
services.AddScoped<ISqlService, SqlService>(); services.AddScoped<ISqlService, SqlService>();
services.AddScoped<ISystemService, SystemService>(); services.AddScoped<ISystemService, SystemService>();
services.AddScoped<ILocalizationService, LocalizationService>();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();