Internationalization in Android
Learn how to create a basic implementation of field-level translation in an Android project.
In your space, open Settings → Internationalization → Languages and add es (Spanish).
- In the article content type block schema, set the
titleandcontentfields as translatable. - Go to each article, select the Spanish language, and provide translated content. You can also use AI Translations.
Use the device locale
Section titled “Use the device locale”Update MainActivity.kt to determine the language from the device locale.
…import androidx.navigation3.runtime.entryProviderimport androidx.compose.ui.platform.LocalConfiguration… val backStack = rememberNavBackStack(HomeKey)
val availableLanguages = arrayOf("es") val locale = LocalConfiguration.current.locales .getFirstMatch(availableLanguages)
Storyblok( accessToken = "YOUR_ACCESS_TOKEN", version = if (BuildConfig.DEBUG) Draft else Published, region = EU, // Choose the correct region from your Space. language = locale?.language?.takeIf { it in availableLanguages }, … ) { … }…First, an array with all language codes configured in the space is defined.
Next, getFirstMatch() resolves the best match among the languages available in the space. If the locale match is in our array of available languages, it is passed to the Storyblok composable function via its language parameter.
Because LocalConfiguration is a composition local, changing the device language triggers a configuration change, and the stories are automatically re-fetched in the newly selected language.
To test the implementation, change the device language to Spanish under Settings → System → Languages, or add a per-app language preference. The app now renders the translated article content.
Related resources
Section titled “Related resources”Was this page helpful?
This site uses reCAPTCHA and Google's Privacy Policy (opens in a new window).Terms of Service (opens in a new window) apply.
Get in touch with the Storyblok community