Add translations to the Dashboard

This commit is contained in:
nicolas.dorier
2024-10-14 14:11:00 +09:00
parent 73a9835a27
commit c35af2dc69
31 changed files with 331 additions and 153 deletions

View File

@@ -18,8 +18,10 @@ using BTCPayServer.Services;
using BTCPayServer.Services.Rates;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
using Newtonsoft.Json.Linq;
using MarkPayoutRequest = BTCPayServer.HostedServices.MarkPayoutRequest;
using PayoutData = BTCPayServer.Data.PayoutData;
@@ -50,7 +52,10 @@ namespace BTCPayServer.Controllers
}
}
public IStringLocalizer StringLocalizer { get; }
public UIStorePullPaymentsController(BTCPayNetworkProvider btcPayNetworkProvider,
IStringLocalizer stringLocalizer,
PayoutMethodHandlerDictionary payoutHandlers,
CurrencyNameTable currencyNameTable,
DisplayFormatter displayFormatter,
@@ -62,6 +67,7 @@ namespace BTCPayServer.Controllers
IAuthorizationService authorizationService)
{
_btcPayNetworkProvider = btcPayNetworkProvider;
StringLocalizer = stringLocalizer;
_payoutHandlers = payoutHandlers;
_currencyNameTable = currencyNameTable;
_displayFormatter = displayFormatter;
@@ -85,7 +91,7 @@ namespace BTCPayServer.Controllers
{
TempData.SetStatusMessageModel(new StatusMessageModel
{
Message = "You must enable at least one payment method before creating a pull payment.",
Message = StringLocalizer["You must enable at least one payment method before creating a pull payment."],
Severity = StatusMessageModel.StatusSeverity.Error
});
return RedirectToAction(nameof(UIStoresController.Index), "UIStores", new { storeId });
@@ -119,25 +125,25 @@ namespace BTCPayServer.Controllers
// them here to reflect user's selection so that they can correct their mistake
model.PayoutMethodsItem =
paymentMethodOptions.Select(id => new SelectListItem(id.ToString(), id.ToString(), false));
ModelState.AddModelError(nameof(model.PayoutMethods), "You need at least one payout method");
ModelState.AddModelError(nameof(model.PayoutMethods), StringLocalizer["You need at least one payout method"]);
}
if (_currencyNameTable.GetCurrencyData(model.Currency, false) is null)
{
ModelState.AddModelError(nameof(model.Currency), "Invalid currency");
ModelState.AddModelError(nameof(model.Currency), StringLocalizer["Invalid currency"]);
}
if (model.Amount <= 0.0m)
{
ModelState.AddModelError(nameof(model.Amount), "The amount should be more than zero");
ModelState.AddModelError(nameof(model.Amount), StringLocalizer["The amount should be more than zero"]);
}
if (model.Name.Length > 50)
{
ModelState.AddModelError(nameof(model.Name), "The name should be maximum 50 characters.");
ModelState.AddModelError(nameof(model.Name), StringLocalizer["The name should be maximum 50 characters."]);
}
var selectedPaymentMethodIds = model.PayoutMethods.Select(PayoutMethodId.Parse).ToArray();
if (!selectedPaymentMethodIds.All(id => paymentMethodOptions.Contains(id)))
{
ModelState.AddModelError(nameof(model.Name), "Not all payout methods are supported");
ModelState.AddModelError(nameof(model.Name), StringLocalizer["Not all payout methods are supported"]);
}
if (!ModelState.IsValid)
return View(model);
@@ -156,7 +162,7 @@ namespace BTCPayServer.Controllers
});
TempData.SetStatusMessageModel(new StatusMessageModel
{
Message = "Pull payment request created",
Message = StringLocalizer["Pull payment request created"],
Severity = StatusMessageModel.StatusSeverity.Success
});
return RedirectToAction(nameof(PullPayments), new { storeId });
@@ -198,7 +204,7 @@ namespace BTCPayServer.Controllers
{
TempData.SetStatusMessageModel(new StatusMessageModel
{
Message = "You must enable at least one payment method before creating a pull payment.",
Message = StringLocalizer["You must enable at least one payment method before creating a pull payment."],
Severity = StatusMessageModel.StatusSeverity.Error
});
return RedirectToAction(nameof(UIStoresController.Index), "UIStores", new { storeId });
@@ -260,7 +266,7 @@ namespace BTCPayServer.Controllers
string pullPaymentId)
{
return View("Confirm",
new ConfirmModel("Archive pull payment", "Do you really want to archive the pull payment?", "Archive"));
new ConfirmModel(StringLocalizer["Archive pull payment"], StringLocalizer["Do you really want to archive the pull payment?"], "Archive"));
}
[HttpPost("stores/{storeId}/pull-payments/{pullPaymentId}/archive")]
@@ -298,7 +304,7 @@ namespace BTCPayServer.Controllers
{
TempData.SetStatusMessageModel(new StatusMessageModel()
{
Message = "No payout selected",
Message = StringLocalizer["No payout selected"],
Severity = StatusMessageModel.StatusSeverity.Error
});
return RedirectToAction(nameof(Payouts),
@@ -341,7 +347,7 @@ namespace BTCPayServer.Controllers
{
this.TempData.SetStatusMessageModel(new StatusMessageModel()
{
Message = $"Rate unavailable: {rateResult.EvaluatedRule}",
Message = StringLocalizer["Rate unavailable: {0}", rateResult.EvaluatedRule],
Severity = StatusMessageModel.StatusSeverity.Error
});
failed = true;
@@ -379,7 +385,7 @@ namespace BTCPayServer.Controllers
TempData.SetStatusMessageModel(new StatusMessageModel()
{
Message = "Payouts approved",
Message = StringLocalizer["Payouts approved"],
Severity = StatusMessageModel.StatusSeverity.Success
});
break;
@@ -391,7 +397,7 @@ namespace BTCPayServer.Controllers
return await handler.InitiatePayment(payoutIds);
TempData.SetStatusMessageModel(new StatusMessageModel()
{
Message = "Paying via this payment method is not supported",
Message = StringLocalizer["Paying via this payment method is not supported"],
Severity = StatusMessageModel.StatusSeverity.Error
});
break;
@@ -430,7 +436,7 @@ namespace BTCPayServer.Controllers
TempData.SetStatusMessageModel(new StatusMessageModel()
{
Message = "Payouts marked as paid",
Message = StringLocalizer["Payouts marked as paid"],
Severity = StatusMessageModel.StatusSeverity.Success
});
break;
@@ -441,7 +447,7 @@ namespace BTCPayServer.Controllers
new PullPaymentHostedService.CancelRequest(payoutIds, new[] { storeId }));
TempData.SetStatusMessageModel(new StatusMessageModel()
{
Message = "Payouts archived",
Message = StringLocalizer["Payouts archived"],
Severity = StatusMessageModel.StatusSeverity.Success
});
break;
@@ -482,7 +488,7 @@ namespace BTCPayServer.Controllers
{
TempData.SetStatusMessageModel(new StatusMessageModel
{
Message = "You must enable at least one payment method before creating a payout.",
Message = StringLocalizer["You must enable at least one payment method before creating a payout."],
Severity = StatusMessageModel.StatusSeverity.Error
});
return RedirectToAction(nameof(UIStoresController.Index), "UIStores", new { storeId });