♻️ Refactored localization service

This commit is contained in:
2026-02-04 23:59:41 +08:00
parent c1669286f4
commit 9b6a62ec66
30 changed files with 530 additions and 369 deletions

View File

@@ -5,7 +5,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 NodaTime;
using NodaTime.Extensions;
@@ -15,7 +15,7 @@ namespace DysonNetwork.Pass.Account;
public class AccountEventService(
AppDatabase db,
ICacheService cache,
IStringLocalizer<Localization.AccountEventResource> localizer,
ILocalizationService localizer,
RingService.RingServiceClient pusher,
Pass.Leveling.ExperienceService experienceService,
RemotePaymentService payment,
@@ -359,8 +359,8 @@ public class AccountEventService(
new CheckInFortuneTip
{
IsPositive = true,
Title = localizer["FortuneTipSpecialTitle_Birthday"].Value,
Content = localizer["FortuneTipSpecialContent_Birthday", user.Nick].Value,
Title = localizer.Get("fortuneTipSpecialTitleBirthday"),
Content = localizer.Get("fortuneTipSpecialContentBirthday", args: new { user.Nick }),
}
];
}
@@ -374,8 +374,8 @@ public class AccountEventService(
tips = positiveIndices.Select(index => new CheckInFortuneTip
{
IsPositive = true,
Title = localizer[$"FortuneTipPositiveTitle_{index}"].Value,
Content = localizer[$"FortuneTipPositiveContent_{index}"].Value
Title = localizer.Get($"fortuneTipPositiveTitle{index}"),
Content = localizer.Get($"fortuneTipPositiveContent{index}")
}).ToList();
// Generate 2 negative tips
@@ -387,8 +387,8 @@ public class AccountEventService(
tips.AddRange(negativeIndices.Select(index => new CheckInFortuneTip
{
IsPositive = false,
Title = localizer[$"FortuneTipNegativeTitle_{index}"].Value,
Content = localizer[$"FortuneTipNegativeContent_{index}"].Value
Title = localizer.Get($"fortuneTipNegativeTitle{index}"),
Content = localizer.Get($"fortuneTipNegativeContent{index}")
}));
// The 5 is specialized, keep it alone.

View File

@@ -6,11 +6,11 @@ using DysonNetwork.Pass.Mailer;
using DysonNetwork.Pass.Resources.Emails;
using DysonNetwork.Shared.Cache;
using DysonNetwork.Shared.Data;
using DysonNetwork.Shared.Localization;
using DysonNetwork.Shared.Models;
using DysonNetwork.Shared.Proto;
using DysonNetwork.Shared.Queue;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
using NATS.Client.Core;
using NATS.Net;
using NodaTime;
@@ -28,8 +28,7 @@ public class AccountService(
AffiliationSpellService ars,
EmailService mailer,
RingService.RingServiceClient pusher,
IStringLocalizer<NotificationResource> localizer,
IStringLocalizer<EmailResource> emailLocalizer,
ILocalizationService localizer,
ICacheService cache,
ILogger<AccountService> logger,
RemoteSubscriptionService remoteSubscription,
@@ -434,8 +433,8 @@ public class AccountService(
Notification = new PushNotification
{
Topic = "auth.verification",
Title = localizer["AuthCodeTitle"],
Body = localizer["AuthCodeBody", code],
Title = localizer.Get("authCodeTitle"),
Body = localizer.Get("authCodeBody", args: new { code }),
IsSavable = false
}
}
@@ -466,7 +465,7 @@ public class AccountService(
.SendTemplatedEmailAsync<FactorCodeEmail, VerificationEmailModel>(
account.Nick,
contact.Content,
emailLocalizer["CodeEmailTitle"],
localizer.Get("codeEmailTitle"),
new VerificationEmailModel
{
Name = account.Name,

View File

@@ -5,7 +5,7 @@ using DysonNetwork.Pass.Resources.Emails;
using DysonNetwork.Shared.Cache;
using DysonNetwork.Shared.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
using DysonNetwork.Shared.Localization;
using NodaTime;
using EmailResource = DysonNetwork.Pass.Localization.EmailResource;
@@ -15,7 +15,7 @@ public class MagicSpellService(
AppDatabase db,
IConfiguration configuration,
ILogger<MagicSpellService> logger,
IStringLocalizer<EmailResource> localizer,
ILocalizationService localizer,
EmailService email,
ICacheService cache
)
@@ -98,7 +98,7 @@ public class MagicSpellService(
await email.SendTemplatedEmailAsync<RegistrationConfirmEmail, LandingEmailModel>(
contact.Account.Nick,
contact.Content,
localizer["RegConfirmTitle"],
localizer.Get("regConfirmTitle"),
new LandingEmailModel
{
Name = contact.Account.Name,
@@ -110,7 +110,7 @@ public class MagicSpellService(
await email.SendTemplatedEmailAsync<AccountDeletionEmail, AccountDeletionEmailModel>(
contact.Account.Nick,
contact.Content,
localizer["AccountDeletionTitle"],
localizer.Get("accountDeletionTitle"),
new AccountDeletionEmailModel
{
Name = contact.Account.Name,
@@ -122,7 +122,7 @@ public class MagicSpellService(
await email.SendTemplatedEmailAsync<PasswordResetEmail, PasswordResetEmailModel>(
contact.Account.Nick,
contact.Content,
localizer["PasswordResetTitle"],
localizer.Get("passwordResetTitle"),
new PasswordResetEmailModel
{
Name = contact.Account.Name,
@@ -136,7 +136,7 @@ public class MagicSpellService(
await email.SendTemplatedEmailAsync<ContactVerificationEmail, ContactVerificationEmailModel>(
contact.Account.Nick,
contactMethod!,
localizer["ContractVerificationTitle"],
localizer.Get("contractVerificationTitle"),
new ContactVerificationEmailModel
{
Name = contact.Account.Name,

View File

@@ -3,7 +3,7 @@ using DysonNetwork.Shared.Cache;
using DysonNetwork.Shared.Models;
using DysonNetwork.Shared.Proto;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
using DysonNetwork.Shared.Localization;
using NodaTime;
namespace DysonNetwork.Pass.Account;
@@ -12,7 +12,7 @@ public class RelationshipService(
AppDatabase db,
ICacheService cache,
RingService.RingServiceClient pusher,
IStringLocalizer<NotificationResource> localizer
ILocalizationService localizer
)
{
private const string UserFriendsCacheKeyPrefix = "accounts:friends:";
@@ -117,8 +117,8 @@ public class RelationshipService(
Notification = new PushNotification
{
Topic = "relationships.friends.request",
Title = localizer["FriendRequestTitle", sender.Nick],
Body = localizer["FriendRequestBody"],
Title = localizer.Get("friendRequestTitle", args: new { sender.Nick }),
Body = localizer.Get("friendRequestBody"),
ActionUri = "/account/relationships",
IsSavable = true
}