Use Interop
This commit is contained in:
@ -16,6 +16,7 @@ using Oqtane.Modules;
|
||||
using Oqtane.Providers;
|
||||
using Oqtane.Services;
|
||||
using Oqtane.Shared;
|
||||
using Oqtane.UI;
|
||||
|
||||
namespace Oqtane.Client
|
||||
{
|
||||
@ -92,7 +93,8 @@ namespace Oqtane.Client
|
||||
|
||||
var host = builder.Build();
|
||||
var jsRuntime = host.Services.GetRequiredService<IJSRuntime>();
|
||||
var culture = await jsRuntime.InvokeAsync<string>("oqtaneCulture.get");
|
||||
var interop = new Interop(jsRuntime);
|
||||
var culture = await interop.getCulture();
|
||||
if (culture != null)
|
||||
{
|
||||
var cultureInfo = CultureInfo.GetCultureInfo(culture);
|
||||
|
@ -25,13 +25,15 @@
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
_selectedCulture = _selectedCulture = await JSRuntime.InvokeAsync<string>("oqtaneCulture.get");
|
||||
var interop = new Interop(JSRuntime);
|
||||
_selectedCulture = await interop.getCulture();
|
||||
_supportedCultures = await LocalizationService.GetSupportedCultures();
|
||||
}
|
||||
|
||||
private async Task SetCultureAsync(string culture)
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync("oqtaneCulture.set", culture);
|
||||
var interop = new Interop(JSRuntime);
|
||||
await interop.setCulture(culture);
|
||||
|
||||
NavigationManager.NavigateTo(NavigationManager.Uri, forceLoad: true);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Microsoft.JSInterop;
|
||||
using Microsoft.JSInterop;
|
||||
using Oqtane.Models;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -234,5 +234,32 @@ namespace Oqtane.UI
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<string> getCulture()
|
||||
{
|
||||
try
|
||||
{
|
||||
var culture = await _jsRuntime.InvokeAsync<string>("Oqtane.Interop.getCulture");
|
||||
|
||||
return culture;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Task setCulture(string culture)
|
||||
{
|
||||
try
|
||||
{
|
||||
_jsRuntime.InvokeVoidAsync("Oqtane.Interop.setCulture", culture);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
@page "/"
|
||||
@page "/"
|
||||
@namespace Oqtane.Pages
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
@using System.Globalization
|
||||
@ -48,12 +48,6 @@
|
||||
@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
|
||||
{
|
||||
|
@ -362,5 +362,11 @@ Oqtane.Interop = {
|
||||
setInterval(function () {
|
||||
window.location.href = url;
|
||||
}, wait * 1000);
|
||||
},
|
||||
getCulture: function () {
|
||||
return window.localStorage['OqtaneCulture'];
|
||||
},
|
||||
setCulture: function (culture) {
|
||||
window.localStorage['OqtaneCulture'] = culture;
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user