Introduce Culture model to avoid CultureInfo.DisplayName issue

This commit is contained in:
hishamco
2020-12-03 14:05:49 +03:00
parent 1b3cc2c44e
commit a37eb8a44a
5 changed files with 40 additions and 9 deletions

View File

@ -1,6 +1,9 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Oqtane.Infrastructure;
using Oqtane.Models;
using Oqtane.Shared;
namespace Oqtane.Controllers
@ -17,10 +20,23 @@ namespace Oqtane.Controllers
// GET: api/localization/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
[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
};
}
}
}