translate: move hardcoded UI strings into string resources
- Commit
f98a4a830837f98acbdcb8531af53971da296ba5- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-08 02:41 UTC (28 days ago)
- Parents
05b6fca
Four user-visible English strings on the text-translate screen were
hardcoded in Kotlin while the module maintains a fully translated
strings.xml (24 locales): the empty-output placeholder ("Translation
will appear here"), the mic status labels ("Listening…" /
"Transcribing…"), and the microphone-denied error ("Microphone
permission is required"). Users in every non-English locale saw these
in English, inconsistent with neighboring strings like the input label
and copy/speak/save actions, which already use stringResource.
This adds translation_placeholder, listening, transcribing, and
mic_permission_required to values/strings.xml (other locales fall back
to English until translated, the standard flow) and reads them via
stringResource at the three call sites. The Page-site string is hoisted
above the permission-callback lambda since stringResource is a
composable call and cannot run inside the callback.
User-visible effect: those four strings now follow the device locale
once translations land, instead of being stuck in English.
Verified with :translate:testDevUnitTest (BUILD SUCCESSFUL); the
existing compose tests assert the English text under the default
locale, which still resolves from values/strings.xml.Diff
translate/src/main/java/com/vayunmathur/translate/ui/TextTranslatePage.kt
diff --git a/translate/src/main/java/com/vayunmathur/translate/ui/TextTranslatePage.kt b/translate/src/main/java/com/vayunmathur/translate/ui/TextTranslatePage.ktindex c747f4537f..cbaad5577b 100644--- a/translate/src/main/java/com/vayunmathur/translate/ui/TextTranslatePage.kt+++ b/translate/src/main/java/com/vayunmathur/translate/ui/TextTranslatePage.kt@@ -108,10 +108,11 @@ fun TextTranslatePage( ) } + val micPermissionRequired = stringResource(R.string.mic_permission_required) val micPermission = rememberPermissionRequest( Manifest.permission.RECORD_AUDIO ) { granted ->- if (granted) startListening() else speechError = "Microphone permission is required"+ if (granted) startListening() else speechError = micPermissionRequired } // Live, debounced translation as input / language selection changes.
translate/src/main/java/com/vayunmathur/translate/ui/TextTranslateScreen.kt
diff --git a/translate/src/main/java/com/vayunmathur/translate/ui/TextTranslateScreen.kt b/translate/src/main/java/com/vayunmathur/translate/ui/TextTranslateScreen.ktindex b694728891..c63bd4859b 100644--- a/translate/src/main/java/com/vayunmathur/translate/ui/TextTranslateScreen.kt+++ b/translate/src/main/java/com/vayunmathur/translate/ui/TextTranslateScreen.kt@@ -181,8 +181,8 @@ private fun SourcePanel( ) val micStatus = when (micState) {- MicState.LISTENING -> "Listening…"- MicState.TRANSCRIBING -> "Transcribing…"+ MicState.LISTENING -> stringResource(R.string.listening)+ MicState.TRANSCRIBING -> stringResource(R.string.transcribing) MicState.IDLE -> null } micStatus?.let {@@ -278,7 +278,7 @@ private fun OutputCard( } Text(- text = outputText.ifBlank { "Translation will appear here" },+ text = outputText.ifBlank { stringResource(R.string.translation_placeholder) }, color = if (outputText.isBlank()) { MaterialTheme.colorScheme.onSurfaceVariant } else {
translate/src/main/res/values/strings.xml
diff --git a/translate/src/main/res/values/strings.xml b/translate/src/main/res/values/strings.xmlindex 0e030b5448..c6ee46a9c4 100644--- a/translate/src/main/res/values/strings.xml+++ b/translate/src/main/res/values/strings.xml@@ -38,4 +38,12 @@ <string name="could_not_read_image">Couldn’t read that image</string> <!-- Image translate: retry action after a failed image load. --> <string name="pick_another_image">Pick another image</string>+ <!-- Placeholder in the translation output card before any input is typed. -->+ <string name="translation_placeholder">Translation will appear here</string>+ <!-- Mic status under the source field while audio is being captured. -->+ <string name="listening">Listening…</string>+ <!-- Mic status under the source field while speech is being transcribed. -->+ <string name="transcribing">Transcribing…</string>+ <!-- Error shown when microphone permission is denied for speech input. -->+ <string name="mic_permission_required">Microphone permission is required</string> </resources>