Open Closed

Localize string while no user login #9821


0
MellowoodMedical created

Prerequisites

Please answer the following questions before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.

  • What is your product version? Abp Zero
  • What is your product type (Angular or MVC)? Angular
  • What is product framework type (.net framework or .net core)? .net core

If issue related with ABP Framework

  • What is ABP Framework version? 7.2.0

I am using a app notifier to send push notification to user and I want the user receive the notification in their language base on their setting on the website Since I can't localize the string on the UI Side since it is a web push, so I have to localize the message on the API side. However, the "L()" method do not respect user language in AppNotifier.

Here is code snap of my code inside Core.Notifications.AppNotifier:

public async Task SendReminderAsync(UserIdentifier user,
            string message,
            int txdID,
            NotificationSeverity severity = NotificationSeverity.Warn)
        {
            // Prepare data for in-app notification
            var notificationData = new MessageNotificationData(message);

            // Prepare data for Web Push Notification
            var webPushTitle = L("Reminder");
            var webPushMessage = message;

            notificationData["WebPushNotificationData"] = new WebPushNotificationData(){
                Type = AppNotificationNames.Reminder,
                Title = webPushTitle,
                Options = new Dictionary<string, string>()
                {
                    {"message", webPushMessage},
                    {"userId", user.UserId.ToString()},
                    {"txdID", txdID.ToString()},
                    {"LocalizeTaken", L("Taken")},
                    {"LocalizeDelay", L("Delay15Mins")},
                    {"utcSentTime", DateTime.UtcNow.ToString()+" UTC"}
                }
        };

        // Publish the notification
            await _notificationPublisher.PublishAsync(
                AppNotificationNames.Reminder,
                notificationData,
                userIds: new[] { user });
        }

For now, the L() only translate token to the default language. How I can make the L("") in the code do translation the token base on user Id?


1 Answer(s)