2024-04-04 16:31:04 +09:00
|
|
|
#nullable enable
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using BTCPayServer.Payments;
|
2024-10-14 21:13:43 +09:00
|
|
|
using Microsoft.Extensions.Localization;
|
2024-04-04 16:31:04 +09:00
|
|
|
|
|
|
|
namespace BTCPayServer.Services
|
|
|
|
{
|
|
|
|
public class PrettyNameProvider
|
|
|
|
{
|
2024-10-14 21:13:43 +09:00
|
|
|
public static string GetTranslationKey(PaymentMethodId paymentMethodId) => $"PrettyName({paymentMethodId})";
|
|
|
|
private readonly IStringLocalizer _stringLocalizer;
|
2024-04-04 16:31:04 +09:00
|
|
|
|
2024-10-14 21:13:43 +09:00
|
|
|
public PrettyNameProvider(IStringLocalizer stringLocalizer)
|
2024-04-04 16:31:04 +09:00
|
|
|
{
|
2024-10-14 21:13:43 +09:00
|
|
|
_stringLocalizer = stringLocalizer;
|
2024-04-04 16:31:04 +09:00
|
|
|
}
|
|
|
|
public string PrettyName(PaymentMethodId paymentMethodId)
|
|
|
|
{
|
|
|
|
if (paymentMethodId is null)
|
|
|
|
return "<NULL>";
|
2024-10-14 21:13:43 +09:00
|
|
|
var key = GetTranslationKey(paymentMethodId);
|
|
|
|
var result = _stringLocalizer[key]?.Value;
|
|
|
|
if (string.IsNullOrEmpty(result) || result == key)
|
|
|
|
return paymentMethodId.ToString();
|
|
|
|
return result;
|
2024-04-04 16:31:04 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|