|
9 | 9 | import android.os.Bundle; |
10 | 10 | import android.os.Handler; |
11 | 11 | import android.os.Looper; |
| 12 | +import android.content.Context; |
12 | 13 | import android.util.Log; |
13 | 14 | import android.net.Uri; |
14 | 15 | import androidx.annotation.NonNull; |
@@ -46,8 +47,11 @@ public void handleReceivedMessage(RemoteMessage message) { |
46 | 47 | // ^ It's null when message is from GCM |
47 | 48 | RNPushNotificationConfig config = new RNPushNotificationConfig(mFirebaseMessagingService.getApplication()); |
48 | 49 |
|
49 | | - bundle.putString("title", remoteNotification.getTitle()); |
50 | | - bundle.putString("message", remoteNotification.getBody()); |
| 50 | + String title = getLocalizedString(remoteNotification.getTitle(), remoteNotification.getTitleLocalizationKey(), remoteNotification.getTitleLocalizationArgs()); |
| 51 | + String body = getLocalizedString(remoteNotification.getBody(), remoteNotification.getBodyLocalizationKey(), remoteNotification.getBodyLocalizationArgs()); |
| 52 | + |
| 53 | + bundle.putString("title", title); |
| 54 | + bundle.putString("message", body); |
51 | 55 | bundle.putString("sound", remoteNotification.getSound()); |
52 | 56 | bundle.putString("color", remoteNotification.getColor()); |
53 | 57 | bundle.putString("tag", remoteNotification.getTag()); |
@@ -178,4 +182,28 @@ private void handleRemotePushNotification(ReactApplicationContext context, Bundl |
178 | 182 | pushNotificationHelper.sendToNotificationCentre(bundle); |
179 | 183 | } |
180 | 184 | } |
| 185 | + |
| 186 | + private String getLocalizedString(String text, String locKey, String[] locArgs) { |
| 187 | + if(text != null) { |
| 188 | + return text; |
| 189 | + } |
| 190 | + |
| 191 | + Context context = mFirebaseMessagingService.getApplicationContext(); |
| 192 | + String packageName = context.getPackageName(); |
| 193 | + |
| 194 | + String result = null; |
| 195 | + |
| 196 | + if (locKey != null) { |
| 197 | + int id = context.getResources().getIdentifier(locKey, "string", packageName); |
| 198 | + if (id != 0) { |
| 199 | + if (locArgs != null) { |
| 200 | + result = context.getResources().getString(id, (Object[]) locArgs); |
| 201 | + } else { |
| 202 | + result = context.getResources().getString(id); |
| 203 | + } |
| 204 | + } |
| 205 | + } |
| 206 | + |
| 207 | + return result; |
| 208 | + } |
181 | 209 | } |
0 commit comments