Skip to content

Commit

Permalink
docs(fcm): add documentation for localized strings in notifications (#…
Browse files Browse the repository at this point in the history
…9502)

* doc(fcm): add documentation for localized strings in notifications

* doc(fcm): add documentation for localized strings in notifications

* doc(fcm): add documentation for localized strings in notifications
  • Loading branch information
Lyokone committed Sep 27, 2022
1 parent d834b90 commit 927c1ca
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions docs/cloud-messaging/receive.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,69 @@ class _Application extends State<Application> {
```

How you handle interaction depends on your application setup. The above example shows a basic illustration using a StatefulWidget.

## Localize Messages

You can send localized strings in two different ways:

* Store the preferred language of each of your users in your server and send customized notifications for each language
* Embed localized strings in your app and make use of the operating system's native locale settings

Here's how to use the second method:

### Android

1. Specify your default-language messages in `resources/values/strings.xml`:

```xml
<string name="notification_title">Hello world</string>
<string name="notification_message">This is a message</string>
```

2. Specify the translated messages in the <code>values-<var>language</var></code> directory. For example, specify French messages in `resources/values-fr/strings.xml`:

```xml
<string name="notification_title">Bonjour le monde</string>
<string name="notification_message">C'est un message</string>
```

3. In the server payload, instead of using `title`, `message`, and `body` keys, use `title_loc_key` and `body_loc_key` for your localized message, and set them to the `name` attribute of the message you want to display.

The message payload would look like this:

```json
{
"data": {
"title_loc_key": "notification_title",
"body_loc_key": "notification_message"
},
}
```


### iOS

1. Specify your default-language messages in `Base.lproj/Localizable.strings`:

```
"NOTIFICATION_TITLE" = "Hello World";
"NOTIFICATION_MESSAGE" = "This is a message";
```

2. Specify the translated messages in the <code><var>language</var>.lproj</code> directory. For example, specify French messages in `fr.lproj/Localizable.strings`:

```
"NOTIFICATION_TITLE" = "Bonjour le monde";
"NOTIFICATION_MESSAGE" = "C'est un message";
```

The message payload would look like this:

```json
{
"data": {
"title_loc_key": "NOTIFICATION_TITLE",
"body_loc_key": "NOTIFICATION_MESSAGE"
},
}
```

0 comments on commit 927c1ca

Please sign in to comment.