A flexible, easy-to-use internationalization framework for Summon applications that supports multiple languages, including right-to-left (RTL) layouts.
Configure the languages your application will support:
// Configure languages in your app initialization
I18nConfig.configure {
language("en", "English")
language("fr", "Français")
language("ar", "العربية", LayoutDirection.RTL)
// Set default language
setDefault("en")
}
Create JSON files for each language with the same structure:
src/jsMain/resources/i18n/
en.json
fr.json
ar.json
Example translation file (en.json):
{
"common": {
"welcome": "Welcome to our application",
"language": "Language"
},
"nav": {
"home": "Home",
"about": "About"
}
}
For JavaScript/browser applications:
// Initialize i18n system
JsI18nImplementation.init()
// Load translations from resources
JsI18nImplementation.loadLanguageResources("/i18n/")
Wrap your application content with the LanguageProvider:
@Composable
fun App() {
LanguageProvider {
// Your app content here
MainContent()
}
}
Access translations with the stringResource composable function:
@Composable
fun WelcomeScreen() {
Text(
text = stringResource("common.welcome"),
modifier = Modifier.padding("20px")
)
}
Replace direction-specific modifiers with direction-aware versions:
// Instead of paddingLeft/paddingRight
.paddingStart("10px") // Left in LTR, Right in RTL
.paddingEnd("10px") // Right in LTR, Left in RTL
// For directional rows that reverse in RTL
Row(Modifier.directionalRow()) {
// Content will be reversed in RTL languages
}
Allow users to change languages:
Button(onClick = { changeLanguage("ar") }) {
Text("العربية")
}
For more detailed documentation, please refer to these resources:
stringResource() for user-visible textmirrorInRtl() modifierContributions to improve the internationalization framework are welcome. Please follow the project's contribution guidelines.