Logic for obtaining user's preferred language

The IAPMiniProgram Android SDK automatically obtains the user's preferred language and uses it for SDK-controlled language display, including SDK-provided UI content and mini program information.

Language source decision logic

The SDK automatically selects the language source based on the super app's multilingual implementation to ensure a consistent user experience. Scenarios include:

Super app multilingual implementation

SDK language source

No multilingual capabilities implemented.

System settings

Multilingual capabilities implemented without following Android guidelines.

Multilingual capabilities implemented via system settings, following Android's Support different languages and cultures guideline.

Multilingual capabilities implemented via per-app language settings, following Android's Per-app language preferences guideline.

Per-app settings

Custom language management implemented, providing the SDK with a custom Resources object with language configuration.

Provided Resources object

The SDK automatically applies the appropriate logic without requiring additional configuration. The only exception is when using custom Resources, where the super app must implement the AppSystemResourcesExtension interface and ensure the resource configuration remains updated after language changes.

Source from system settings

When the SDK uses system settings as the language source, it obtains the user's preferred language from the language settings on the user's device.

Users usually configure this language in the device system settings. The exact path to change this setting may vary by Android version and device manufacturer. An example path is Settings > System > Language & input > Language.

Source from per-app settings

When the SDK uses per-app settings as the language source, it obtains the user's preferred language from the app's current locale using the following code:

copy
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
    return resources.getConfiguration().getLocales().get(0);
} else {
    Configuration configuration = resources.getConfiguration();
    return configuration.locale;
}

With the following example locale-config, the SDK obtains the first locale in the list, en-US, as the preferred language:

copy
<?xml version="1.0" encoding="utf-8"?>
<locale-config xmlns:android="http://schemas.android.com/apk/res/android">
  <locale android:name="en-US"/>
  <locale android:name="en-GB"/>
  <locale android:name="fr"/>
  <locale android:name="ja"/>
  <locale android:name="zh-Hans-MO"/>
  <locale android:name="zh-Hant-MO"/>
</locale-config>

Source from provided Resources object

If your super app uses a highly customized language management system instead of standard Android language APIs, the SDK supports obtaining the language from a custom Resources object provided by the super app.

This logic works as follows:

  1. The super app implements AppSystemResourcesExtension interface and provides a Resources object that contains the desired language configuration.
  2. The SDK uses the provided Resources instead of the default application Resources.
  3. The SDK reads the locale from the configuration of the provided Resources.
  4. The SDK uses that locale as the user's preferred language.

Note: If the app language changes, the super app must update the Resources configuration accordingly to ensure the SDK reflects the current language setting.