feature: offer the Android per-app language picker for localized apps - #369
feature: offer the Android per-app language picker for localized apps#369SRWieZ wants to merge 1 commit into
Conversation
Android 13+ only lists an app in Settings' per-app language picker when its manifest points at a locale-config resource. iOS already registers the locales declared via permission_localizations (per-locale InfoPlist.strings + knownRegions); Android silently ignored them, so a localized NativePHP app followed the system language but never appeared in per-app language settings. The Android compiler now collects every locale declared by the app's permission_localizations and plugins' ios.info_plist_localizations, writes res/xml/locales_config.xml (new default_locale config leads the list so users can always switch back), and injects android:localeConfig into the <application> tag. Runs before the no-plugins early return, mirrors the iOS app-config-only path, and is idempotent. Apps declaring no localizations are untouched.
49835ca to
8e28e8a
Compare
|
Awesome, thanks! Great PR 🚀 One design question first, more for @simonhamp (and my own understanding) than for this PR. The language list comes from Then a smaller one, about what happens when the localizations go away again by an update after the app is already installed:
Admittedly, this will likely not happen often in nativephp apps, but it might. It is cosmetic, but |
|
I think this was originally based on iOS, if I recall correctly. As a user, I’d personally prefer full control over which locales are suggested. It really depends more on my Laravel app’s translation strings than on plugin permissions. So maybe a new config ? |
|
Exactly. We cant have a random plugin contributing a bunch of extra language options the app doesnt even support. Dedicated config makes sense to me. Good to be explicit. What do you think bossmen @simonhamp @shanerbaner82 ? |
The gap
Declare
permission_localizationsinconfig/nativephp.phpand iOS registers the locales — per-localeInfoPlist.strings,knownRegions— so the app shows up in Settings → [App] → Preferred Language.On Android, nothing happens. Android 13+ only lists an app in the per-app language picker when its manifest points at a locale-config resource, and the compiler never writes one. So a fully localized NativePHP app follows the system language but can never be switched per app:
The fix
AndroidPluginCompilernow mirrors what the iOS compiler already does with the same declarations:permission_localizationsand by plugins'ios.info_plist_localizations.res/xml/locales_config.xml. A new documenteddefault_localeconfig key (default'en') leads the list, so users can always switch back to the app's base language explicitly.android:localeConfig="@xml/locales_config"into the<application>tag (once — idempotent across rebuilds).It runs before the no-plugins early return, so an app with only its own
permission_localizationsgets the picker too (same app-config-only path the iOS side handles).Apps that declare no localizations are completely untouched — no file, no manifest change.
Verified on an emulator (Android 16)
The picker lists exactly the declared locales, and selecting one changes what the app's PHP sees (
Locale.getDefault()→Device::getInfo()['language']):Tests
Three new cases in
AndroidCompilerTest: writes the config + manifest attribute from app declarations, merges plugin locales and stays idempotent, and leaves apps without localizations untouched. Full suite passes (899).