App-level Language Setting (Flutter)
Dart integration
Please refer to the Language support table to learn the languages we supported.
Generally, the changeAppLanguage
API should be called in the following cases:
The App is launched(e.g. in the initState method of your App State.).
Users change the app language manually.
Other cases that change app language.
Additional setup steps on Android
On Android, we have two behaviors for switching languages: RestartingActivity
and NotRestartingActivity
. Different behaviors have different setup steps. You could choose one of them.
Option 1: Setup steps for RestartingActivity
RestartingActivity
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:
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
.Optional: Override the attachBaseContext
method in your MainApplication
.
attachBaseContext
method in your MainApplication
.If you need to support RTL, then please add the following configuration to the AndroidManifest.xml
AndroidManifest.xml
Option 2: Setup steps for NotRestartingActivity
NotRestartingActivity
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
.Configure the theme in your MainActivity
add android:theme="@style/Theme.AppCompat.DayNight.NoActionBar"
to the file app/src/Androidmanifest.xml
Besides the Theme.AppCompat.DayNight.NoActionBar
, you could also use a theme that meets one of the following conditions.
Any theme starting with Theme.AppCompat
Any theme that extends the theme starting with Theme.AppCompat
Override the attachBaseContext
method in your MainApplication
.
Set NotRestartingActivity
behavior for language-switching in your MainApplication
Add androidx.appcompat:appcompat
library in app/firework.gradle
If you need to support RTL, then please add the following configuration to the AndroidManifest.xml
AndroidManifest.xml
Language support table
Language | Language code |
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 |
Last updated