erp-platform/api/src/Kurs.Platform.HttpApi.Host/TenantLocalizationInitializer.cs
2025-10-25 00:53:53 +03:00

59 lines
2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
}
}
}
}