问题
I am trying to display localized notification in flutter using firebase_messaging, I am getting a json with 3 language strings in body of a notification like so:
{"it": "italian text", "de": "german text", "en": "english text"}
As of now, it is showing the whole json string in the notification tray. How can I select the appropriate language text from the json and show in notification when app is in background? myBackgroundMessageHandler this function is never called. Thanks.
回答1:
I could not get myBackgroundMessageHandler function to call when in background. I did find a couple of ways to localize notifications using loc_key like tags in iOS like this and in android like this.
However, this method was not suitable for my case because I had to send a bulk text (for example for sending promotions) in the notification. So I ended up saving the device's language in the backend when user subscribes something. That way backend can send the notification only in that language to that device.
来源:https://stackoverflow.com/questions/64804684/flutter-how-to-format-title-and-body-of-notification-in-background