From c4d1b16abb16f713a950d37325e4d14bcc68edd1 Mon Sep 17 00:00:00 2001 From: hishamco Date: Wed, 2 Dec 2020 01:52:46 +0300 Subject: [PATCH] Add LanguageSwitcher component --- Oqtane.Client/Program.cs | 5 ++-- .../Themes/Controls/ControlPanel.razor | 2 ++ .../Themes/Controls/LanguageSwitcher.razor | 30 +++++++++++++++++++ Oqtane.Server/Pages/_Host.cshtml | 6 ++++ Oqtane.Server/Startup.cs | 1 + 5 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 Oqtane.Client/Themes/Controls/LanguageSwitcher.razor diff --git a/Oqtane.Client/Program.cs b/Oqtane.Client/Program.cs index af283cec..7fdfa6bd 100644 --- a/Oqtane.Client/Program.cs +++ b/Oqtane.Client/Program.cs @@ -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(); builder.Services.AddScoped(); builder.Services.AddScoped(); + builder.Services.AddScoped(); await LoadClientAssemblies(httpClient); diff --git a/Oqtane.Client/Themes/Controls/ControlPanel.razor b/Oqtane.Client/Themes/Controls/ControlPanel.razor index 02ae862c..0ea20a8a 100644 --- a/Oqtane.Client/Themes/Controls/ControlPanel.razor +++ b/Oqtane.Client/Themes/Controls/ControlPanel.razor @@ -198,6 +198,8 @@ } + + @if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, PageState.Page.Permissions) || (PageState.Page.IsPersonalizable && PageState.User != null)) { if (PageState.EditMode) diff --git a/Oqtane.Client/Themes/Controls/LanguageSwitcher.razor b/Oqtane.Client/Themes/Controls/LanguageSwitcher.razor new file mode 100644 index 00000000..3b630a7a --- /dev/null +++ b/Oqtane.Client/Themes/Controls/LanguageSwitcher.razor @@ -0,0 +1,30 @@ +@namespace Oqtane.Themes.Controls +@inherits ThemeControlBase +@using System.Globalization +@inject ILocalizationService LocalizationService + +@if (_supportedCultures != null) +{ +
+ + +
+} + +@code{ + private string _selectedCulture; + private string[] _supportedCultures; + + protected override async Task OnParametersSetAsync() + { + _selectedCulture = await JSRuntime.InvokeAsync("oqtaneCulture.get"); + _supportedCultures = await LocalizationService.GetSupportedCultures(); + } +} diff --git a/Oqtane.Server/Pages/_Host.cshtml b/Oqtane.Server/Pages/_Host.cshtml index 2aa0dd9d..92dea6bc 100644 --- a/Oqtane.Server/Pages/_Host.cshtml +++ b/Oqtane.Server/Pages/_Host.cshtml @@ -48,6 +48,12 @@ @if (Configuration.GetSection("Runtime").Value == "WebAssembly") { + } else { diff --git a/Oqtane.Server/Startup.cs b/Oqtane.Server/Startup.cs index b008ee30..b134a19e 100644 --- a/Oqtane.Server/Startup.cs +++ b/Oqtane.Server/Startup.cs @@ -127,6 +127,7 @@ namespace Oqtane services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); services.AddSingleton();