🐛 Fix sending notification didn't set culture info for localization

This commit is contained in:
LittleSheep 2025-06-05 00:20:54 +08:00
parent a98bfec86f
commit f961469db1
6 changed files with 18 additions and 4 deletions

View File

@ -1,3 +1,4 @@
using System.Globalization;
using DysonNetwork.Sphere.Auth; using DysonNetwork.Sphere.Auth;
using DysonNetwork.Sphere.Storage; using DysonNetwork.Sphere.Storage;
using EFCore.BulkExtensions; using EFCore.BulkExtensions;
@ -14,6 +15,18 @@ public class AccountService(
ICacheService cache ICacheService cache
) )
{ {
public static void SetCultureInfo(Account account)
{
SetCultureInfo(account.Language);
}
public static void SetCultureInfo(string? languageCode)
{
var info = new CultureInfo(languageCode ?? "en-us", false);
CultureInfo.CurrentCulture = info;
CultureInfo.CurrentUICulture = info;
}
public const string AccountCachePrefix = "account:"; public const string AccountCachePrefix = "account:";
public async Task PurgeAccountCache(Account account) public async Task PurgeAccountCache(Account account)

View File

@ -78,10 +78,7 @@ public class MagicSpellService(
.Where(a => a.Id == spell.AccountId) .Where(a => a.Id == spell.AccountId)
.Select(a => a.Language) .Select(a => a.Language)
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
AccountService.SetCultureInfo(accountLanguage);
var cultureInfo = new CultureInfo(accountLanguage ?? "en-us", false);
CultureInfo.CurrentCulture = cultureInfo;
CultureInfo.CurrentUICulture = cultureInfo;
try try
{ {

View File

@ -741,6 +741,7 @@ public class ChatRoomController(
? localizer["ChatInviteDirectBody", sender.Nick] ? localizer["ChatInviteDirectBody", sender.Nick]
: localizer["ChatInviteBody", member.ChatRoom.Name ?? "Unnamed"]; : localizer["ChatInviteBody", member.ChatRoom.Name ?? "Unnamed"];
AccountService.SetCultureInfo(member.Account);
await nty.SendNotification(member.Account, "invites.chats", title, null, body); await nty.SendNotification(member.Account, "invites.chats", title, null, body);
} }
} }

View File

@ -261,6 +261,7 @@ public class PostService(
if (!isSelfReact && op is not null) if (!isSelfReact && op is not null)
{ {
AccountService.SetCultureInfo(op);
await nty.SendNotification( await nty.SendNotification(
op, op,
"posts.reactions.new", "posts.reactions.new",

View File

@ -71,6 +71,7 @@ public class PublisherSubscriptionService(
{ {
try try
{ {
AccountService.SetCultureInfo(subscription.Account);
await nty.SendNotification( await nty.SendNotification(
subscription.Account, subscription.Account,
"posts.new", "posts.new",

View File

@ -9,6 +9,7 @@ public class RealmService(AppDatabase db, NotificationService nty, IStringLocali
{ {
public async Task SendInviteNotify(RealmMember member) public async Task SendInviteNotify(RealmMember member)
{ {
AccountService.SetCultureInfo(member.Account);
await nty.SendNotification( await nty.SendNotification(
member.Account, member.Account,
"invites.realms", "invites.realms",