Merge pull request #6007 from sbwalker/dev
add new method for getting neutral cultures
This commit is contained in:
@@ -721,7 +721,7 @@
|
|||||||
if (site != null)
|
if (site != null)
|
||||||
{
|
{
|
||||||
_timezones = TimeZoneService.GetTimeZones();
|
_timezones = TimeZoneService.GetTimeZones();
|
||||||
_cultures = await LocalizationService.GetCulturesAsync(false);
|
_cultures = await LocalizationService.GetNeutralCulturesAsync();
|
||||||
var settings = await SettingService.GetSiteSettingsAsync(site.SiteId);
|
var settings = await SettingService.GetSiteSettingsAsync(site.SiteId);
|
||||||
|
|
||||||
_pages = await PageService.GetPagesAsync(PageState.Site.SiteId);
|
_pages = await PageService.GetPagesAsync(PageState.Site.SiteId);
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Oqtane.Documentation;
|
using Oqtane.Documentation;
|
||||||
@@ -14,10 +13,16 @@ namespace Oqtane.Services
|
|||||||
public interface ILocalizationService
|
public interface ILocalizationService
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a collection of supported cultures
|
/// Returns a collection of supported or installed cultures
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<Culture>> GetCulturesAsync(bool installed);
|
Task<IEnumerable<Culture>> GetCulturesAsync(bool installed);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a collection of neutral cultures
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<Culture>> GetNeutralCulturesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
[PrivateApi("Don't show in the documentation, as everything should use the Interface")]
|
[PrivateApi("Don't show in the documentation, as everything should use the Interface")]
|
||||||
@@ -31,5 +36,10 @@ namespace Oqtane.Services
|
|||||||
{
|
{
|
||||||
return await GetJsonAsync<IEnumerable<Culture>>($"{Apiurl}?installed={installed}");
|
return await GetJsonAsync<IEnumerable<Culture>>($"{Apiurl}?installed={installed}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<Culture>> GetNeutralCulturesAsync()
|
||||||
|
{
|
||||||
|
return await GetJsonAsync<IEnumerable<Culture>>($"{Apiurl}/neutral");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,8 @@ using System.Collections.Generic;
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Oqtane.Extensions;
|
|
||||||
using Oqtane.Infrastructure;
|
using Oqtane.Infrastructure;
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using Oqtane.Repository;
|
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
namespace Oqtane.Controllers
|
||||||
@@ -15,33 +13,27 @@ namespace Oqtane.Controllers
|
|||||||
public class LocalizationController : Controller
|
public class LocalizationController : Controller
|
||||||
{
|
{
|
||||||
private readonly ILocalizationManager _localizationManager;
|
private readonly ILocalizationManager _localizationManager;
|
||||||
private readonly ISiteRepository _siteRepository;
|
|
||||||
private readonly ISiteGroupRepository _siteGroupRepository;
|
|
||||||
private readonly IAliasRepository _aliasRepository;
|
|
||||||
|
|
||||||
public LocalizationController(ILocalizationManager localizationManager, ISiteRepository siteRepository, ISiteGroupRepository siteGroupRepository, IAliasRepository aliasRepository)
|
public LocalizationController(ILocalizationManager localizationManager)
|
||||||
{
|
{
|
||||||
_localizationManager = localizationManager;
|
_localizationManager = localizationManager;
|
||||||
_siteRepository = siteRepository;
|
|
||||||
_siteGroupRepository = siteGroupRepository;
|
|
||||||
_aliasRepository = aliasRepository;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET: api/localization
|
// GET: api/localization?installed=true/false
|
||||||
[HttpGet()]
|
[HttpGet()]
|
||||||
public IEnumerable<Culture> Get(bool installed)
|
public IEnumerable<Culture> Get(bool installed)
|
||||||
{
|
{
|
||||||
string[] culturecodes;
|
string[] cultureCodes;
|
||||||
if (installed)
|
if (installed)
|
||||||
{
|
{
|
||||||
culturecodes = _localizationManager.GetInstalledCultures();
|
cultureCodes = _localizationManager.GetInstalledCultures();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
culturecodes = _localizationManager.GetSupportedCultures();
|
cultureCodes = _localizationManager.GetSupportedCultures();
|
||||||
}
|
}
|
||||||
|
|
||||||
var cultures = culturecodes.Select(c => new Culture
|
var cultures = cultureCodes.Select(c => new Culture
|
||||||
{
|
{
|
||||||
Name = CultureInfo.GetCultureInfo(c).Name,
|
Name = CultureInfo.GetCultureInfo(c).Name,
|
||||||
DisplayName = CultureInfo.GetCultureInfo(c).DisplayName,
|
DisplayName = CultureInfo.GetCultureInfo(c).DisplayName,
|
||||||
@@ -56,5 +48,26 @@ namespace Oqtane.Controllers
|
|||||||
|
|
||||||
return cultures.OrderBy(item => item.DisplayName);
|
return cultures.OrderBy(item => item.DisplayName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GET: api/localization/neutral
|
||||||
|
[HttpGet("neutral")]
|
||||||
|
public IEnumerable<Culture> Get()
|
||||||
|
{
|
||||||
|
var cultureCodes = _localizationManager.GetNeutralCultures();
|
||||||
|
|
||||||
|
var cultures = cultureCodes.Select(c => new Culture
|
||||||
|
{
|
||||||
|
Name = CultureInfo.GetCultureInfo(c).Name,
|
||||||
|
DisplayName = CultureInfo.GetCultureInfo(c).DisplayName,
|
||||||
|
IsDefault = false
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
if (cultures.Count == 0)
|
||||||
|
{
|
||||||
|
cultures.Add(new Culture { Name = "en", DisplayName = "English", IsDefault = false });
|
||||||
|
}
|
||||||
|
|
||||||
|
return cultures.OrderBy(item => item.DisplayName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ namespace Oqtane.Infrastructure
|
|||||||
string GetDefaultCulture();
|
string GetDefaultCulture();
|
||||||
string[] GetSupportedCultures();
|
string[] GetSupportedCultures();
|
||||||
string[] GetInstalledCultures();
|
string[] GetInstalledCultures();
|
||||||
|
string[] GetNeutralCultures();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LocalizationManager : ILocalizationManager
|
public class LocalizationManager : ILocalizationManager
|
||||||
@@ -42,7 +43,6 @@ namespace Oqtane.Infrastructure
|
|||||||
public string[] GetSupportedCultures()
|
public string[] GetSupportedCultures()
|
||||||
{
|
{
|
||||||
return CultureInfo.GetCultures(CultureTypes.AllCultures)
|
return CultureInfo.GetCultures(CultureTypes.AllCultures)
|
||||||
.Where(item => item.Name.Length == 2) // major languages only (this could be configurable)
|
|
||||||
.Select(item => item.Name).OrderBy(c => c).ToArray();
|
.Select(item => item.Name).OrderBy(c => c).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +51,14 @@ namespace Oqtane.Infrastructure
|
|||||||
return GetSatelliteAssemblyCultures();
|
return GetSatelliteAssemblyCultures();
|
||||||
}
|
}
|
||||||
|
|
||||||
// method is static as it is called during startup
|
public string[] GetNeutralCultures()
|
||||||
|
{
|
||||||
|
return CultureInfo.GetCultures(CultureTypes.AllCultures)
|
||||||
|
.Where(item => item.IsNeutralCulture)
|
||||||
|
.Select(item => item.Name).OrderBy(c => c).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
// note: method is public and static as it is called during startup
|
||||||
public static string[] GetSatelliteAssemblyCultures()
|
public static string[] GetSatelliteAssemblyCultures()
|
||||||
{
|
{
|
||||||
var cultures = new List<string>();
|
var cultures = new List<string>();
|
||||||
|
|||||||
Reference in New Issue
Block a user