Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.
build(i18n): generate the app's LocaleConfig from its translations
Durganshud1a87c1800d2
diff --git a/app/build.gradle.kts b/app/build.gradle.ktsindex 35f62db..9dc2167 100644--- a/app/build.gradle.kts+++ b/app/build.gradle.kts@@ -185,6 +185,13 @@ android {}}+ // Builds the app's LocaleConfig from the values-<lang>/ folders, so Android 13++ // lists Gotcha under per-app languages with exactly the translations it ships.+ // Default (unqualified) strings are English; see res/resources.properties.+ androidResources {+ generateLocaleConfig = true+ }+lint {abortOnError = truewarningsAsErrors = falsediff --git a/app/src/main/java/com/gotcha/ui/LanguageScreen.kt b/app/src/main/java/com/gotcha/ui/LanguageScreen.ktindex 6ce6797..799d664 100644--- a/app/src/main/java/com/gotcha/ui/LanguageScreen.kt+++ b/app/src/main/java/com/gotcha/ui/LanguageScreen.kt@@ -388,11 +388,14 @@ internal fun transcriptionOverrideHint(provider: AudioProvider): String = when {* language list. If neither activity can be started, a toast says so.** Android 13+ shows the per-app screen only for apps that declare their locales- * (a `LocaleConfig`). Gotcha declares none, because its UI is English only, so- * Settings refuses the screen. Stock builds still draw a picker whose choices do- * nothing, and some OEM builds (Nothing OS) close it at once: a blank flash, and- * no exception for us to fall back on (issue #112). So the per-app screen is only- * tried when [appHasLocales] says the app declares more than one locale.+ * (a `LocaleConfig`). The build generates Gotcha's from its `values-<lang>/`+ * folders, so until a translation ships it lists English alone. With nothing to+ * choose, stock builds draw a picker whose choices do nothing, and some OEM builds+ * (Nothing OS) close it at once: a blank flash, and no exception for us to fall+ * back on (issue #112). So the per-app screen is only tried when [appHasLocales]+ * says the app declares more than one locale, which turns it on by itself once+ * the first translation is added. Android 11 and 12 have no per-app screen and+ * always get the device-wide one.*/internal fun openLanguageSettings(context: Context,diff --git a/app/src/main/res/resources.properties b/app/src/main/res/resources.propertiesnew file mode 100644index 0000000..467b3ef--- /dev/null+++ b/app/src/main/res/resources.properties@@ -0,0 +1 @@+unqualifiedResLocale=en-USdiff --git a/app/src/test/java/com/gotcha/i18n/AppLocalesTest.kt b/app/src/test/java/com/gotcha/i18n/AppLocalesTest.ktnew file mode 100644index 0000000..0b6d304--- /dev/null+++ b/app/src/test/java/com/gotcha/i18n/AppLocalesTest.kt@@ -0,0 +1,72 @@+package com.gotcha.i18n++import org.junit.Assert.assertEquals+import org.junit.Assert.assertTrue+import org.junit.Test+import java.io.File+import java.util.Properties++/**+ * The app's display languages are the `values-<lang>/` folders: the build turns+ * them into the LocaleConfig Android reads for per-app languages+ * (`generateLocaleConfig`). The interface may only be offered in a language+ * Gotcha can also speak and hear, so every such folder has to name a [Language].+ */+class AppLocalesTest {++ // Unit tests run with the module directory as the working directory.+ private val resDir = File("src/main/res")++ /** Language subtag of each `values-*` folder that carries a locale qualifier. */+ private fun translatedLanguages(): Map<String, String> =+ resDir.listFiles().orEmpty()+ .filter { it.isDirectory && it.name.startsWith("values-") }+ .mapNotNull { dir -> localeOf(dir.name)?.let { dir.name to it } }+ .toMap()++ /**+ * `values-hi`, `values-pt-rBR` and `values-b+zh+Hans` name a locale; `values-night`+ * and `values-v29` don't. Android's first qualifier is the locale when it is one.+ */+ private fun localeOf(folder: String): String? {+ val qualifiers = folder.removePrefix("values-")+ if (qualifiers.startsWith("b+")) return qualifiers.removePrefix("b+").substringBefore('+')+ val first = qualifiers.substringBefore('-')+ return first.takeIf { it.length in 2..3 && it.all(Char::isLowerCase) }+ }++ @Test+ fun `resources dir is found`() {+ assertTrue("expected ${resDir.absolutePath}", File(resDir, "values/strings.xml").isFile)+ }++ @Test+ fun `every translation folder is a voice language`() {+ val voiceLanguages = Language.entries.map { it.iso639 }.toSet()+ val strays = translatedLanguages().filterValues { it !in voiceLanguages }+ assertTrue(+ "Translations for languages Gotcha can't speak or hear: ${strays.keys}. " ++ "Add the language to Language first, or drop the folder.",+ strays.isEmpty()+ )+ }++ @Test+ fun `default strings are declared as English`() {+ // generateLocaleConfig needs this to list English alongside the translations.+ val props = Properties().apply {+ File(resDir, "resources.properties").inputStream().use { load(it) }+ }+ assertEquals("en-US", props.getProperty("unqualifiedResLocale"))+ }++ @Test+ fun `locale folder parsing ignores non-locale qualifiers`() {+ assertEquals("hi", localeOf("values-hi"))+ assertEquals("pt", localeOf("values-pt-rBR"))+ assertEquals("zh", localeOf("values-b+zh+Hans"))+ assertEquals("hi", localeOf("values-hi-night"))+ assertEquals(null, localeOf("values-night"))+ assertEquals(null, localeOf("values-v29"))+ }+}