App-level Language Setting (Flutter)
Dart integration
import 'package:fw_flutter_sdk/fw_flutter_sdk.dart';
// You should pass language code to this API, such as "en", "ar", "pt-BR" and "hu" etc.
// For the language codes we support, please refer to "Language support table" below.
FireworkSDK.getInstance().changeAppLanguage("ar");
Please refer to the Language support table to learn the languages we supported.
Additional setup steps on iOS
Firework SDK widgets are based on native views. Thus, as depicted in the screenshot below, you must add all the language localizations you wish to support to the iOS project, as required by Apple.

Additional setup steps on Android
We also require some additional setup steps on Android. On Android, there are two behaviors for switching languages: RestartingActivity
and NotRestartingActivity
. Each behavior involves different setup steps, and you can choose either one.
Option 1: Setup steps for RestartingActivity
RestartingActivity
RestartingActivity
option will restart the Android activity when changing the app language.
Calling sequence
Currently, FireworkSDK.getInstance().changeAppLanguage
will recreate the activity by default on Android. Therefore, we need to follow the calling sequence.
Generally, you also have codes for switching languages, such as the codes of caching the language. Please call FireworkSDK.getInstance().changeAppLanguage
after all your codes for switching languages. For example:
import 'package:localstorage/localstorage.dart';
const language = "ar";
// cache language
await localStorage.setItem("app_language", language);
// We need to call SDK changeAppLanguage API after your codes for switching languages,
// such as the codes of caching the language
await FireworkSDK.getInstance().changeAppLanguage(language);
Add codes on Android project
To be able to use the in-app language feature, the following configuration needs to be added to the app project.
Override the attachBaseContext
method in your MainActivity
.
attachBaseContext
method in your MainActivity
.import com.fireworksdk.bridge.flutter.FWFlutterSDK
class MainActivity: FlutterFragmentActivity() {
override fun attachBaseContext(newBase: Context) {
super.attachBaseContext(FWFlutterSDK.updateBaseContextLocale(newBase))
}
}
Optional: Override the attachBaseContext
method in your MainApplication
.
attachBaseContext
method in your MainApplication
.class MainApplication: FlutterApplication() {
override fun attachBaseContext(base: Context) {
// If you can know the app language here, you could also call FWFlutterSDK.changeLanguage here to sync the app language to SDK. Such as:
// FWFlutterSDK.changeLanguage("en", base)
super.attachBaseContext(FWFlutterSDK.updateBaseContextLocale(base))
}
}
If you need to support RTL, then please add the following configuration to the AndroidManifest.xml
AndroidManifest.xml
<application
...
android:supportsRtl="true"
>
...
Option 2: Setup steps for NotRestartingActivity
NotRestartingActivity
NotRestartingActivity
option won't restart the Android activity when changing the app language.
Add codes on Android project
To be able to use the in-app language feature, the following configuration needs to be added to the app project.
Inherit the FWFlutterFragmentActivity
class in your MainActivity
.
FWFlutterFragmentActivity
class in your MainActivity
.import com.fireworksdk.bridge.flutter.base.FWFlutterFragmentActivity
class MainActivity: FWFlutterFragmentActivity()
Configure the theme in your MainActivity
add android:theme="@style/Theme.AppCompat.DayNight.NoActionBar"
to the file app/src/Androidmanifest.xml
<application
android:name=".MainApplication"
...>
<activity
android:name=".MainActivity"
...
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar">
</activity>
</application>
Override the attachBaseContext
method in your MainApplication
.
class MainApplication: FlutterApplication() {
override fun attachBaseContext(base: Context) {
super.attachBaseContext(FWFlutterSDK.updateBaseContextLocale(base))
}
}
Set NotRestartingActivity
behavior for language-switching in your MainApplication
class MainApplication: FlutterApplication() {
override fun onCreate() {
super.onCreate()
// We suggest setting behavior before you invoke FWFlutterSDK.init()
FWFlutterSDK.setLanguageSwitchingBehavior(FWSwitchLanguageBehavior.NotRestartingActivity)
// Invoke FWFlutterSDK.init() for initialize FWFlutterSDK
...
}
}
Add androidx.appcompat:appcompat
library in app/firework.gradle
dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
...
}
...
If you need to support RTL, then please add the following configuration to the AndroidManifest.xml
AndroidManifest.xml
<application
...
android:supportsRtl="true"
>
...
Language support table
English
en
Arabic
ar
Arabic (Saudi Arabia)
ar-SA
Arabic (United Arab Emirates)
ar-AE
German
de
Italian
it
Japanese
ja
Polish
pl
Portuguese (Brazil)
pt-BR
Russian
ru
Spanish
es
Spanish (Mexico)
es-MX
Spanish (Colombia)
es-CO
Vietnamese
vi
Thailand
th
Hungarian
hu
Turkish
tr
French
fr
Portuguese
pt
Indonesian
id
Swedish
sv
Last updated
Was this helpful?