Thursday, 1 October 2020

How does admin. messaging. AndroidNotification need to be configured for localization?

In the firebase documentation I found that admin. messaging. AndroidNotification has properties to provide localization to your notifications. Or at least that is what I understand from it.

https://firebase.google.com/docs/reference/admin/node/admin.messaging.AndroidNotification

In the docs they have bodyLocArgs and bodyLocKey to localize the body and titleLocArgs and titleLocKey. How do these need to be configured in order to localize my notification?

So let's say my client (the android device) is using en_US as his current language. Is my clients locale used to localize the notification?

This is what my current message

const translator = deviceData.language !== 'nl' ? languages.en : languages.nl;
const title = `${translator['messageTitle' as keyof typeof translator]} ${group.displayName}`;
const body =  `${sender.displayName} ${translator[type as keyof typeof translator]}`;

const systemTrayNotification: TokenMessage = {
    token: deviceData.cloudMessagingToken,
    notification: {
        title: title,
        body: body,
    },
    data: {
        title: title,
        body: body,
        senderId: sender.id,
        senderDisplayName: sender.displayName,
        groupId: group.id,
        type: 'groupMessage',
        messageType: type,
        sentAt: new Date().toISOString(),
    },
    android: {
        priority: 'high',
        notification: {
            priority: 'max',
            channelId: '59054',
            clickAction: 'FLUTTER_NOTIFICATION_CLICK',
            tag: 'groupMessage',
            defaultSound: true,
            defaultVibrateTimings: true,
            bodyLocArgs: //what do I do here?,
            bodyLocKey: //what do I do here?
            titleLocArgs: //what do I do here?,
            titleLocKey: //what do I do here?
        }
    },
    apns: {
        payload: {
            aps: {
                category: 'groupMessage',
                headers:{
                    "apns-priority":"10"
                },
                alert: {
                    title: title,
                    body: body,
                },
                aps: {
                    sound: 'default',
                },
                customData: {
                    title: title,
                    body: body,
                    senderId: sender.id,
                    senderDisplayName: sender.displayName,
                    groupId: group.id,
                    type: 'groupMessage',
                    messageType: type,
                    sentAt: new Date().toISOString(),
                }
            }
        },
    }
}


from How does admin. messaging. AndroidNotification need to be configured for localization?

No comments:

Post a Comment