Skip to content

Internationalization in CMP

Learn how to create a basic implementation of field-level translation in a Compose Multiplatform (CMP) project.

In your space, open Settings → Internationalization → Languages and add es (Spanish).

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

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

shared/src/commonMain/kotlin/org/example/project/App.kt
…
import androidx.navigation3.runtime.entryProvider
import androidx.compose.ui.text.intl.LocaleList
…
val backStack = rememberNavBackStack(NavConfiguration, initialStoryKey)
val availableLanguages = listOf("es")
val language = LocaleList.current.localeList
.map { it.language }
.firstOrNull { it in availableLanguages }
Storyblok(
accessToken = "YOUR_ACCESS_TOKEN",
version = contentVersion,
region = EU, // Choose the correct region from your Space.
language = language,
…
) {
…
}
…

First, availableLanguages lists the language codes configured in the space.

Next, LocaleList.current returns the user’s preferred locales in priority order. The first locale whose language is in availableLanguages becomes the language parameter of the Storyblok composable function. If no locale matches, language stays null and the API returns the space’s default language.

Each target changes the language differently:

  • Android: change the device language under Settings → System → Languages, or set a per-app language preference. The configuration change recreates the composition and the stories are re-fetched automatically.
  • iOS: change the language in Settings → General → Language & Region, or set a per-scheme language in Xcode. The app restarts.
  • Web: change the language in the browser settings, then reload the page.

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.