This document provides an overview of Summon's internationalization (i18n) capabilities, including how to set up multiple languages, handle RTL languages, and integrate translations into your application.
Summon provides a complete internationalization solution that allows you to:
To configure the languages your application supports, use the I18nConfig object:
// In your application initialization
fun main() {
// Configure languages
I18nConfig.configure {
language("en", "English")
language("fr", "Français")
language("ar", "العربية", LayoutDirection.RTL)
language("he", "עברית", LayoutDirection.RTL)
// Set the default language
setDefault("en")
}
// Load translations (platform-specific)
// ...
}
Each language is defined with:
Create JSON files for each supported language:
src/jsMain/resources/i18n/
en.json
fr.json
ar.json
he.json
Example translation file (en.json):
{
"common": {
"welcome": "Welcome to our application",
"language": "Language",
"back": "Back",
"next": "Next",
"save": "Save",
"cancel": "Cancel"
},
"nav": {
"home": "Home",
"about": "About",
"contact": "Contact"
}
}
The same keys should be present in all language files, with translated values.
JavaScript/Browser:
// JS-specific loading
JsI18nImplementation.init()
JsI18nImplementation.loadLanguageResources("/i18n/")
Use the stringResource composable function to get translated strings:
@Composable
fun WelcomeScreen() {
Text(
text = stringResource("common.welcome"),
modifier = Modifier.padding("20px")
)
Button(onClick = { /* ... */ }) {
Text(stringResource("common.next"))
}
}
Summon supports right-to-left (RTL) languages with automatic layout adjustments.
RTL support is automatically enabled when you define a language with LayoutDirection.RTL.
For JavaScript/browser applications, the dir attribute is automatically applied to the HTML element when the language changes.
Use directional modifiers to create layouts that adapt to text direction:
@Composable
fun DirectionalExample() {
Row(Modifier.directionalRow()) {
// This row will automatically reverse in RTL mode
Icon(imageVector = Icons.Default.ArrowForward)
Text(
text = stringResource("nav.next"),
modifier = Modifier
.paddingStart("8px") // Will be left padding in LTR, right in RTL
.paddingEnd("16px") // Will be right padding in LTR, left in RTL
)
}
}
dir attributeTo change the application language:
Button(onClick = { changeLanguage("ar") }) {
Text("العربية")
}
The changeLanguage function will update the UI and document direction automatically.
mirrorInRtl() modifierFor any questions or issues, please file a report in the issue tracker.