Language: the account's by default, Settings › Language, per-app locale
CI / check (push) Canceled after 0s

The app followed the phone's locale, so a Slovak phone showed Slovak while the
instance and the account were English. Now the default is the account's
language from /api/v2/me (read once per instance in use, kept in Prefs), and
Settings › Language offers Same as my account / Phone language / each language
the app has, named in itself.

Android 13+: LocaleManager.setApplicationLocales, and android:localeConfig
(res/xml/locales_config.xml, written by gen-strings.py from LANGS) so the
system's per-app language lists the same set; a choice made there is adopted
as the person's. Older phones: the chosen tag in a small synchronous file,
applied in attachBaseContext of every activity and to the assistant's window.
No AppCompat: the framework API covers it.

LanguageTest holds the offered list, the values-* folders and the locale
config equal. Screenshot 17-language.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Opus 5.5 committed 2026-11-10 08:06:47 +00:00
1 parent 6828dbd844
commit 37cf778c44
25 files changed
+467 -4

No files matched your search

@@ -0,0 +1,53 @@
package eu.llembas.android
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
import java.io.File
class LanguageTest {
@Test
fun theAccountsLanguageIsTheDefault() {
assertEquals("en", AppLanguage.effective(AppLanguage.ACCOUNT, "en"))
assertEquals("sk", AppLanguage.effective(AppLanguage.ACCOUNT, "sk"))
// A server language written with a region still names one the app has.
assertEquals("cs", AppLanguage.effective(AppLanguage.ACCOUNT, "cs_CZ"))
}
@Test
fun anUnknownOrUnreadAccountLanguageFollowsThePhone() {
assertNull(AppLanguage.effective(AppLanguage.ACCOUNT, ""))
assertNull(AppLanguage.effective(AppLanguage.ACCOUNT, "ja"))
}
@Test
fun aChoiceBeatsTheAccount() {
assertNull(AppLanguage.effective(AppLanguage.PHONE, "en"))
assertEquals("de", AppLanguage.effective("de", "en"))
// A code the app no longer has (a newer build's choice, say) follows the phone.
assertNull(AppLanguage.effective("ja", "en"))
}
@Test
fun everyLanguageIsNamedInItself() {
assertEquals("Slovenčina", AppLanguage.name("sk"))
assertEquals("English", AppLanguage.name("en-GB"))
assertNull(AppLanguage.name("ja"))
}
/** The list Settings offers, the strings gen-strings.py writes, and the locale config agree. */
@Test
fun theLanguagesAreTheOnesTheAppHasStringsFor() {
val res = File("src/main/res")
val folders = res.listFiles().orEmpty()
.map { it.name }
.filter { it.startsWith("values-") && File(res, "$it/strings.xml").exists() }
.map { it.removePrefix("values-") }
.toSet()
val offered = AppLanguage.LANGUAGES.map { it.first }.toSet()
assertEquals(offered - "en", folders)
val config = File(res, "xml/locales_config.xml").readText()
val listed = Regex("""android:name="([a-z]+)"""").findAll(config).map { it.groupValues[1] }.toSet()
assertEquals(offered, listed)
}
}
@@ -213,7 +213,7 @@ object Fakes {
val settings = SettingsState(
instances = listOf(home, work),
active = home,
prefs = Prefs(theme = "", assistantTemporary = true),
prefs = Prefs(theme = "", assistantTemporary = true, accountLanguage = "en"),
hasDistributor = true,
version = "1.0.0-beta.3",
selfUpdate = true,
@@ -30,6 +30,7 @@ import eu.llembas.android.ui.scheduled.ScheduleContent
import eu.llembas.android.ui.scheduled.ScheduleEditContent
import eu.llembas.android.ui.scheduled.ScheduledContent
import eu.llembas.android.ui.scheduled.SchedulingModelsContent
import eu.llembas.android.ui.settings.LanguageChoices
import eu.llembas.android.ui.settings.SettingsActions
import eu.llembas.android.ui.settings.SettingsContent
import eu.llembas.android.ui.theme.LocalPalette
@@ -119,6 +120,12 @@ class ScreenShots {
shoot("08-settings", Phone.Small) { SettingsContent(Fakes.settings, NoSettingsActions) }
}
@Test
fun language() {
shoot("17-language", Phone.Scroll) { SheetOver { LanguageChoices(Fakes.settings.prefs, onPick = {}) } }
shoot("17-language", Phone.Small, fontScale = 1.5f) { SheetOver { LanguageChoices(Fakes.settings.prefs, onPick = {}) } }
}
@Test
fun scheduled() {
shoot("09-scheduled") { ScheduledContent(Fakes.scheduled) }