This document provides detailed API reference for the internationalization framework in Summon.
Languagedata class Language(
val code: String,
val name: String,
val direction: LayoutDirection
)
Represents a supported language in the application.
Properties:
code: ISO language code (e.g., "en", "fr")name: Display name of the languagedirection: Text direction for this languageLayoutDirectionenum class LayoutDirection {
LTR, RTL
}
Enum representing text and UI element direction.
Values:
LTR: Left-to-right (default for most Western languages)RTL: Right-to-left (for languages like Arabic, Hebrew)I18nConfigobject I18nConfig
Configuration object for internationalization settings.
Properties:
supportedLanguages: List of supported languagesdefaultLanguage: The default language (nullable)Methods:
configure(block: I18nConfigBuilder.() -> Unit): Configure i18n settings using the DSL builderI18nConfigBuilderclass I18nConfigBuilder
Builder class for i18n configuration DSL.
Methods:
language(code: String, name: String, direction: LayoutDirection = LayoutDirection.LTR): Add a supported languagesetDefault(code: String): Set the default language by language codeStringResourcesobject StringResources
Manager for string translation resources.
Methods:
loadTranslations(languageCode: String, jsonContent: String): Load translations for a specific languagegetString(key: String, languageCode: String, fallbackLanguageCode: String? = null): Get a translated stringclearTranslations(): Clear all loaded translationsgetKeysForLanguage(languageCode: String): Get all keys for a specific languageval LocalLanguage: CompositionLocal<Language>
val LocalLayoutDirection: CompositionLocal<LayoutDirection>
Composition locals that provide the current language and layout direction in the composition.
LanguageProvider@Composable
fun LanguageProvider(
initialLanguage: Language = I18nConfig.defaultLanguage ?: Language("en", "English", LayoutDirection.LTR),
content: @Composable () -> Unit
)
Provides language context to the application.
Parameters:
initialLanguage: The initial language to use (defaults to the configured default language)content: The content to be provided with language contextstringResource@Composable
fun stringResource(key: String): String
Utility function to get a localized string.
Parameters:
key: The translation key (e.g., "common.welcome")Returns:
@Composable
fun Modifier.paddingStart(value: String): Modifier
@Composable
fun Modifier.paddingEnd(value: String): Modifier
@Composable
fun Modifier.marginStart(value: String): Modifier
@Composable
fun Modifier.marginEnd(value: String): Modifier
Creates padding/margin that adapts to the current layout direction.
Parameters:
value: The padding/margin value (e.g., "8px")@Composable
fun Modifier.borderStart(width: String, style: String, color: String): Modifier
@Composable
fun Modifier.borderEnd(width: String, style: String, color: String): Modifier
Adds a border to the start/end edge of an element.
Parameters:
width: Border widthstyle: Border stylecolor: Border color@Composable
fun Modifier.textStart(): Modifier
@Composable
fun Modifier.textEnd(): Modifier
Set the text alignment to the start/end edge.
@Composable
fun Modifier.flexRow(): Modifier
@Composable
fun Modifier.directionalRow(): Modifier
Adds flexbox direction that respects the current layout direction.
@Composable
fun Modifier.mirrorInRtl(): Modifier
Applies CSS transform to mirror an element in RTL mode.
@Composable
fun Modifier.withDirection(): Modifier
Applies the direction attribute to an element.
@Composable
fun Modifier.directionalPadding(
start: String,
top: String,
end: String,
bottom: String
): Modifier
@Composable
fun Modifier.directionalMargin(
start: String,
top: String,
end: String,
bottom: String
): Modifier
Extension functions to apply directional padding/margin to all sides.
changeLanguagefun changeLanguage(languageCode: String): Boolean
Change the application language.
Parameters:
languageCode: The language code to switch toReturns:
true if the language was changed, false if not foundRtlUtilsobject RtlUtils
Utility class for RTL layout support.
Methods:
isRtl(): Boolean: Check if the current layout direction is RTLdirectionalValue(ltrValue: T, rtlValue: T): T: Mirror a set of values based on the current layout directionobject JsI18nImplementation
JavaScript-specific implementation for loading i18n translation files.
Methods:
init(): Initialize i18n for the JS platformloadLanguageResources(basePath: String = "/i18n/"): Load language resources from the specified base pathgetCurrentLanguage(): Language: Get the current language for JS platform