Skip to content

fix(notifications): use app language#20747

Merged
mikehardy merged 2 commits intoankidroid:mainfrom
david-allison:19048-notification-language
Apr 19, 2026
Merged

fix(notifications): use app language#20747
mikehardy merged 2 commits intoankidroid:mainfrom
david-allison:19048-notification-language

Conversation

@david-allison
Copy link
Copy Markdown
Member

Note

Assisted-by: Claude Opus 4.6 - withAppLocale + investigation

Purpose / Description

On API 32 and earlier, AppCompatDelegate.setApplicationLocales only works with AppCompatActivity.

Fixes

Approach

Work around this by manually setting the app locale

How Has This Been Tested?

Android Version = 7.0 (SDK 24)

  • Set the language to German then launch the app, before and after
Screenshot 2026-04-15 at 12 04 47 Screenshot 2026-04-15 at 12 03 44

Learning (optional, can help others)

https://developer.android.com/reference/androidx/appcompat/app/AppCompatDelegate#setApplicationLocales(androidx.core.os.LocaleListCompat)

Checklist

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

On API 32 and earlier, AppCompatDelegate.setApplicationLocales
 only works with AppCompatActivity.

Work around this by manually setting the app locale

Fixes 19048

Assisted-by: Claude Opus 4.6 - withAppLocale + investigation
Comment thread AnkiDroid/src/main/java/com/ichi2/anki/services/NotificationService.kt Outdated
@david-allison david-allison added this to the 2.24 release milestone Apr 15, 2026
Copy link
Copy Markdown
Member

@ericli3690 ericli3690 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you David!! This looks great. I'll make a note to test this on the new review reminders system too once our strings are localized.

Only one major concern: this issue was originally opened when I found this to-do comment by @mikehardy in NotificationChannels:

/**
 * Create or update all the notification channels for the app
 *
 * In Oreo and higher, you must create a channel for all notifications.
 * This will create the channel if it doesn't exist, or if it exists it will update the name.
 *
 * Note that once a channel is created, only the name may be changed as long as the application
 * is installed on the user device. All other settings are fully under user control.
 *
 * TODO should be called in response to [Intent.ACTION_LOCALE_CHANGED]
 * @param context the context for access to localized strings for channel names
 */
fun setupNotificationChannels(context: Context) {
// ...

In particular the TODO portion. Do we actually need to make setupNotificationChannels listen to Intent.ACTION_LOCALE_CHANGED, or will that no longer necessary after merging this PR? If so, please remove the above comment in NotificationChannels.

Comment thread AnkiDroid/src/main/java/com/ichi2/anki/services/NotificationService.kt Outdated
Comment thread AnkiDroid/src/main/java/com/ichi2/utils/LanguageUtil.kt
@david-allison
Copy link
Copy Markdown
Member Author

Thank you David!! This looks great. I'll make a note to test this on the new review reminders system too once our strings are localized.

Only one major concern: this issue was originally opened when I found this to-do comment by @mikehardy in NotificationChannels:

/**
 * Create or update all the notification channels for the app
 *
 * In Oreo and higher, you must create a channel for all notifications.
 * This will create the channel if it doesn't exist, or if it exists it will update the name.
 *
 * Note that once a channel is created, only the name may be changed as long as the application
 * is installed on the user device. All other settings are fully under user control.
 *
 * TODO should be called in response to [Intent.ACTION_LOCALE_CHANGED]
 * @param context the context for access to localized strings for channel names
 */
fun setupNotificationChannels(context: Context) {
// ...

In particular the TODO portion. Do we actually need to make setupNotificationChannels listen to Intent.ACTION_LOCALE_CHANGED, or will that no longer necessary after merging this PR? If so, please remove the above comment in NotificationChannels.

Untested, I suspect it will still be necessary

@mikehardy
Copy link
Copy Markdown
Member

If the goal is to have "all of the app" change when a language changes - either through our in-app language picker or through a system locale change, then you also must persist new notification channel names into the android system as well, implying that - yes - that notification channel setup needs to be hooked on to whatever infra we have for handling language updates, and we should be listening to system locale change broadcast

@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Apr 16, 2026
@david-allison david-allison force-pushed the 19048-notification-language branch from 0bb479f to 5745591 Compare April 17, 2026 09:05
@david-allison david-allison removed the Needs Author Reply Waiting for a reply from the original author label Apr 17, 2026
@david-allison
Copy link
Copy Markdown
Member Author

david-allison commented Apr 17, 2026

I'm leaving the NotificationChannel TODO as out of scope for this PR

From what I recall, the state of notification channels being semi-immutable would need some additional brainpower, whereas this is a fairly simple refactor.

@david-allison david-allison force-pushed the 19048-notification-language branch from 5745591 to 159da03 Compare April 17, 2026 18:28
Copy link
Copy Markdown
Member

@ericli3690 ericli3690 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Comment thread AnkiDroid/src/main/java/com/ichi2/anki/CoroutineHelpers.kt Outdated
On API 32 and earlier, AppCompatDelegate.setApplicationLocales
only works with AppCompatActivity.

Work around this by manually setting the app locale

Issue 19048

Assisted-by: Claude Opus 4.6 - most of the refactoring
@david-allison david-allison force-pushed the 19048-notification-language branch from 159da03 to b95e885 Compare April 19, 2026 05:52
@david-allison david-allison added Needs Second Approval Has one approval, one more approval to merge and removed Needs Review labels Apr 19, 2026
@david-allison
Copy link
Copy Markdown
Member Author

@ericli3690 Thanks so much!

Im assuming your approval still stands, but a second look would be excellent

Copy link
Copy Markdown
Member

@ericli3690 ericli3690 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep looks great! Thanks thanks

Copy link
Copy Markdown
Member

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - it is unbelievable how much effort it takes to keep an "app language may not be system language" feature working correctly in Android across Android SDK version skew... the amount of time over the years...

@mikehardy mikehardy added this pull request to the merge queue Apr 19, 2026
@mikehardy mikehardy added Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) and removed Needs Second Approval Has one approval, one more approval to merge labels Apr 19, 2026
Merged via the queue into ankidroid:main with commit 2668e57 Apr 19, 2026
15 checks passed
@github-actions github-actions Bot removed the Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) label Apr 19, 2026
@david-allison david-allison deleted the 19048-notification-language branch April 19, 2026 18:41
@david-allison
Copy link
Copy Markdown
Member Author

I forgot to force push here, there will be a minor follow-up

@david-allison david-allison self-assigned this Apr 19, 2026
ericli3690 added a commit to ericli3690/Anki-Android-ericli3690 that referenced this pull request Apr 19, 2026
ericli3690 added a commit to ericli3690/Anki-Android-ericli3690 that referenced this pull request Apr 20, 2026
ericli3690 added a commit to ericli3690/Anki-Android-ericli3690 that referenced this pull request Apr 23, 2026
ericli3690 added a commit to ericli3690/Anki-Android-ericli3690 that referenced this pull request Apr 23, 2026
Follow-up for ankidroid#20747

Also a small comment change requested by David.
ericli3690 added a commit to ericli3690/Anki-Android-ericli3690 that referenced this pull request Apr 23, 2026
Follow-up for ankidroid#20747

Also a small comment change requested by David.
ericli3690 added a commit to ericli3690/Anki-Android-ericli3690 that referenced this pull request Apr 23, 2026
Follow-up for ankidroid#20747

Also a small comment change requested by David!
ericli3690 added a commit to ericli3690/Anki-Android-ericli3690 that referenced this pull request Apr 23, 2026
Follow-up for ankidroid#20747

Also a small comment change requested by David!
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

Successfully merging this pull request may close these issues.

Notification Doesn't Follow App Language

3 participants