This document provides detailed API reference for the internationalization framework in Summon.
data 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 language
enum 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)
object I18nConfigConfiguration 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 builder
class I18nConfigBuilderBuilder 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 code
object StringResourcesManager 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 language
val LocalLanguage: CompositionLocal<Language>
val LocalLayoutDirection: CompositionLocal<LayoutDirection>Composition locals that provide the current language and layout direction in the composition.
@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 context
@Composable
fun stringResource(key: String): StringUtility function to get a localized string.
Parameters:
key: The translation key (e.g., "common.welcome")
Returns:
- The translated string for the current language
@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): ModifierCreates 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): ModifierAdds 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(): ModifierSet the text alignment to the start/end edge.
@Composable
fun Modifier.flexRow(): Modifier
@Composable
fun Modifier.directionalRow(): ModifierAdds flexbox direction that respects the current layout direction.
@Composable
fun Modifier.mirrorInRtl(): ModifierApplies CSS transform to mirror an element in RTL mode.
@Composable
fun Modifier.withDirection(): ModifierApplies 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
): ModifierExtension functions to apply directional padding/margin to all sides.
fun changeLanguage(languageCode: String): BooleanChange the application language.
Parameters:
languageCode: The language code to switch to
Returns:
trueif the language was changed,falseif not found
object RtlUtilsUtility 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 direction
object JsI18nImplementationJavaScript-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