Language setting: name the system language without its region

This commit is contained in:
maxjivi05 committed 2026-10-04 22:30:42 -04:00
1 parent 1addb5c848
commit 0fc6ccb6f4
2 files changed
+17 -1

No files matched your search

@@ -97,6 +97,22 @@ object AppLanguage {
// 0 leaves it undefined, so only the locale is changed.
private fun override(locale: Locale) = Configuration().apply { fontScale = 0f; setLocales(LocaleList(locale)) }
/** Which of the app's languages [locale] reads as, or null when the app does not ship it. */
fun supportedTag(locale: Locale): String? = when (locale.language) {
"en", "es", "ja", "ko" -> locale.language
"zh" -> when {
locale.script == "Hans" -> "zh-CN"
locale.country == "HK" || locale.country == "MO" -> "zh-HK"
locale.script == "Hant" || locale.country == "TW" -> "zh-TW"
else -> "zh-CN"
}
else -> null
}
/** [locale]'s language named in itself, without its region unless the app tells them apart. */
fun displayName(locale: Locale): String =
supportedTag(locale)?.let(::nativeName) ?: locale.getDisplayLanguage(locale).replaceFirstChar { it.titlecase(locale) }
/** A language's name in that language, for the picker: what a reader of it looks for. */
fun nativeName(tag: String): String = when (tag) {
"en" -> "English"
@@ -474,7 +474,7 @@ private fun SettingCard(label: String, value: String, id: String, modifier: Modi
@Composable
private fun LanguageRow(host: MenuHost, chosen: String, onPick: (String) -> Unit) {
val context = androidx.compose.ui.platform.LocalContext.current
val systemName = AppLanguage.system(context).let { it.getDisplayName(it) }
val systemName = AppLanguage.displayName(AppLanguage.system(context))
val systemLabel = stringResource(R.string.setup_language_system, systemName)
SettingsRow(stringResource(R.string.setup_language), stringResource(R.string.setup_language_hint)) {
Box {