♻️ Refactored localization service
This commit is contained in:
@@ -29,4 +29,8 @@
|
||||
<ProjectReference Include="..\DysonNetwork.Shared\DysonNetwork.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Resources\Locales\*.json" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -6,7 +6,7 @@ using DysonNetwork.Shared.Proto;
|
||||
using DysonNetwork.Shared.Queue;
|
||||
using DysonNetwork.Shared.Registry;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using DysonNetwork.Shared.Localization;
|
||||
using NATS.Client.Core;
|
||||
using NATS.Net;
|
||||
using NodaTime;
|
||||
@@ -17,7 +17,7 @@ public class PaymentService(
|
||||
AppDatabase db,
|
||||
WalletService wat,
|
||||
RingService.RingServiceClient pusher,
|
||||
IStringLocalizer<NotificationResource> localizer,
|
||||
ILocalizationService localizer,
|
||||
INatsConnection nats
|
||||
)
|
||||
{
|
||||
@@ -189,14 +189,16 @@ public class PaymentService(
|
||||
Notification = new PushNotification
|
||||
{
|
||||
Topic = "wallets.transactions",
|
||||
Title = localizer["TransactionNewTitle", readableTransactionRemark],
|
||||
Title = localizer.Get("transactionNewTitle", args: new { remark = readableTransactionRemark }),
|
||||
Body = transaction.Amount > 0
|
||||
? localizer["TransactionNewBodyMinus",
|
||||
transaction.Amount.ToString(CultureInfo.InvariantCulture),
|
||||
transaction.Currency]
|
||||
: localizer["TransactionNewBodyPlus",
|
||||
transaction.Amount.ToString(CultureInfo.InvariantCulture),
|
||||
transaction.Currency],
|
||||
? localizer.Get("transactionNewBodyMinus", args: new {
|
||||
amount = transaction.Amount.ToString(CultureInfo.InvariantCulture),
|
||||
currency = transaction.Currency
|
||||
})
|
||||
: localizer.Get("transactionNewBodyPlus", args: new {
|
||||
amount = transaction.Amount.ToString(CultureInfo.InvariantCulture),
|
||||
currency = transaction.Currency
|
||||
}),
|
||||
IsSavable = true
|
||||
}
|
||||
}
|
||||
@@ -216,14 +218,16 @@ public class PaymentService(
|
||||
Notification = new PushNotification
|
||||
{
|
||||
Topic = "wallets.transactions",
|
||||
Title = localizer["TransactionNewTitle", readableTransactionRemark],
|
||||
Title = localizer.Get("transactionNewTitle", args: new { remark = readableTransactionRemark }),
|
||||
Body = transaction.Amount > 0
|
||||
? localizer["TransactionNewBodyPlus",
|
||||
transaction.Amount.ToString(CultureInfo.InvariantCulture),
|
||||
transaction.Currency]
|
||||
: localizer["TransactionNewBodyMinus",
|
||||
transaction.Amount.ToString(CultureInfo.InvariantCulture),
|
||||
transaction.Currency],
|
||||
? localizer.Get("transactionNewBodyPlus", args: new {
|
||||
amount = transaction.Amount.ToString(CultureInfo.InvariantCulture),
|
||||
currency = transaction.Currency
|
||||
})
|
||||
: localizer.Get("transactionNewBodyMinus", args: new {
|
||||
amount = transaction.Amount.ToString(CultureInfo.InvariantCulture),
|
||||
currency = transaction.Currency
|
||||
}),
|
||||
IsSavable = true
|
||||
}
|
||||
}
|
||||
@@ -320,10 +324,12 @@ public class PaymentService(
|
||||
Notification = new PushNotification
|
||||
{
|
||||
Topic = "wallets.orders.paid",
|
||||
Title = localizer["OrderPaidTitle", $"#{readableOrderId}"],
|
||||
Body = localizer["OrderPaidBody", order.Amount.ToString(CultureInfo.InvariantCulture),
|
||||
order.Currency,
|
||||
readableOrderRemark],
|
||||
Title = localizer.Get("orderPaidTitle", args: new { orderId = $"#{readableOrderId}" }),
|
||||
Body = localizer.Get("orderPaidBody", args: new {
|
||||
amount = order.Amount.ToString(CultureInfo.InvariantCulture),
|
||||
currency = order.Currency,
|
||||
remark = readableOrderRemark
|
||||
}),
|
||||
IsSavable = true
|
||||
}
|
||||
}
|
||||
@@ -343,10 +349,12 @@ public class PaymentService(
|
||||
Notification = new PushNotification
|
||||
{
|
||||
Topic = "wallets.orders.received",
|
||||
Title = localizer["OrderReceivedTitle", $"#{readableOrderId}"],
|
||||
Body = localizer["OrderReceivedBody", order.Amount.ToString(CultureInfo.InvariantCulture),
|
||||
order.Currency,
|
||||
readableOrderRemark],
|
||||
Title = localizer.Get("orderReceivedTitle", args: new { orderId = $"#{readableOrderId}" }),
|
||||
Body = localizer.Get("orderReceivedBody", args: new {
|
||||
amount = order.Amount.ToString(CultureInfo.InvariantCulture),
|
||||
currency = order.Currency,
|
||||
remark = readableOrderRemark
|
||||
}),
|
||||
IsSavable = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ using DysonNetwork.Shared.Models;
|
||||
using DysonNetwork.Shared.Proto;
|
||||
using DysonNetwork.Shared.Registry;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using DysonNetwork.Shared.Localization;
|
||||
using NodaTime;
|
||||
using Duration = NodaTime.Duration;
|
||||
|
||||
@@ -19,7 +19,7 @@ public class SubscriptionService(
|
||||
PaymentService payment,
|
||||
AccountService.AccountServiceClient accounts,
|
||||
RingService.RingServiceClient pusher,
|
||||
IStringLocalizer<NotificationResource> localizer,
|
||||
ILocalizationService localizer,
|
||||
IConfiguration configuration,
|
||||
ICacheService cache,
|
||||
ILogger<SubscriptionService> logger
|
||||
@@ -423,8 +423,8 @@ public class SubscriptionService(
|
||||
var notification = new PushNotification
|
||||
{
|
||||
Topic = "subscriptions.begun",
|
||||
Title = localizer["SubscriptionAppliedTitle", humanReadableName],
|
||||
Body = localizer["SubscriptionAppliedBody", duration, humanReadableName],
|
||||
Title = localizer.Get("subscriptionAppliedTitle", args: new { subscriptionName = humanReadableName }),
|
||||
Body = localizer.Get("subscriptionAppliedBody", args: new { duration, subscriptionName = humanReadableName }),
|
||||
Meta = GrpcTypeHelper.ConvertObjectToByteString(new Dictionary<string, object>
|
||||
{
|
||||
["subscription_id"] = subscription.Id.ToString()
|
||||
@@ -920,8 +920,8 @@ public class SubscriptionService(
|
||||
var notification = new PushNotification
|
||||
{
|
||||
Topic = "gifts.claimed",
|
||||
Title = localizer["GiftClaimedTitle"],
|
||||
Body = localizer["GiftClaimedBody", humanReadableName, redeemer.Name],
|
||||
Title = localizer.Get("giftClaimedTitle"),
|
||||
Body = localizer.Get("giftClaimedBody", args: new { subscriptionName = humanReadableName, redeemerName = redeemer.Name }),
|
||||
Meta = GrpcTypeHelper.ConvertObjectToByteString(new Dictionary<string, object>
|
||||
{
|
||||
["gift_id"] = gift.Id.ToString(),
|
||||
|
||||
13
DysonNetwork.Wallet/Resources/Locales/en.json
Normal file
13
DysonNetwork.Wallet/Resources/Locales/en.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"transactionNewTitle": "New Transaction",
|
||||
"transactionNewBodyMinus": "You spent {amount} {currency}",
|
||||
"transactionNewBodyPlus": "You received {amount} {currency}",
|
||||
"orderPaidTitle": "Order Paid",
|
||||
"orderPaidBody": "Paid {amount} {currency} for {remark}",
|
||||
"orderReceivedTitle": "Order Received",
|
||||
"orderReceivedBody": "Received {amount} {currency} for {remark}",
|
||||
"subscriptionAppliedTitle": "Subscription Applied",
|
||||
"subscriptionAppliedBody": "Your subscription for {duration} days of {subscription} has been applied",
|
||||
"giftClaimedTitle": "Gift Claimed",
|
||||
"giftClaimedBody": "Your gift of {subscription} has been claimed by {user}"
|
||||
}
|
||||
13
DysonNetwork.Wallet/Resources/Locales/zh-hans.json
Normal file
13
DysonNetwork.Wallet/Resources/Locales/zh-hans.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"transactionNewTitle": "新交易",
|
||||
"transactionNewBodyMinus": "您花费了 {amount} {currency}",
|
||||
"transactionNewBodyPlus": "您收到了 {amount} {currency}",
|
||||
"orderPaidTitle": "订单已支付",
|
||||
"orderPaidBody": "支付了 {amount} {currency} 用于 {remark}",
|
||||
"orderReceivedTitle": "订单已接收",
|
||||
"orderReceivedBody": "收到了 {amount} {currency} 用于 {remark}",
|
||||
"subscriptionAppliedTitle": "订阅已应用",
|
||||
"subscriptionAppliedBody": "您的 {duration} 天 {subscription} 订阅已应用",
|
||||
"giftClaimedTitle": "礼物已领取",
|
||||
"giftClaimedBody": "您的 {subscription} 礼物已被 {user} 领取"
|
||||
}
|
||||
Reference in New Issue
Block a user