Support for per-app language preferences on Android
Andor Davoti
On iOS you can simply add:
"ios": {
"infoPlist": {
"CFBundleLocalizations": ["no", "en"]
}
}
For the iOS settings app to recognize that your app supports specific languages and allow you to select these in the native iOS settings app for your app.
On Android you need to create a "locales_config.xml" file with the locales and include it in the manifest, as described here: https://developer.android.com/guide/topics/resources/app-languages
This is possible with expo, but it breaks CNG. Would be great to be able to pass the locales you can to support to the config plugin, for it then to add it to "CFBundleLocalizations" and generate the required config on Android as well.
It would also be beneficial if there was a way to open the app's locale settings from expo localization. Right now I have had to create a custom native module for it in Kotlin. Linking.openSettings() works for this on iOS, but on Android it's excessively complicated. The Kotlin code looks like this:
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
@ReactMethod
fun openAppLocaleSettings() {
val intent = Intent(Settings.ACTION_APP_LOCALE_SETTINGS)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
intent.data = Uri.parse("package:" + context.packageName)
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName)
if (intent.resolveActivity(context.packageManager) != null) {
context.startActivity(intent)
}
}
I've tried replicating this with expo-intent-launcher like this:
await startActivityAsync(
"android.settings.APP_LOCALE_SETTINGS",
{
data: `package:${Application.applicationId}`,
extra: {
"android.provider.extra.APP_PACKAGE": Application.applicationId,
},
}
);
However it doesn't work and it's unclear how the flags would be passed in here since it requires a number.
Andor Davoti
I created an open-source Expo Module that solves this: https://github.com/andordavoti/expo-localization-utils
However, it would be nice to have this be a part of the Expo Localization library. I tried looking at the code for that in Expo, but I couldn't find any good docs on how to get familiar with the Expo codebase. If someone could help me with that, I'd gladly work on a PR.