60 lines
2 KiB
C#
60 lines
2 KiB
C#
|
|
using System;
|
|||
|
|
using System.Globalization;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using Volo.Abp.DependencyInjection;
|
|||
|
|
using Volo.Abp.Settings;
|
|||
|
|
using Volo.Abp.Timing;
|
|||
|
|
using Volo.Abp.MultiTenancy;
|
|||
|
|
using Microsoft.Extensions.Options;
|
|||
|
|
|
|||
|
|
namespace Kurs.Platform.Localization
|
|||
|
|
{
|
|||
|
|
public class TenantLocalizationInitializer : ITransientDependency
|
|||
|
|
{
|
|||
|
|
private readonly ISettingProvider _settingProvider;
|
|||
|
|
private readonly ICurrentTenant _currentTenant;
|
|||
|
|
private readonly IOptions<AbpClockOptions> _clockOptions;
|
|||
|
|
|
|||
|
|
public TenantLocalizationInitializer(
|
|||
|
|
ISettingProvider settingProvider,
|
|||
|
|
ICurrentTenant currentTenant,
|
|||
|
|
IOptions<AbpClockOptions> clockOptions)
|
|||
|
|
{
|
|||
|
|
_settingProvider = settingProvider;
|
|||
|
|
_currentTenant = currentTenant;
|
|||
|
|
_clockOptions = clockOptions;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public async Task ApplyTenantSettingsAsync()
|
|||
|
|
{
|
|||
|
|
// Dil ayarı
|
|||
|
|
var lang = await _settingProvider.GetOrNullAsync("Abp.Localization.DefaultLanguage") ?? "en";
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var culture = new CultureInfo(lang);
|
|||
|
|
CultureInfo.DefaultThreadCurrentCulture = culture;
|
|||
|
|
CultureInfo.DefaultThreadCurrentUICulture = culture;
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
|
|||
|
|
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Saat tipi (UTC / Local)
|
|||
|
|
var timeZoneId = await _settingProvider.GetOrNullAsync("Abp.Timing.TimeZone") ?? "UTC";
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var tz = TimeZoneInfo.FindSystemTimeZoneById(timeZoneId);
|
|||
|
|
_clockOptions.Value.Kind = tz.Id.Contains("UTC", StringComparison.OrdinalIgnoreCase)
|
|||
|
|
? DateTimeKind.Utc
|
|||
|
|
: DateTimeKind.Local;
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
_clockOptions.Value.Kind = DateTimeKind.Utc;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|