diff --git a/examples/llama.android/app/src/main/java/com/example/llama/revamp/ui/components/ModelCards.kt b/examples/llama.android/app/src/main/java/com/example/llama/revamp/ui/components/ModelCards.kt index 03ff799087..ebd5583601 100644 --- a/examples/llama.android/app/src/main/java/com/example/llama/revamp/ui/components/ModelCards.kt +++ b/examples/llama.android/app/src/main/java/com/example/llama/revamp/ui/components/ModelCards.kt @@ -40,6 +40,7 @@ import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import com.example.llama.revamp.data.model.ModelInfo +import com.example.llama.revamp.util.languageCodeToFlagEmoji import java.text.SimpleDateFormat import java.util.Date import java.util.Locale @@ -333,12 +334,12 @@ fun ModelCardContentLanguagesSections(languages: List) = horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp) ) { - languages.forEach { language -> + languages.mapNotNull { languageCodeToFlagEmoji(it) }.forEach { emoji -> AssistChip( onClick = { /* No action */ }, label = { Text( - text = language, + text = emoji, style = MaterialTheme.typography.bodySmall, fontStyle = FontStyle.Italic, fontWeight = FontWeight.Light, diff --git a/examples/llama.android/app/src/main/java/com/example/llama/revamp/util/FormatUtils.kt b/examples/llama.android/app/src/main/java/com/example/llama/revamp/util/FormatUtils.kt index c91517221d..ba817dd832 100644 --- a/examples/llama.android/app/src/main/java/com/example/llama/revamp/util/FormatUtils.kt +++ b/examples/llama.android/app/src/main/java/com/example/llama/revamp/util/FormatUtils.kt @@ -46,3 +46,62 @@ fun formatContextLength(contextLength: Int): String { else -> contextLength.toString() } } + + +/** + * Maps ISO 639-1 language codes into ISO 3166-1 alpha-2 country codes, and then map to Emoji. + * + */ +fun languageCodeToFlagEmoji(languageCode: String): String? { + val countryCode = LANGUAGE_TO_COUNTRY[languageCode.lowercase()] ?: return null + + return countryCodeToFlagEmoji(countryCode) +} + +/** + * Formats ISO 3166-1 alpha-2 country code into corresponding Emoji. + */ +private fun countryCodeToFlagEmoji(countryCode: String): String? { + if (countryCode.length != 2) return null + + // Convert each character to a Regional Indicator Symbol + val firstChar = Character.codePointAt(countryCode.uppercase(), 0) - 'A'.code + 0x1F1E6 + val secondChar = Character.codePointAt(countryCode.uppercase(), 1) - 'A'.code + 0x1F1E6 + + return String(Character.toChars(firstChar)) + String(Character.toChars(secondChar)) +} + +private val LANGUAGE_TO_COUNTRY by lazy { + mapOf( + "en" to "US", + "de" to "DE", + "fr" to "FR", + "it" to "IT", + "es" to "ES", + "pt" to "BR", + "hi" to "IN", + "th" to "TH", + "ja" to "JP", + "ko" to "KR", + "zh" to "CN", + "ru" to "RU", + "ar" to "SA", + "nl" to "NL", + "sv" to "SE", + "fi" to "FI", + "pl" to "PL", + "tr" to "TR", + "vi" to "VN", + "el" to "GR", + "he" to "IL", + "id" to "ID", + "ms" to "MY", + "no" to "NO", + "da" to "DK", + "cs" to "CZ", + "hu" to "HU", + "ro" to "RO", + "sk" to "SK", + "uk" to "UA", + ) +}