How to translate Firebase Push Notifications?
There are two approaches to this.
Send localized content
You might be able to keep track of the user's locale on the server side (inside Cloud Firestore for example) and just choose the right translation there before you send it.
This tends to get more tricky when sending a message to multiple users. You could however have the users subscribe to a language specific topic, for example lang_en, lang_fr, ...
and send your localized messages to those topics.
Use localization keys
As you already mentioned, there are specific keys available: titleLocKey
and bodyLocKey
. If you have the correct localization strings set up in the specific platforms, you can use their keys and the platform will figure out which label to show in the notification.
For iOS, this is managed in Localizable.strings
files, for Android, in res/values/strings.xml
.
Comments
-
asored over 1 year
I'm sending FCM Push Notifications with Firebase Cloud Messaging, Cloud Functions and Flutter as framework. I'm searching since 3 hours for a solution to receive the background notifications with translations. I want to display the translation in the device language.
What I found are parameters like
titleLocKey
andbodyLocKey
, but I can't find any way to use this parameters. Where in my project or on server environment I have to include this variables?I fire the notification like this:
// Push Notification const payload: admin.messaging.MessagingPayload = { notification: { title: "New User", body: "A new user entered your platform", badge: "1", } } fcm.sendToDevice(userToken, payload);
Do you have any idea?
-
Fatima ayaa almost 3 yearsi want to use the second method but i am confused, in my i have already config with flutter_localization is that a relation or need another configuration of res / values / strings.xml, thank you
-
Fatima ayaa almost 3 yearsstackoverflow.com/questions/67909213/… i asked a question here, plz check
-
dumazy almost 3 yearsI posted an answer there