From 37cf778c448863c43ba819165f73d86927029c45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20Bene=C5=A1?= Date: Tue, 10 Nov 2026 08:06:47 +0000 Subject: [PATCH] =?UTF-8?q?Language:=20the=20account's=20by=20default,=20S?= =?UTF-8?q?ettings=20=E2=80=BA=20Language,=20per-app=20locale?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- CHANGELOG.md | 9 ++ app/src/main/AndroidManifest.xml | 1 + .../main/java/eu/llembas/android/Language.kt | 109 ++++++++++++++++++ .../java/eu/llembas/android/MainActivity.kt | 31 +++++ .../llembas/android/assist/AssistActivity.kt | 4 + .../llembas/android/assist/AssistService.kt | 4 +- .../java/eu/llembas/android/auth/Instances.kt | 14 ++- .../eu/llembas/android/share/ShareActivity.kt | 4 + .../android/ui/settings/SettingsScreen.kt | 96 +++++++++++++++ app/src/main/res/values-cs/strings.xml | 7 ++ app/src/main/res/values-de/strings.xml | 7 ++ app/src/main/res/values-es/strings.xml | 7 ++ app/src/main/res/values-fr/strings.xml | 7 ++ app/src/main/res/values-hu/strings.xml | 7 ++ app/src/main/res/values-it/strings.xml | 7 ++ app/src/main/res/values-pl/strings.xml | 7 ++ app/src/main/res/values-sk/strings.xml | 7 ++ app/src/main/res/values/strings.xml | 7 ++ app/src/main/res/xml/locales_config.xml | 13 +++ .../java/eu/llembas/android/LanguageTest.kt | 53 +++++++++ .../java/eu/llembas/android/shots/Fakes.kt | 2 +- .../eu/llembas/android/shots/ScreenShots.kt | 7 ++ scripts/gen-strings.py | 13 +++ scripts/strings.py | 8 ++ scripts/strings_own.json | 40 +++++++ 25 files changed, 467 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/eu/llembas/android/Language.kt create mode 100644 app/src/main/res/xml/locales_config.xml create mode 100644 app/src/test/java/eu/llembas/android/LanguageTest.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 06c3567..6e3482b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,15 @@ is in alpha and releases come off `main`. ## [Unreleased] +### Changed + +- **The app speaks your account's language**, the one chosen on your instance, rather than the + phone's: a phone set to Slovak signed in to an English account shows the app in English. + **Settings › Language** chooses otherwise -- *Same as my account* (the default), *Phone + language*, or any language the app has, each named in itself. On Android 13 and newer the + system's own per-app language (Settings › Apps › LLeMbas › Language) offers the same + languages, and a language chosen there is kept as your choice. + ## [1.0.0-beta.4] — 2026-11-09 For LLeMbas server 2.0 (2.0.0-beta.7 or later for the Subagents setting and the panel's compaction). diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a36b2d5..3466712 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -20,6 +20,7 @@ android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher" android:label="@string/app_name" + android:localeConfig="@xml/locales_config" android:networkSecurityConfig="@xml/network_security_config" android:supportsRtl="true" android:theme="@style/Theme.Lembas"> diff --git a/app/src/main/java/eu/llembas/android/Language.kt b/app/src/main/java/eu/llembas/android/Language.kt new file mode 100644 index 0000000..1075bea --- /dev/null +++ b/app/src/main/java/eu/llembas/android/Language.kt @@ -0,0 +1,109 @@ +package eu.llembas.android + +import android.app.Activity +import android.app.LocaleManager +import android.content.Context +import android.content.res.Configuration +import android.os.Build +import android.os.LocaleList +import java.util.Locale + +/** + * The app's language. By default the account's, from the server (`/api/v2/me`'s `language`), so + * a phone set to one language shows the app in the language the person chose on their instance; + * Settings › Language can choose the phone's language instead, or any language the app has. + * + * Android 13 and newer keep a per-app language themselves (`LocaleManager`, and the system's own + * Settings › Apps › LLeMbas › Language, which `res/xml/locales_config.xml` feeds). Older phones + * have none: there the chosen language is kept in a small synchronous file and every activity + * wraps its context in it ([wrap]), because the DataStore is read too late for `attachBaseContext`. + */ +object AppLanguage { + /** Prefs.language: the account's language (the default). */ + const val ACCOUNT = "" + + /** Prefs.language: the phone's language. */ + const val PHONE = "system" + + /** + * The languages the app has, by code, each named in itself. The same set as the + * `values-*` folders `scripts/gen-strings.py` writes, plus English; a test holds them equal. + */ + val LANGUAGES: List> = listOf( + "en" to "English", + "cs" to "Čeština", + "de" to "Deutsch", + "es" to "Español", + "fr" to "Français", + "hu" to "Magyar", + "it" to "Italiano", + "pl" to "Polski", + "sk" to "Slovenčina", + ) + + private val CODES = LANGUAGES.map { it.first }.toSet() + + /** A language's own name, or null for one the app does not have. */ + fun name(code: String?): String? = LANGUAGES.firstOrNull { it.first == code?.lowercase()?.substringBefore('-')?.substringBefore('_') }?.second + + /** The app's code for a server's language (`sk`, `pt_BR` -> `pt`), or null if the app lacks it. */ + fun known(code: String?): String? = code?.trim()?.lowercase()?.substringBefore('-')?.substringBefore('_')?.takeIf { it in CODES } + + /** + * The language the app should be in: a language tag, or null for the phone's own. + * [choice] is Prefs.language; [account] the account's language as the server last said it. + * An account in a language the app does not have follows the phone, rather than English. + */ + fun effective(choice: String, account: String): String? = when (choice) { + ACCOUNT -> known(account) + PHONE -> null + else -> known(choice) + } + + private const val FILE = "language" + private const val APPLIED = "applied" + + /** What [apply] last set; null if it never ran. */ + fun applied(context: Context): String? = context.getSharedPreferences(FILE, Context.MODE_PRIVATE).getString(APPLIED, null) + + /** + * What the system says the app's language is now (Android 13+): "" for the phone's. Differs + * from [applied] when the person chose a language in the system's settings for the app. + */ + fun systemChoice(context: Context): String? { + if (Build.VERSION.SDK_INT < 33) return null + val locales = context.getSystemService(LocaleManager::class.java)?.applicationLocales ?: return null + return if (locales.isEmpty) "" else locales[0].language + } + + /** + * Put the app in [tag] (null: the phone's language). Does nothing when that is already so, + * so a running app is not recreated for nothing. Android 13+ recreates the activities + * itself; an older phone recreates [activity]. + */ + fun apply(context: Context, tag: String?, activity: Activity? = null) { + val value = tag.orEmpty() + if (applied(context) == value && (Build.VERSION.SDK_INT < 33 || systemChoice(context) == value)) return + context.getSharedPreferences(FILE, Context.MODE_PRIVATE).edit().putString(APPLIED, value).commit() + if (Build.VERSION.SDK_INT >= 33) { + context.getSystemService(LocaleManager::class.java)?.applicationLocales = + if (value.isEmpty()) LocaleList.getEmptyLocaleList() else LocaleList.forLanguageTags(value) + } else { + activity?.recreate() + } + } + + /** + * [base] in the chosen language, for `attachBaseContext` and for a window that is not an + * activity's (the assistant's sheet). Android 13+ does this itself; the context is returned + * as it is there. + */ + fun wrap(base: Context): Context { + if (Build.VERSION.SDK_INT >= 33) return base + val tag = base.getSharedPreferences(FILE, Context.MODE_PRIVATE).getString(APPLIED, null) + if (tag.isNullOrEmpty()) return base + val locale = Locale.forLanguageTag(tag) + val config = Configuration(base.resources.configuration).apply { setLocales(LocaleList(locale)) } + return base.createConfigurationContext(config) + } +} diff --git a/app/src/main/java/eu/llembas/android/MainActivity.kt b/app/src/main/java/eu/llembas/android/MainActivity.kt index 7e32876..aa44aa6 100644 --- a/app/src/main/java/eu/llembas/android/MainActivity.kt +++ b/app/src/main/java/eu/llembas/android/MainActivity.kt @@ -1,6 +1,7 @@ package eu.llembas.android import android.Manifest +import android.content.Context import android.content.Intent import android.content.pm.PackageManager import android.os.Build @@ -49,6 +50,7 @@ import eu.llembas.android.ui.scheduled.SchedulingModelsScreen import eu.llembas.android.ui.settings.SettingsScreen import eu.llembas.android.ui.signin.SignInScreen import eu.llembas.android.ui.theme.LembasTheme +import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch @@ -62,10 +64,13 @@ class MainActivity : ComponentActivity() { /** A chat or a schedule a notification, the assistant or a share asked to open; consumed once. */ private val opening = mutableStateOf(null) + override fun attachBaseContext(newBase: Context) = super.attachBaseContext(AppLanguage.wrap(newBase)) + override fun onCreate(savedInstanceState: Bundle?) { enableEdgeToEdge() super.onCreate(savedInstanceState) take(intent) + followLanguage() if (Build.VERSION.SDK_INT >= 33 && ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED ) { @@ -79,6 +84,25 @@ class MainActivity : ComponentActivity() { } } + /** + * Keep the app in the language Settings › Language says: the account's by default. A + * language chosen for the app in the system's own settings (Android 13+) since the app last + * set one is the person's choice, and is kept as such. + */ + private fun followLanguage() { + lifecycleScope.launch { + val store = lembas.instances + val system = AppLanguage.systemChoice(this@MainActivity) + if (system != null && system != AppLanguage.applied(this@MainActivity).orEmpty()) { + store.savePrefs { it.copy(language = system.ifEmpty { AppLanguage.PHONE }) } + } + store.prefs + .map { AppLanguage.effective(it.language, it.accountLanguage) } + .distinctUntilChanged() + .collect { AppLanguage.apply(applicationContext, it, this@MainActivity) } + } + } + override fun onNewIntent(intent: Intent) { super.onNewIntent(intent) take(intent) @@ -141,6 +165,13 @@ class MainActivity : ComponentActivity() { scope.launch { drawer.close() } nav.navigate(target) } + // The account's language, which the app follows unless Settings › Language says + // otherwise. Read once per instance in use; kept, so the next start has it at once. + LaunchedEffect(instance.id) { + runCatching { lembas.instances.clientFor(instance).me() }.onSuccess { me -> + if (me.language.isNotBlank()) lembas.instances.savePrefs { it.copy(accountLanguage = me.language) } + } + } // The list is read again each time the drawer opens, so a new title or a finished // reply's dot is there without a pull. LaunchedEffect(drawer.isOpen) { if (drawer.isOpen) chats.load() } diff --git a/app/src/main/java/eu/llembas/android/assist/AssistActivity.kt b/app/src/main/java/eu/llembas/android/assist/AssistActivity.kt index a783b97..29277be 100644 --- a/app/src/main/java/eu/llembas/android/assist/AssistActivity.kt +++ b/app/src/main/java/eu/llembas/android/assist/AssistActivity.kt @@ -2,6 +2,7 @@ package eu.llembas.android.assist import android.Manifest import android.app.KeyguardManager +import android.content.Context import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent @@ -20,6 +21,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.lifecycle.lifecycleScope +import eu.llembas.android.AppLanguage import eu.llembas.android.auth.Prefs import eu.llembas.android.lembas import eu.llembas.android.ui.theme.LembasTheme @@ -36,6 +38,8 @@ class AssistActivity : ComponentActivity() { if (granted) controller.listen() } + override fun attachBaseContext(newBase: Context) = super.attachBaseContext(AppLanguage.wrap(newBase)) + override fun onCreate(savedInstanceState: Bundle?) { enableEdgeToEdge() super.onCreate(savedInstanceState) diff --git a/app/src/main/java/eu/llembas/android/assist/AssistService.kt b/app/src/main/java/eu/llembas/android/assist/AssistService.kt index 871d8a6..1a53984 100644 --- a/app/src/main/java/eu/llembas/android/assist/AssistService.kt +++ b/app/src/main/java/eu/llembas/android/assist/AssistService.kt @@ -20,6 +20,7 @@ import androidx.savedstate.SavedStateRegistry import androidx.savedstate.SavedStateRegistryController import androidx.savedstate.SavedStateRegistryOwner import androidx.savedstate.setViewTreeSavedStateRegistryOwner +import eu.llembas.android.AppLanguage import eu.llembas.android.lembas import eu.llembas.android.ui.theme.LembasTheme import kotlinx.coroutines.CoroutineScope @@ -66,7 +67,8 @@ class LembasAssistSession(context: Context) : override fun onCreateContentView(): View { val theme = runBlocking { context.lembas.instances.prefs.first() }.theme - return ComposeView(context).apply { + // In the app's language on a phone older than Android 13, which has no per-app one. + return ComposeView(AppLanguage.wrap(context)).apply { setViewTreeLifecycleOwner(this@LembasAssistSession) setViewTreeSavedStateRegistryOwner(this@LembasAssistSession) setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnDetachedFromWindow) diff --git a/app/src/main/java/eu/llembas/android/auth/Instances.kt b/app/src/main/java/eu/llembas/android/auth/Instances.kt index bd4796c..0677641 100644 --- a/app/src/main/java/eu/llembas/android/auth/Instances.kt +++ b/app/src/main/java/eu/llembas/android/auth/Instances.kt @@ -66,9 +66,19 @@ private val INSTANCES = stringPreferencesKey("instances") private val ACTIVE = stringPreferencesKey("active") private val PREFS = stringPreferencesKey("prefs") -/** What the person chose in Settings, for this phone. */ +/** + * What the person chose in Settings, for this phone. [language]: "" the account's language (the + * default), "system" the phone's, or a language's code -- see [eu.llembas.android.AppLanguage]. + * [accountLanguage] is the account's language as the instance in use last said it. + */ @Serializable -data class Prefs(val theme: String = "", val assistantTemporary: Boolean = false, val readAloudSpoken: Boolean = true) +data class Prefs( + val theme: String = "", + val assistantTemporary: Boolean = false, + val readAloudSpoken: Boolean = true, + val language: String = "", + val accountLanguage: String = "", +) class InstanceStore(private val context: Context) { private val listSerializer = ListSerializer(Instance.serializer()) diff --git a/app/src/main/java/eu/llembas/android/share/ShareActivity.kt b/app/src/main/java/eu/llembas/android/share/ShareActivity.kt index 93fd504..4f97004 100644 --- a/app/src/main/java/eu/llembas/android/share/ShareActivity.kt +++ b/app/src/main/java/eu/llembas/android/share/ShareActivity.kt @@ -1,5 +1,6 @@ package eu.llembas.android.share +import android.content.Context import android.content.Intent import android.net.Uri import android.os.Bundle @@ -22,6 +23,7 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.core.content.IntentCompat import androidx.lifecycle.lifecycleScope +import eu.llembas.android.AppLanguage import eu.llembas.android.MainActivity import eu.llembas.android.R import eu.llembas.android.lembas @@ -39,6 +41,8 @@ import kotlinx.coroutines.withContext class ShareActivity : ComponentActivity() { private val failure = mutableStateOf(null) + override fun attachBaseContext(newBase: Context) = super.attachBaseContext(AppLanguage.wrap(newBase)) + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { diff --git a/app/src/main/java/eu/llembas/android/ui/settings/SettingsScreen.kt b/app/src/main/java/eu/llembas/android/ui/settings/SettingsScreen.kt index 8bd5d85..bd17068 100644 --- a/app/src/main/java/eu/llembas/android/ui/settings/SettingsScreen.kt +++ b/app/src/main/java/eu/llembas/android/ui/settings/SettingsScreen.kt @@ -34,10 +34,12 @@ import androidx.compose.material.icons.filled.Palette import androidx.compose.material.icons.filled.RecordVoiceOver import androidx.compose.material.icons.filled.SystemUpdate import androidx.compose.material.icons.filled.Timer +import androidx.compose.material.icons.filled.Translate import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.ModalBottomSheet import androidx.compose.material3.RadioButton import androidx.compose.material3.Scaffold import androidx.compose.material3.Surface @@ -45,6 +47,7 @@ import androidx.compose.material3.Switch import androidx.compose.material3.Text import androidx.compose.material3.TopAppBar import androidx.compose.material3.TopAppBarDefaults +import androidx.compose.material3.rememberModalBottomSheetState import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue @@ -62,6 +65,7 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp +import eu.llembas.android.AppLanguage import eu.llembas.android.BuildConfig import eu.llembas.android.R import eu.llembas.android.auth.Instance @@ -78,6 +82,7 @@ interface SettingsActions { fun add() {} fun signOut(instance: Instance) {} fun theme(value: String) {} + fun language(value: String) {} fun enablePush(instance: Instance) {} fun notificationSettings() {} fun assistantSettings() {} @@ -129,6 +134,11 @@ fun SettingsScreen(onBack: () -> Unit, onAddInstance: () -> Unit) { scope.launch { store.savePrefs { it.copy(theme = value) } } } + // MainActivity follows the choice: it puts the app in the language at once. + override fun language(value: String) { + scope.launch { store.savePrefs { it.copy(language = value) } } + } + override fun enablePush(instance: Instance) { (context as? Activity)?.let { activity -> Push.enable(activity, instance) { ok -> pushNote = context.getString(if (ok) R.string.push_on else R.string.push_failed) } @@ -184,6 +194,15 @@ fun SettingsScreen(onBack: () -> Unit, onAddInstance: () -> Unit) { @Composable fun SettingsContent(state: SettingsState, actions: SettingsActions, onBack: () -> Unit = {}) { val palette = LocalPalette.current + var choosingLanguage by remember { mutableStateOf(false) } + if (choosingLanguage) { + ModalBottomSheet(onDismissRequest = { choosingLanguage = false }, sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)) { + LanguageChoices(state.prefs, onPick = { + choosingLanguage = false + actions.language(it) + }) + } + } Scaffold( containerColor = palette.bg, topBar = { @@ -248,6 +267,16 @@ fun SettingsContent(state: SettingsState, actions: SettingsActions, onBack: () - } } } + item { + Group(stringResource(R.string.settings_language)) { + SettingRow( + Icons.Filled.Translate, + languageLabel(state.prefs), + subtitle = stringResource(R.string.language_hint), + onClick = { choosingLanguage = true }, + ) + } + } item { Group(stringResource(R.string.settings_theme)) { listOf("" to R.string.theme_system, "moria" to R.string.theme_moria, "shire" to R.string.theme_shire).forEachIndexed { i, (value, label) -> @@ -394,3 +423,70 @@ private fun Initial(name: String) { Text(name.trim().firstOrNull()?.uppercase() ?: "?", style = MaterialTheme.typography.titleMedium, color = palette.accent) } } + +/** The phone's own language, named in itself: what "Phone language" would show. */ +private fun phoneLanguage(): String { + val locale = android.content.res.Resources.getSystem().configuration.locales[0] + return locale.getDisplayName(locale).replaceFirstChar { it.titlecase(locale) } +} + +/** The language row's words: what is chosen, and for the account's, which language that is. */ +@Composable +private fun languageLabel(prefs: Prefs): String = when (prefs.language) { + AppLanguage.ACCOUNT -> AppLanguage.name(prefs.accountLanguage)?.let { stringResource(R.string.language_account_is, it) } + ?: stringResource(R.string.language_account) + + AppLanguage.PHONE -> stringResource(R.string.language_phone_is, phoneLanguage()) + + else -> AppLanguage.name(prefs.language) ?: stringResource(R.string.language_account) +} + +/** + * Settings › Language, as a sheet: the account's language (the default), the phone's, then every + * language the app has, each named in itself so a person who cannot read the current one still + * finds theirs. + */ +@Composable +fun LanguageChoices(prefs: Prefs, onPick: (String) -> Unit) { + val palette = LocalPalette.current + val choices = buildList { + add( + Triple( + AppLanguage.ACCOUNT, + stringResource(R.string.language_account), + AppLanguage.name(prefs.accountLanguage) ?: stringResource(R.string.language_account_unknown), + ), + ) + add(Triple(AppLanguage.PHONE, stringResource(R.string.language_phone), phoneLanguage())) + AppLanguage.LANGUAGES.forEach { (code, name) -> add(Triple(code, name, null)) } + } + LazyColumn(Modifier.fillMaxWidth(), contentPadding = PaddingValues(bottom = 24.dp)) { + item { + Text( + stringResource(R.string.settings_language), + style = MaterialTheme.typography.titleMedium, + modifier = Modifier.padding(start = 24.dp, end = 24.dp, bottom = 8.dp), + ) + } + choices.forEachIndexed { i, (value, title, subtitle) -> + item(key = "lang-$value-$i") { + if (i == 2) HorizontalDivider(color = palette.border, modifier = Modifier.padding(vertical = 4.dp)) + Row( + Modifier + .fillMaxWidth() + .clickable { onPick(value) } + .heightIn(min = 56.dp) + .padding(horizontal = 24.dp, vertical = 8.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + Column(Modifier.weight(1f)) { + Text(title, style = MaterialTheme.typography.bodyLarge) + subtitle?.let { Text(it, style = MaterialTheme.typography.bodyMedium, color = palette.inkMuted) } + } + Spacer(Modifier.width(12.dp)) + RadioButton(selected = prefs.language == value, onClick = { onPick(value) }) + } + } + } + } +} diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 2d66e80..e39817f 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -235,6 +235,13 @@ Podle systému Moria (temná) Shire (světlý) + Jazyk + Jen rozhraní. Modely odpovídají v jazyce, ve kterém jim píšete, bez ohledu na toto nastavení. + Stejný jako můj účet + Stejný jako můj účet: %1$s + Z vaší instance zatím nenačteno + Jazyk telefonu + Jazyk telefonu: %1$s Upozornění Upozornění chodí přes UnifiedPush, bez služeb Google: doručuje je distribuční aplikace, kterou jste zvolili; jsou zašifrované jen pro tento telefon. Abyste se dozvěděli, že je odpověď hotová, nainstalujte distributora UnifiedPush, například ntfy, a pak se vraťte sem. Bez něj aplikace nové odpovědi ukáže, jen když je otevřená. diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 9e1506d..27b1f81 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -235,6 +235,13 @@ Wie das System Moria (dunkel) Shire (hell) + Sprache + Nur die Oberfläche. Modelle antworten in der Sprache, in der Sie ihnen schreiben, egal was hier steht. + Wie mein Konto + Wie mein Konto: %1$s + Noch nicht von Ihrer Instanz gelesen + Sprache des Telefons + Sprache des Telefons: %1$s Benachrichtigungen Benachrichtigungen kommen über UnifiedPush, ohne Google-Dienste: Die von Ihnen gewählte Distributor-App trägt sie, verschlüsselt nur für dieses Telefon. Um erfahren zu lassen, wenn eine Antwort fertig ist, installieren Sie einen UnifiedPush-Distributor wie ntfy und kommen Sie dann hierher zurück. Ohne einen zeigt die App neue Antworten nur, wenn sie geöffnet ist. diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 9a2f38a..0c61f9d 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -235,6 +235,13 @@ Como el sistema Moria (oscuro) Shire (claro) + Idioma + Solo la interfaz. Los modelos responden en el idioma en el que usted les escribe, diga lo que diga esto. + Igual que mi cuenta + Igual que mi cuenta: %1$s + Aún no se ha leído de su instancia + Idioma del teléfono + Idioma del teléfono: %1$s Notificaciones Las notificaciones llegan mediante UnifiedPush, sin servicios de Google: la aplicación distribuidora que eligió las transporta, cifradas solo para este teléfono. Para que le avisen cuando una respuesta esté lista, instale un distribuidor de UnifiedPush como ntfy y luego vuelva aquí. Sin uno, la aplicación muestra las respuestas nuevas solo cuando está abierta. diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 8c9abb5..641c664 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -235,6 +235,13 @@ Comme le système Moria (sombre) Shire (clair) + Langue + L\'interface uniquement. Les modèles répondent dans la langue dans laquelle vous leur écrivez, quoi qu\'indique ce réglage. + Comme mon compte + Comme mon compte : %1$s + Pas encore lue sur votre instance + Langue du téléphone + Langue du téléphone : %1$s Notifications Les notifications arrivent par UnifiedPush, sans services Google : l\'application distributrice que vous avez choisie les transporte, chiffrées pour ce téléphone uniquement. Pour être averti quand une réponse est prête, installez un distributeur UnifiedPush tel que ntfy, puis revenez ici. Sans cela, l\'application affiche les nouvelles réponses seulement quand elle est ouverte. diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index da829a2..de9b8ed 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -235,6 +235,13 @@ A rendszer szerint Moria (sötét) Shire (világos) + Nyelv + Csak a felület. A modellek azon a nyelven válaszolnak, amelyen ír nekik, függetlenül ettől a beállítástól. + Ugyanaz, mint a fiókomé + Ugyanaz, mint a fiókomé: %1$s + Még nincs beolvasva a példányáról + A telefon nyelve + A telefon nyelve: %1$s Értesítések Az értesítések a UnifiedPush-on keresztül érkeznek, Google-szolgáltatások nélkül: az Ön által választott elosztó alkalmazás szállítja őket, titkosítva, csak ehhez a telefonhoz. Hogy értesítést kapjon, amikor egy válasz elkészül, telepítsen egy UnifiedPush-elosztót, például az ntfy-t, majd jöjjön vissza ide. Ha nincs ilyen, az alkalmazás csak akkor mutatja az új válaszokat, amikor meg van nyitva. diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 13ba480..de75584 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -235,6 +235,13 @@ Come il sistema Moria (scuro) Shire (chiaro) + Lingua + Solo l\'interfaccia. I modelli rispondono nella lingua in cui scrivi loro, qualunque cosa dica questa impostazione. + Come il mio account + Come il mio account: %1$s + Non ancora letta dalla sua istanza + Lingua del telefono + Lingua del telefono: %1$s Notifiche Le notifiche arrivano tramite UnifiedPush, senza servizi Google: l\'app di distribuzione che hai scelto le trasporta, cifrate solo per questo telefono. Per essere avvisato quando una risposta è pronta, installa un distributore UnifiedPush come ntfy, poi torna qui. Senza uno, l\'app mostra le nuove risposte solo quando è aperta. diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 5093559..9701d2c 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -235,6 +235,13 @@ Jak system Moria (ciemny) Shire (jasny) + Język + Tylko interfejs. Modele odpowiadają w języku, w którym się do nich pisze, bez względu na to ustawienie. + Tak jak moje konto + Tak jak moje konto: %1$s + Jeszcze nie odczytano z Twojej instancji + Język telefonu + Język telefonu: %1$s Powiadomienia Powiadomienia przychodzą przez UnifiedPush, bez usług Google: niesie je wybrana aplikacja dystrybucyjna, zaszyfrowane tylko dla tego telefonu. Aby dostawać informacje, kiedy odpowiedź jest gotowa, zainstaluj dystrybutora UnifiedPush, na przykład ntfy, a potem wróć tutaj. Bez niego aplikacja pokazuje nowe odpowiedzi tylko wtedy, gdy jest otwarta. diff --git a/app/src/main/res/values-sk/strings.xml b/app/src/main/res/values-sk/strings.xml index 17a5e90..aa1e72e 100644 --- a/app/src/main/res/values-sk/strings.xml +++ b/app/src/main/res/values-sk/strings.xml @@ -235,6 +235,13 @@ Podľa systému Moria (tmavá) Shire (svetlá) + Jazyk + Len rozhranie. Modely odpovedajú v jazyku, v ktorom im píšete, bez ohľadu na toto nastavenie. + Rovnaký ako môj účet + Rovnaký ako môj účet: %1$s + Z vašej inštancie ešte nenačítaný + Jazyk telefónu + Jazyk telefónu: %1$s Upozornenia Upozornenia chodia cez UnifiedPush, bez služieb Google: doručuje ich distribučná aplikácia, ktorú ste zvolili, zašifrované len pre tento telefón. Aby ste sa dozvedeli, že je odpoveď hotová, nainštalujte distributora UnifiedPush, napríklad ntfy, a potom sa vráťte sem. Bez neho aplikácia nové odpovede ukáže, len keď je otvorená. diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 73cc7ad..849c8ee 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -236,6 +236,13 @@ As the system Moria (dark) Shire (light) + Language + The interface only. Models answer in the language you write to them in, whatever this says. + Same as my account + Same as my account: %1$s + Not read from your instance yet + Phone language + Phone language: %1$s Notifications Notifications come through UnifiedPush, with no Google services: the distributor app you chose carries them, encrypted for this phone only. To be told when a reply is ready, install a UnifiedPush distributor such as ntfy, then come back here. Without one, the app shows new replies when it is open. diff --git a/app/src/main/res/xml/locales_config.xml b/app/src/main/res/xml/locales_config.xml new file mode 100644 index 0000000..0350aa9 --- /dev/null +++ b/app/src/main/res/xml/locales_config.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/app/src/test/java/eu/llembas/android/LanguageTest.kt b/app/src/test/java/eu/llembas/android/LanguageTest.kt new file mode 100644 index 0000000..5e8ea27 --- /dev/null +++ b/app/src/test/java/eu/llembas/android/LanguageTest.kt @@ -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) + } +} diff --git a/app/src/test/java/eu/llembas/android/shots/Fakes.kt b/app/src/test/java/eu/llembas/android/shots/Fakes.kt index 16f095b..c7f7f43 100644 --- a/app/src/test/java/eu/llembas/android/shots/Fakes.kt +++ b/app/src/test/java/eu/llembas/android/shots/Fakes.kt @@ -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, diff --git a/app/src/test/java/eu/llembas/android/shots/ScreenShots.kt b/app/src/test/java/eu/llembas/android/shots/ScreenShots.kt index 78fecaa..2338523 100644 --- a/app/src/test/java/eu/llembas/android/shots/ScreenShots.kt +++ b/app/src/test/java/eu/llembas/android/shots/ScreenShots.kt @@ -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) } diff --git a/scripts/gen-strings.py b/scripts/gen-strings.py index eb86f45..070d31b 100755 --- a/scripts/gen-strings.py +++ b/scripts/gen-strings.py @@ -103,6 +103,18 @@ def write(folder: Path, entries: dict[str, str]) -> None: (folder / "strings.xml").write_text("\n".join(lines) + "\n", encoding="utf-8") +def write_locale_config() -> None: + """`res/xml/locales_config.xml`: the languages the app has, for Android 13+'s per-app language + (the manifest's `android:localeConfig`). Written from LANGS, so it cannot list a language + the app has no strings for, or miss one it has.""" + lines = ['', HEADER.replace("Edit scripts/strings.py or strings_own.json", "Edit LANGS there"), + '', + ' '] + lines += [f' ' for code in LANGS] + lines.append("") + (RES / "xml/locales_config.xml").write_text("\n".join(lines) + "\n", encoding="utf-8") + + def main() -> None: used = used_keys() missing = sorted(used - set(STRINGS)) @@ -123,6 +135,7 @@ def main() -> None: ).stdout.strip() own = json.loads((Path(__file__).parent / "strings_own.json").read_text(encoding="utf-8")) write(RES / "values", STRINGS) + write_locale_config() for code in LANGS: catalogue = server_catalogue(code, ref) mine = own.get(code, {}) diff --git a/scripts/strings.py b/scripts/strings.py index e923f16..eaf5315 100755 --- a/scripts/strings.py +++ b/scripts/strings.py @@ -255,6 +255,14 @@ STRINGS: dict[str, str] = { "theme_system": "As the system", "theme_moria": "Moria (dark)", "theme_shire": "Shire (light)", + # Language + "settings_language": "Language", + "language_hint": "The interface only. Models answer in the language you write to them in, whatever this says.", + "language_account": "Same as my account", + "language_account_is": "Same as my account: %1$s", + "language_account_unknown": "Not read from your instance yet", + "language_phone": "Phone language", + "language_phone_is": "Phone language: %1$s", "settings_notifications": "Notifications", "push_explained": "Notifications come through UnifiedPush, with no Google services: the distributor app you chose carries them, encrypted for this phone only.", "push_no_distributor": "To be told when a reply is ready, install a UnifiedPush distributor such as ntfy, then come back here. Without one, the app shows new replies when it is open.", diff --git a/scripts/strings_own.json b/scripts/strings_own.json index b1218e8..d1880e4 100644 --- a/scripts/strings_own.json +++ b/scripts/strings_own.json @@ -48,6 +48,11 @@ "empty_chat": "O čem si promluvíme?", "empty_chats": "Zatím žádné konverzace. Ne všichni, kdo bloudí, jsou ztraceni — založte jednu.", "instance_in_use": "Používá se", + "language_account": "Stejný jako můj účet", + "language_account_is": "Stejný jako můj účet: %1$s", + "language_account_unknown": "Z vaší instance zatím nenačteno", + "language_phone": "Jazyk telefonu", + "language_phone_is": "Jazyk telefonu: %1$s", "listening": "Naslouchám…", "loading_line": "Pečou se lembasy…", "mode_continue": "Jeden chat, který roste", @@ -215,6 +220,11 @@ "empty_chat": "Worüber sprechen wir?", "empty_chats": "Noch keine Chats. Nicht jeder, der wandert, ist verloren — fangen Sie einen an.", "instance_in_use": "In Verwendung", + "language_account": "Wie mein Konto", + "language_account_is": "Wie mein Konto: %1$s", + "language_account_unknown": "Noch nicht von Ihrer Instanz gelesen", + "language_phone": "Sprache des Telefons", + "language_phone_is": "Sprache des Telefons: %1$s", "listening": "Hört zu…", "loading_line": "Lembas wird gebacken…", "mode_continue": "Ein Chat, der wächst", @@ -383,6 +393,11 @@ "empty_chat": "¿De qué hablamos?", "empty_chats": "Aún no hay chats. No todos los que vagan están perdidos — empiece uno.", "instance_in_use": "En uso", + "language_account": "Igual que mi cuenta", + "language_account_is": "Igual que mi cuenta: %1$s", + "language_account_unknown": "Aún no se ha leído de su instancia", + "language_phone": "Idioma del teléfono", + "language_phone_is": "Idioma del teléfono: %1$s", "listening": "Escuchando…", "loading_line": "Horneando lembas…", "mode_continue": "Un chat que crece", @@ -550,6 +565,11 @@ "empty_chat": "De quoi allons-nous parler ?", "empty_chats": "Pas encore de conversation. Tous ceux qui errent ne sont pas perdus — commencez-en une.", "instance_in_use": "Utilisée", + "language_account": "Comme mon compte", + "language_account_is": "Comme mon compte : %1$s", + "language_account_unknown": "Pas encore lue sur votre instance", + "language_phone": "Langue du téléphone", + "language_phone_is": "Langue du téléphone : %1$s", "listening": "Écoute…", "loading_line": "Cuisson des lembas…", "mode_continue": "Une discussion qui s’allonge", @@ -718,6 +738,11 @@ "empty_chat": "Miről beszéljünk?", "empty_chats": "Még nincs csevegés. Nem mindenki van elveszve, aki bolyong — kezdjen el egyet.", "instance_in_use": "Használatban", + "language_account": "Ugyanaz, mint a fiókomé", + "language_account_is": "Ugyanaz, mint a fiókomé: %1$s", + "language_account_unknown": "Még nincs beolvasva a példányáról", + "language_phone": "A telefon nyelve", + "language_phone_is": "A telefon nyelve: %1$s", "listening": "Hallgatja…", "loading_line": "Lembas sül…", "mode_continue": "Egy csevegés, amely bővül", @@ -886,6 +911,11 @@ "empty_chat": "Di cosa parliamo?", "empty_chats": "Ancora nessuna chat. Non tutti quelli che vagano sono perduti — iniziane una.", "instance_in_use": "In uso", + "language_account": "Come il mio account", + "language_account_is": "Come il mio account: %1$s", + "language_account_unknown": "Non ancora letta dalla sua istanza", + "language_phone": "Lingua del telefono", + "language_phone_is": "Lingua del telefono: %1$s", "listening": "In ascolto…", "loading_line": "I lembas stanno cuocendo…", "mode_continue": "Una chat che cresce", @@ -1053,6 +1083,11 @@ "empty_chat": "O czym porozmawiamy?", "empty_chats": "Nie ma jeszcze czatów. Nie każdy, kto błądzi, jest zgubiony — zacznij jeden.", "instance_in_use": "W użyciu", + "language_account": "Tak jak moje konto", + "language_account_is": "Tak jak moje konto: %1$s", + "language_account_unknown": "Jeszcze nie odczytano z Twojej instancji", + "language_phone": "Język telefonu", + "language_phone_is": "Język telefonu: %1$s", "listening": "Słucham…", "loading_line": "Lembasy się pieczą…", "mode_continue": "Jeden czat, który rośnie", @@ -1220,6 +1255,11 @@ "empty_chat": "O čom sa pozhovárame?", "empty_chats": "Zatiaľ žiadne konverzácie. Nie všetci, čo blúdia, sú stratení — začnite jednu.", "instance_in_use": "Používa sa", + "language_account": "Rovnaký ako môj účet", + "language_account_is": "Rovnaký ako môj účet: %1$s", + "language_account_unknown": "Z vašej inštancie ešte nenačítaný", + "language_phone": "Jazyk telefónu", + "language_phone_is": "Jazyk telefónu: %1$s", "listening": "Počúvam…", "loading_line": "Pečú sa lembasy…", "mode_continue": "Jedna konverzácia, ktorá rastie",