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
titleandcontentfields as translatable. - Open 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 App.kt to determine the language from the device locale.
…import androidx.navigation3.runtime.entryProviderimport 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.
Test on each target
Section titled “Test on each target”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.
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