Links

App-level Language Setting

We support app-level setting language on the iOS side since RN SDK V2.1.0.

Integration

JS/TS

import FireworkSDK from 'react-native-firework-sdk';
FireworkSDK.getInstance().changeAppLanguage('ar'); // such as: en, ar and en-US
Generally, the changeAppLanguage API should be called in the following cases:
  1. 1.
    The App is launched(e.g. in the componentDidMount method of App component).
  2. 2.
    Users change the app language manually.
  3. 3.
    Other cases that change app language.
If there is a react-native restart code in your app. Please add the code before the react-native restart code. Such as:
await FireworkSDK.getInstance().changeAppLanguage(language);
RNRestart.Restart();

Change app language on iOS native side

import FireworkVideoUI
AppLanguageManager.shared.changeAppLanguage("ar") // such as ar, ar-JO, en, etc.
Generally, the changeAppLanguage API should be called in the following cases:
  1. 1.
    The App is launched(e.g. in the application(:, didFinishLaunchingWithOptions:) -> Bool method).
  2. 2.
    Users change the app language manually.
  3. 3.
    Other cases that change app language.
After calling changeAppLanguage API, we need to recreate FireworkVideo SDK components to update the UI. Such as:
  • Recreate video feed and story block
  • Stop floating player

Change app language on Android native side

Step 1: The following methods need to be prepared
// Some code
// change language
fun changeLanguage(inputLocaleString: String, activity: Activity) {
// save to sp, or save to application or your app cache system
sharedPreferences.edit().apply {
putString(LOCALE_KEY, inputLocaleString)
}.commit()
restartActivity(activity)
}
// update the base context locale
fun updateBaseContextLocale(baseContext: Context): Context {
// Read from sp or application. If the language/locale exists in your app, use it directly
val currentLocaleString = sharedPreferences.getString(LOCALE_KEY, null)
if (currentLocaleStrinotg.isNullOrBlank()) {
return baseContext
}
val localeStrings = currentLocaleString.split("-")
val locale = if (localeStrings.size > 1) {
Locale(localeStrings[0], localeStrings[1])
} else {
Locale(currentLocaleString)
}
updateDefaultLocale(locale)
return updateResourcesLocale(baseContext, locale)
}
// update the default locale
private fun updateDefaultLocale(locale: Locale) {
Locale.setDefault(locale)
}
// update the context locale
private fun updateResourcesLocale(context: Context, locale: Locale): Context {
val resources = context.resources
val configuration = resources.configuration
configuration.setLocale(locale)
configuration.setLayoutDirection(locale)
return context.createConfigurationContext(configuration)
}
// restart activity
private fun restartActivity(activity: Activity) {
activity.recreate()
}
Step 2: Add the following code to all activities
// Some code
class YourActivity: Activity() {
...
override fun attachBaseContext(newBase: Context) {
super.attachBaseContext(updateBaseContextLocale(newBase))
}
}
Step 3: Call the change language method where you need
// Some code
// You must call this for all currently live activities
changeLanguage("ar", activity) // "ar-jo", "en-US", "en"