Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translation of Push-Notification #407

Closed
Fintasys opened this issue Jul 20, 2021 · 2 comments
Closed

Translation of Push-Notification #407

Fintasys opened this issue Jul 20, 2021 · 2 comments

Comments

@Fintasys
Copy link

I'm using Firebase Cloud-Messaging to send push notifications to my App.
FCM does not call main() instead it calls a global method. Inside this global method I am initializing easy_localization and firebase. This method will then show a notification where I try to translate received body text.

Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  await Firebase.initializeApp();
  await NotificationManager.instance.init();
  await EasyLocalization.ensureInitialized();
  ....
  var body = LocaleKeys.chat_message_notification_body_image.tr()
}

body will be chat_message_notification_body_image and throws error message that the key couldn't be found.

Does anyone know to get translation to work here?

@Fintasys
Copy link
Author

Solved with workaround described here: #210

@hasanm08
Copy link

use this code

  static Future<bool> isEnglish() async {
    SharedPreferences preferences = await SharedPreferences.getInstance();
    await preferences.reload();
    String? locale = preferences.getString('locale');
    return locale?.contains('en') ?? true;
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants