thudugala / Plugin.LocalNotification

The local notification plugin provides a way to show local notifications from .Net MAUI and Xamarin Forms apps .
MIT License
401 stars 66 forks source link

Unable to localize Action Button text in MAUI #446

Closed sfysi closed 10 months ago

sfysi commented 10 months ago

Describe the bug The NotificationAction class has a string Title property, but as the application context does not exist yet in the MauiProgram.CreateMauiApp method, trying to assign this property to something like Platform.CurrentActivity.Resources.GetString(Resource.String.some_string_key) will fail, and Resource.String.some_string_key itself is just an int that can't be assigned to the Title property.

To Reproduce Steps to reproduce the behavior:

  1. Use builder.UseLocalNotification to initialize configuration settings.
  2. Use config.AddCategory to create a category and give it an ActionList of NotificationAction objects.
  3. Try setting the Title of one of them to use Resources.GetString.
  4. Build and deploy the app, and it will immediately crash on startup.

Expected behavior The localized string can be used.

Platform (please complete the following information):

Smartphone (please complete the following information):

thudugala commented 10 months ago

@sfysi can you please attach a sample project?

sfysi commented 10 months ago

@thudugala - In the process of creating a sample project I discovered that MAUI has its own platform-agnostic localization handling, and while the Android-specific strings.xml files in Platforms/Android/Resources/values can't be accessed in the CreateMauiApp method, the Resources/Localization/AppStrings.resx files can, so that can be used for handling the button translations. Looks like no changes are needed after all. Thank you for your time!