mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 01:43:50 +01:00
Do not translate checkout with the backend language
This commit is contained in:
parent
3dfdbf544a
commit
74011e50e3
@ -856,7 +856,7 @@ namespace BTCPayServer.Controllers
|
||||
var model = new CheckoutModel
|
||||
{
|
||||
Activated = prompt.Activated,
|
||||
PaymentMethodName = _prettyName.PrettyName(paymentMethodId),
|
||||
PaymentMethodName = _prettyName.PrettyName(paymentMethodId, true),
|
||||
PaymentMethodCurrency = prompt.Currency,
|
||||
RootPath = Request.PathBase.Value.WithTrailingSlash(),
|
||||
OrderId = orderId,
|
||||
@ -908,7 +908,7 @@ namespace BTCPayServer.Controllers
|
||||
{
|
||||
Displayed = displayedPaymentMethods.Contains(kv.PaymentMethodId),
|
||||
PaymentMethodId = kv.PaymentMethodId,
|
||||
PaymentMethodName = _prettyName.PrettyName(kv.PaymentMethodId),
|
||||
PaymentMethodName = _prettyName.PrettyName(kv.PaymentMethodId, true),
|
||||
Order = kv.PaymentMethodId switch
|
||||
{
|
||||
_ when PaymentTypes.CHAIN.GetPaymentMethodId(_NetworkProvider.DefaultNetwork.CryptoCode) == kv.PaymentMethodId => 0,
|
||||
|
@ -299,6 +299,7 @@ namespace BTCPayServer
|
||||
}
|
||||
public static IServiceCollection AddDefaultPrettyName(this IServiceCollection services, PaymentMethodId paymentMethodId, string defaultPrettyName)
|
||||
{
|
||||
services.AddSingleton<PrettyNameProvider.UntranslatedPrettyName>(new PrettyNameProvider.UntranslatedPrettyName(paymentMethodId, defaultPrettyName));
|
||||
return services.AddDefaultTranslations(KeyValuePair.Create<string, string?>(PrettyNameProvider.GetTranslationKey(paymentMethodId), defaultPrettyName));
|
||||
}
|
||||
public static IServiceCollection AddDefaultTranslations(this IServiceCollection services, params KeyValuePair<string, string?>[] keyValues)
|
||||
|
@ -7,17 +7,28 @@ namespace BTCPayServer.Services
|
||||
{
|
||||
public class PrettyNameProvider
|
||||
{
|
||||
public record UntranslatedPrettyName(PaymentMethodId PaymentMethodId, string Text);
|
||||
public static string GetTranslationKey(PaymentMethodId paymentMethodId) => $"PrettyName({paymentMethodId})";
|
||||
private readonly IStringLocalizer _stringLocalizer;
|
||||
|
||||
public PrettyNameProvider(IStringLocalizer stringLocalizer)
|
||||
Dictionary<PaymentMethodId, string> _untranslated = new Dictionary<PaymentMethodId, string>();
|
||||
public PrettyNameProvider(IEnumerable<UntranslatedPrettyName> untranslatedPrettyNames, IStringLocalizer stringLocalizer)
|
||||
{
|
||||
_stringLocalizer = stringLocalizer;
|
||||
foreach (var e in untranslatedPrettyNames)
|
||||
_untranslated.TryAdd(e.PaymentMethodId, e.Text);
|
||||
}
|
||||
public string PrettyName(PaymentMethodId paymentMethodId)
|
||||
public string PrettyName(PaymentMethodId paymentMethodId, bool untranslated)
|
||||
{
|
||||
if (paymentMethodId is null)
|
||||
return "<NULL>";
|
||||
if (untranslated)
|
||||
{
|
||||
if (_untranslated.TryGetValue(paymentMethodId, out var v))
|
||||
return v;
|
||||
return paymentMethodId.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
var key = GetTranslationKey(paymentMethodId);
|
||||
var result = _stringLocalizer[key]?.Value;
|
||||
if (string.IsNullOrEmpty(result) || result == key)
|
||||
@ -25,4 +36,6 @@ namespace BTCPayServer.Services
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public string PrettyName(PaymentMethodId paymentMethodId) => PrettyName(paymentMethodId, false);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user