add new method for getting neutral cultures
This commit is contained in:
@@ -3,10 +3,8 @@ using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Oqtane.Extensions;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Repository;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
@@ -15,33 +13,27 @@ namespace Oqtane.Controllers
|
||||
public class LocalizationController : Controller
|
||||
{
|
||||
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;
|
||||
_siteRepository = siteRepository;
|
||||
_siteGroupRepository = siteGroupRepository;
|
||||
_aliasRepository = aliasRepository;
|
||||
}
|
||||
|
||||
// GET: api/localization
|
||||
// GET: api/localization?installed=true/false
|
||||
[HttpGet()]
|
||||
public IEnumerable<Culture> Get(bool installed)
|
||||
{
|
||||
string[] culturecodes;
|
||||
string[] cultureCodes;
|
||||
if (installed)
|
||||
{
|
||||
culturecodes = _localizationManager.GetInstalledCultures();
|
||||
cultureCodes = _localizationManager.GetInstalledCultures();
|
||||
}
|
||||
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,
|
||||
DisplayName = CultureInfo.GetCultureInfo(c).DisplayName,
|
||||
@@ -56,5 +48,26 @@ namespace Oqtane.Controllers
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user