The SDK supports multilingual adaptation out of the box, including Chinese, English, and Arabic. It automatically adjusts based on the system’s language settings.
Issue 1: Sync IMKit SDK language changes with the app’s language configuration
By default, the SDK only monitors system language changes. However, it provides an interface for the app to update the language configuration. Check the RongConfigurationManager
class for related methods:
RongConfigurationManager.getInstance().switchLocale()
Issue 2: Update the built-in UI in IMKit SDK
You’ll need to address both the Activity and Application components:
Handling Activity
- Use the SDK’s built-in Activity for the conversation list and conversation pages.
- Use your own Activity to load SDK pages by inheriting
RongBaseActivity
. - Use your own Activity to load SDK pages without inheriting
RongBaseActivity
, and add the following code:
Context context = RongConfigurationManager.getInstance().getConfigurationContext(newBase);
Code reference:
Handling Application
Add the following code:
Context context = LangUtils.getConfigurationContext(base);
Code reference:
Issue 3: Set the entire IMKit to a fixed language
To set IMKit to English regardless of the system language, follow these steps:
Note: The context must be of Application type (or use context.getApplicationContext()
), otherwise some pages may not take effect.
// Refer to RCLocale
LangUtils.RCLocale selectedLocale = LangUtils.RCLocale.LOCALE_US;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Resources resources = context.getResources();
DisplayMetrics dm = resources.getDisplayMetrics();
Configuration config = resources.getConfiguration();
LocaleList localeList = new LocaleList(selectedLocale.toLocale());
LocaleList.setDefault(localeList);
config.setLocales(localeList);
resources.updateConfiguration(config, dm);
LangUtils.saveLocale(context, selectedLocale);
} else {
RongConfigurationManager.getInstance().switchLocale(selectedLocale, context);
}
Supported language types in LangUtils.RCLocale
:
class RCLocale {
/** Chinese */
public static final RCLocale LOCALE_CHINA = new RCLocale("zh");
/** English */
public static final RCLocale LOCALE_US = new RCLocale("en");
/** Arabic */
public static final RCLocale LOCALE_ARAB = new RCLocale("ar");
}