Introduce Culture model to avoid CultureInfo.DisplayName issue
This commit is contained in:
parent
1b3cc2c44e
commit
a37eb8a44a
|
@ -1,11 +1,13 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Oqtane.Models;
|
||||||
|
|
||||||
namespace Oqtane.Services
|
namespace Oqtane.Services
|
||||||
{
|
{
|
||||||
public interface ILocalizationService
|
public interface ILocalizationService
|
||||||
{
|
{
|
||||||
Task<string> GetDefaultCulture();
|
Task<Culture> GetDefaultCulture();
|
||||||
|
|
||||||
Task<string[]> GetSupportedCultures();
|
Task<IEnumerable<Culture>> GetSupportedCultures();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Oqtane.Models;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
|
|
||||||
namespace Oqtane.Services
|
namespace Oqtane.Services
|
||||||
|
@ -15,8 +17,9 @@ namespace Oqtane.Services
|
||||||
|
|
||||||
private string Apiurl => CreateApiUrl(_siteState.Alias, "Localization");
|
private string Apiurl => CreateApiUrl(_siteState.Alias, "Localization");
|
||||||
|
|
||||||
public async Task<string> GetDefaultCulture() => await GetJsonAsync<string>($"{Apiurl}/getDefaultCulture");
|
public async Task<Culture> GetDefaultCulture() => await GetJsonAsync<Culture>($"{Apiurl}/getDefaultCulture");
|
||||||
|
|
||||||
public async Task<string[]> GetSupportedCultures() => await GetJsonAsync<string[]>($"{Apiurl}/getSupportedCultures");
|
public async Task<IEnumerable<Culture>> GetSupportedCultures()
|
||||||
|
=> await GetJsonAsync<IEnumerable<Culture>>($"{Apiurl}/getSupportedCultures");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
@namespace Oqtane.Themes.Controls
|
@namespace Oqtane.Themes.Controls
|
||||||
@inherits ThemeControlBase
|
@inherits ThemeControlBase
|
||||||
@using System.Globalization
|
@using System.Globalization
|
||||||
|
@using Oqtane.Models
|
||||||
@inject ILocalizationService LocalizationService
|
@inject ILocalizationService LocalizationService
|
||||||
@inject NavigationManager NavigationManager
|
@inject NavigationManager NavigationManager
|
||||||
|
|
||||||
|
@ -13,7 +14,7 @@
|
||||||
<div class="dropdown-menu" aria-labelledby="btnCultures">
|
<div class="dropdown-menu" aria-labelledby="btnCultures">
|
||||||
@foreach (var culture in _supportedCultures)
|
@foreach (var culture in _supportedCultures)
|
||||||
{
|
{
|
||||||
<a class="dropdown-item @(_selectedCulture == culture ? "active" : String.Empty)" href="#" @onclick="@(async e => await SetCultureAsync(culture))">@CultureInfo.GetCultureInfo(culture).DisplayName</a>
|
<a class="dropdown-item @(_selectedCulture == culture.Name ? "active" : String.Empty)" href="#" @onclick="@(async e => await SetCultureAsync(culture.Name))">@culture.DisplayName</a>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -21,7 +22,7 @@
|
||||||
|
|
||||||
@code{
|
@code{
|
||||||
private string _selectedCulture;
|
private string _selectedCulture;
|
||||||
private string[] _supportedCultures;
|
private IEnumerable<Culture> _supportedCultures;
|
||||||
|
|
||||||
protected override async Task OnParametersSetAsync()
|
protected override async Task OnParametersSetAsync()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Oqtane.Infrastructure;
|
using Oqtane.Infrastructure;
|
||||||
|
using Oqtane.Models;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
namespace Oqtane.Controllers
|
||||||
|
@ -17,10 +20,23 @@ namespace Oqtane.Controllers
|
||||||
|
|
||||||
// GET: api/localization/getSupportedCultures
|
// GET: api/localization/getSupportedCultures
|
||||||
[HttpGet("getSupportedCultures")]
|
[HttpGet("getSupportedCultures")]
|
||||||
public IEnumerable<string> GetSupportedCultures() => _localizationManager.GetSupportedCultures();
|
public IEnumerable<Culture> GetSupportedCultures()
|
||||||
|
=> _localizationManager.GetSupportedCultures().Select(c => new Culture {
|
||||||
|
Name = CultureInfo.GetCultureInfo(c).Name,
|
||||||
|
DisplayName = CultureInfo.GetCultureInfo(c).DisplayName
|
||||||
|
});
|
||||||
|
|
||||||
// GET api/localization/getDefaultCulture
|
// GET api/localization/getDefaultCulture
|
||||||
[HttpGet("getDefaultCulture")]
|
[HttpGet("getDefaultCulture")]
|
||||||
public string GetDefaultCulture() => _localizationManager.GetDefaultCulture();
|
public Culture GetDefaultCulture()
|
||||||
|
{
|
||||||
|
var culture = _localizationManager.GetDefaultCulture();
|
||||||
|
|
||||||
|
return new Culture
|
||||||
|
{
|
||||||
|
Name = CultureInfo.GetCultureInfo(culture).Name,
|
||||||
|
DisplayName = CultureInfo.GetCultureInfo(culture).DisplayName
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
9
Oqtane.Shared/Models/Culture.cs
Normal file
9
Oqtane.Shared/Models/Culture.cs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
namespace Oqtane.Models
|
||||||
|
{
|
||||||
|
public class Culture
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public string DisplayName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user