localize time zone names

This commit is contained in:
sbwalker
2025-07-23 14:52:18 -04:00
parent 190d973b77
commit 962488fd34
8 changed files with 204 additions and 7 deletions

View File

@ -0,0 +1,17 @@
using System.Collections.Generic;
using Oqtane.Models;
namespace Oqtane.Services
{
/// <summary>
/// Service to retrieve <see cref="TimeZone"/> entries
/// </summary>
public interface ITimeZoneService
{
/// <summary>
/// Get the list of time zones
/// </summary>
/// <returns></returns>
List<TimeZone> GetTimeZones();
}
}

View File

@ -0,0 +1,34 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Localization;
using Oqtane.Documentation;
using Oqtane.Models;
using Oqtane.Shared;
namespace Oqtane.Services
{
[PrivateApi("Don't show in the documentation, as everything should use the Interface")]
public class TimeZoneService : ITimeZoneService
{
private readonly IStringLocalizer<TimeZoneResources> _TimeZoneLocalizer;
public TimeZoneService(IStringLocalizer<TimeZoneResources> TimeZoneLocalizer)
{
_TimeZoneLocalizer = TimeZoneLocalizer;
}
public List<TimeZone> GetTimeZones()
{
var _timezones = new List<TimeZone>();
foreach (var timezone in Utilities.GetTimeZones())
{
_timezones.Add(new TimeZone
{
Id = timezone.Id,
DisplayName = _TimeZoneLocalizer[timezone.Id]
});
}
return _timezones.OrderBy(item => item.DisplayName).ToList();
}
}
}