Skip to content

Internationalization in Android

Learn how to create a basic implementation of field-level translation in an Android project.

In your space, open SettingsInternationalizationLanguages and add es (Spanish).

  • In the article content type block schema, set the title and content fields as translatable.
  • Go to each article, select the Spanish language, and provide translated content. You can also use AI Translations.

Update MainActivity.kt to determine the language from the device locale.

app/src/main/java/com/example/myapplication/MainActivity.kt
import androidx.navigation3.runtime.entryProvider
import 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 SettingsSystemLanguages, or add a per-app language preference. The app now renders the translated article content.

Was this page helpful?

What went wrong?

This site uses reCAPTCHA and Google's Privacy Policy (opens in a new window).Terms of Service (opens in a new window) apply.