Skip to content

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.

refactor(i18n): services' on-screen text in string resources

Durganshuc84e3fbbe8c7
diff --git a/app/src/main/java/com/gotcha/service/AssistiveBallService.kt b/app/src/main/java/com/gotcha/service/AssistiveBallService.kt
index 2d1743e..27636cd 100644
--- a/app/src/main/java/com/gotcha/service/AssistiveBallService.kt
+++ b/app/src/main/java/com/gotcha/service/AssistiveBallService.kt
@@ -24,6 +24,7 @@ import com.gotcha.data.ChatHistoryRepository
import com.gotcha.data.SettingsRepository
import com.gotcha.data.WakeWordListeningMode
import com.gotcha.data.settingsChangeNotifier
+import com.gotcha.i18n.stringLookup
import com.gotcha.ui.AssistiveBallOverlay
import com.gotcha.ui.CallChatWindow
import com.gotcha.util.GotchaLog
@@ -351,7 +352,7 @@ class AssistiveBallService : Service() {
val response = showingActivity(com.gotcha.ui.BallActivity.THINKING) {
llmClient.chat(history.toList())
}
- val replyText = response.choices.firstOrNull()?.message?.textContent ?: "No response"
+ val replyText = response.choices.firstOrNull()?.message?.textContent ?: getString(R.string.companion_no_response)
history.add(
com.gotcha.llm.ChatMessage(
"assistant",
@@ -360,7 +361,7 @@ class AssistiveBallService : Service() {
)
screenCompanionPanel.updateResponse(replyText)
} catch (e: Exception) {
- screenCompanionPanel.updateResponse("Error: ${HumanReadableError.format(e)}")
+ screenCompanionPanel.updateResponse(getString(R.string.companion_error, HumanReadableError.format(e)))
}
}
}
@@ -371,18 +372,18 @@ class AssistiveBallService : Service() {
* "Summarize link?" action — the earlier version wrongly attached a screenshot.
*/
private fun handleFetchAndSummarize(url: String, history: MutableList<com.gotcha.llm.ChatMessage>) {
- screenCompanionPanel.show("Summarize link:\n$url")
+ screenCompanionPanel.show(getString(R.string.companion_summarize_link, url))
overlay.isPanelOpen = true
- screenCompanionPanel.updateResponse("Fetching $url …")
+ screenCompanionPanel.updateResponse(getString(R.string.companion_fetching, url))
scope.launch {
val fetched = showingActivity(com.gotcha.ui.BallActivity.ACTING) {
withContext(Dispatchers.IO) { webFetchTool.fetch(url, "text") }
}
if (!fetched.success) {
- screenCompanionPanel.updateResponse("Couldn't fetch the link: ${fetched.message}")
+ screenCompanionPanel.updateResponse(getString(R.string.companion_fetch_failed, fetched.message))
return@launch
}
- screenCompanionPanel.updateResponse("Summarizing …")
+ screenCompanionPanel.updateResponse(getString(R.string.companion_summarizing))
try {
history.clear()
history.add(
@@ -405,13 +406,13 @@ class AssistiveBallService : Service() {
val response = showingActivity(com.gotcha.ui.BallActivity.THINKING) {
llmClient.chat(history.toList())
}
- val replyText = response.choices.firstOrNull()?.message?.textContent ?: "No response"
+ val replyText = response.choices.firstOrNull()?.message?.textContent ?: getString(R.string.companion_no_response)
history.add(
com.gotcha.llm.ChatMessage("assistant", kotlinx.serialization.json.JsonPrimitive(replyText))
)
screenCompanionPanel.updateResponse(replyText)
} catch (e: Exception) {
- screenCompanionPanel.updateResponse("Error: ${HumanReadableError.format(e)}")
+ screenCompanionPanel.updateResponse(getString(R.string.companion_error, HumanReadableError.format(e)))
}
}
}
@@ -478,7 +479,7 @@ class AssistiveBallService : Service() {
val url = SmartActionDetector.extractUrl(clipText)
if (url != null) {
GotchaLog.d("AssistiveBallService") { "Setting smart action: Summarize link ($url)" }
- val fetch = SmartActionDetector.fetchAction(url)
+ val fetch = SmartActionDetector.fetchAction(url, stringLookup())
overlay.setSmartActionAvailable(fetch.label, fetch.prompt)
return@readClipboardWithFocus
}
@@ -491,14 +492,15 @@ class AssistiveBallService : Service() {
clipText,
allowChat = true,
targetCurrency = preferredCurr,
- targetLanguage = preferredLang
+ targetLanguage = preferredLang,
+ strings = stringLookup()
)
if (!isAlreadyTargetLang) {
- val translateLabel = "🌐 Translate: ${SmartActionDetector.snippet(clipText, 20)}"
+ val translateLabel = getString(R.string.ball_translate_clip, SmartActionDetector.snippet(clipText, 20))
val translatePrompt = "Translate the copied text to $preferredLang:\n\n$clipText"
- if (smart != null && !smart.label.contains("Translate", ignoreCase = true)) {
+ if (smart != null && smart.actionType != ActionType.LLM_TRANSLATE) {
overlay.setSmartActionPairAvailable(
translateLabel,
translatePrompt,
@@ -512,7 +514,7 @@ class AssistiveBallService : Service() {
overlay.setSmartActionAvailable(smart.label, smart.prompt)
} else {
overlay.setSmartActionAvailable(
- "📋 Summarize: ${SmartActionDetector.snippet(clipText, 24)}",
+ getString(R.string.ball_summarize_clip, SmartActionDetector.snippet(clipText, 24)),
"Summarize the copied text:\n\n$clipText"
)
}
@@ -580,7 +582,7 @@ class AssistiveBallService : Service() {
this.type = "text/plain"
putExtra(Intent.EXTRA_TEXT, payload)
},
- "Share"
+ getString(R.string.action_share)
)
SmartActionDetector.TYPE_CONTACT ->
Intent(Intent.ACTION_INSERT).apply {
@@ -595,7 +597,11 @@ class AssistiveBallService : Service() {
SmartActionDetector.TYPE_COPY -> {
val clipManager = getSystemService(Context.CLIPBOARD_SERVICE) as? android.content.ClipboardManager
clipManager?.setPrimaryClip(android.content.ClipData.newPlainText("Gotcha", payload))
- android.widget.Toast.makeText(this, "Copied to clipboard", android.widget.Toast.LENGTH_SHORT).show()
+ android.widget.Toast.makeText(
+ this,
+ getString(R.string.ball_copied_to_clipboard),
+ android.widget.Toast.LENGTH_SHORT
+ ).show()
null
}
SmartActionDetector.TYPE_CONVERT -> {
@@ -608,7 +614,7 @@ class AssistiveBallService : Service() {
if (result != null) {
overlay.showCard(result, showClose = true)
} else {
- overlay.showError("Could not fetch exchange rate for $price")
+ overlay.showError(getString(R.string.ball_could_not_fetch_exchange_rate, price))
}
}
}
@@ -619,7 +625,7 @@ class AssistiveBallService : Service() {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
} catch (e: Exception) {
- overlay.showError("Couldn't open action: ${HumanReadableError.format(e)}")
+ overlay.showError(getString(R.string.ball_couldn_t_open_action, HumanReadableError.format(e)))
}
}
@@ -641,8 +647,8 @@ class AssistiveBallService : Service() {
)
pendingCropImage = base64Jpeg
overlay.isPanelOpen = true
- screenCompanionPanel.show("📸 Region attached — ask a question about it below.")
- screenCompanionPanel.updateResponse("Ask me anything about the selected region.")
+ screenCompanionPanel.show(getString(R.string.ball_region_attached_ask_a_question))
+ screenCompanionPanel.updateResponse(getString(R.string.ball_ask_me_anything_about_the))
}
/**
@@ -661,21 +667,21 @@ class AssistiveBallService : Service() {
)
activeCompanionHistory.add(com.gotcha.llm.visionUserMessage(prompt, base64Jpeg, "jpeg"))
overlay.isPanelOpen = true
- screenCompanionPanel.show("📸 Region attached")
- screenCompanionPanel.updateResponse("Thinking...")
+ screenCompanionPanel.show(getString(R.string.ball_region_attached))
+ screenCompanionPanel.updateResponse(getString(R.string.ball_thinking))
val currentHistory = activeCompanionHistory.toList()
scope.launch {
try {
val response = showingActivity(com.gotcha.ui.BallActivity.THINKING) {
llmClient.chat(currentHistory)
}
- val replyText = response.choices.firstOrNull()?.message?.textContent ?: "No response"
+ val replyText = response.choices.firstOrNull()?.message?.textContent ?: getString(R.string.companion_no_response)
activeCompanionHistory.add(
com.gotcha.llm.ChatMessage("assistant", kotlinx.serialization.json.JsonPrimitive(replyText))
)
screenCompanionPanel.updateResponse(replyText)
} catch (e: Exception) {
- screenCompanionPanel.updateResponse("Error: ${HumanReadableError.format(e)}")
+ screenCompanionPanel.updateResponse(getString(R.string.companion_error, HumanReadableError.format(e)))
}
}
}
@@ -695,14 +701,14 @@ class AssistiveBallService : Service() {
}
val text = result.text.trim()
if (text.isBlank()) {
- showToast("No text found in selection")
+ showToast(getString(R.string.ball_no_text_found_in_selection))
} else {
val clipboard = getSystemService(CLIPBOARD_SERVICE) as android.content.ClipboardManager
clipboard.setPrimaryClip(android.content.ClipData.newPlainText("Lens text", text))
- showToast("Copied to clipboard")
+ showToast(getString(R.string.ball_copied_to_clipboard))
}
} catch (e: Exception) {
- showToast("Couldn't read text: ${HumanReadableError.format(e)}")
+ showToast(getString(R.string.ball_couldn_t_read_text, HumanReadableError.format(e)))
} finally {
if (!bitmap.isRecycled) bitmap.recycle()
}
@@ -774,13 +780,13 @@ class AssistiveBallService : Service() {
}
activeCompanionHistory.add(userMsg)
val currentHistory = activeCompanionHistory.toList()
- updateResponse("Thinking...")
+ updateResponse(getString(R.string.ball_thinking))
scope.launch {
try {
val response = showingActivity(com.gotcha.ui.BallActivity.THINKING) {
llmClient.chat(currentHistory)
}
- val replyText = response.choices.firstOrNull()?.message?.textContent ?: "No response"
+ val replyText = response.choices.firstOrNull()?.message?.textContent ?: getString(R.string.companion_no_response)
activeCompanionHistory.add(
com.gotcha.llm.ChatMessage(
"assistant",
@@ -789,7 +795,7 @@ class AssistiveBallService : Service() {
)
updateResponse(replyText)
} catch (e: Exception) {
- updateResponse("Error: ${HumanReadableError.format(e)}")
+ updateResponse(getString(R.string.ball_error, HumanReadableError.format(e)))
}
}
}
@@ -805,14 +811,14 @@ class AssistiveBallService : Service() {
when {
s.sttProvider == AudioProvider.ANDROID -> {
if (!hasMicPermission()) {
- overlay.showError("Microphone permission not granted.")
+ overlay.showError(getString(R.string.ball_microphone_permission_not_granted))
screenCompanionPanel.setListening(false)
return
}
if (sttEngine.startAndroidListening(s.effectiveVoiceLanguage)) {
panelVoiceActive = true
} else {
- overlay.showError("Failed to start speech recognition.")
+ overlay.showError(getString(R.string.ball_failed_to_start_speech_recognition))
screenCompanionPanel.setListening(false)
}
}
@@ -829,19 +835,19 @@ class AssistiveBallService : Service() {
return
}
if (!hasMicPermission()) {
- overlay.showError("Microphone permission not granted.")
+ overlay.showError(getString(R.string.ball_microphone_permission_not_granted))
screenCompanionPanel.setListening(false)
return
}
if (sttEngine.startRecording()) {
panelVoiceActive = true
} else {
- overlay.showError("Failed to start recording.")
+ overlay.showError(getString(R.string.ball_failed_to_start_recording))
screenCompanionPanel.setListening(false)
}
}
else -> {
- overlay.showError("No STT provider configured. Enable one in settings.")
+ overlay.showError(getString(R.string.ball_no_stt_provider_configured_enable))
screenCompanionPanel.setListening(false)
}
}
@@ -868,7 +874,9 @@ class AssistiveBallService : Service() {
screenCompanionPanel.setListening(false)
result
.onSuccess { text -> if (text.isNotBlank()) screenCompanionPanel.appendVoiceInput(text) }
- .onFailure { e -> overlay.showError("Transcription failed: ${HumanReadableError.format(e)}") }
+ .onFailure { e ->
+ overlay.showError(getString(R.string.ball_transcription_failed, HumanReadableError.format(e)))
+ }
}
}
@@ -876,7 +884,7 @@ class AssistiveBallService : Service() {
private fun readPanelResponseAloud(text: String) {
val s = settingsRepository.load()
if (s.ttsProvider == AudioProvider.NONE) {
- overlay.showError("No TTS provider configured. Enable one in settings.")
+ overlay.showError(getString(R.string.ball_no_tts_provider_configured_enable))
screenCompanionPanel.setSpeaking(false)
return
}
@@ -1041,7 +1049,9 @@ class AssistiveBallService : Service() {
try {
val service = GotchaAccessibilityService.instance
if (service == null) {
- withContext(Dispatchers.Main) { overlay.showError("Accessibility service not available") }
+ withContext(
+ Dispatchers.Main
+ ) { overlay.showError(getString(R.string.ball_accessibility_service_not_available)) }
return@launch
}
withContext(Dispatchers.Main) {
@@ -1062,7 +1072,9 @@ class AssistiveBallService : Service() {
screenCompanionPanel.setVisibleForCapture(true)
}
if (bitmap == null) {
- withContext(Dispatchers.Main) { overlay.showError("Screenshot failed — try again") }
+ withContext(
+ Dispatchers.Main
+ ) { overlay.showError(getString(R.string.ball_screenshot_failed_try_again)) }
return@launch
}
val timestamp = java.text.SimpleDateFormat(
@@ -1082,7 +1094,7 @@ class AssistiveBallService : Service() {
overlay.showChromeAfterCapture()
chatWindow.setVisibleForCapture(true)
screenCompanionPanel.setVisibleForCapture(true)
- overlay.showError("Screenshot error: ${HumanReadableError.format(e)}")
+ overlay.showError(getString(R.string.ball_screenshot_error, HumanReadableError.format(e)))
}
}
}
diff --git a/app/src/main/java/com/gotcha/service/CallSessionController.kt b/app/src/main/java/com/gotcha/service/CallSessionController.kt
index 8b5dee8..2ac4f9e 100644
--- a/app/src/main/java/com/gotcha/service/CallSessionController.kt
+++ b/app/src/main/java/com/gotcha/service/CallSessionController.kt
@@ -4,6 +4,7 @@ import android.content.Context
import android.content.pm.PackageManager
import android.util.Log
import androidx.core.content.ContextCompat
+import com.gotcha.R
import com.gotcha.agent.AgentEngine
import com.gotcha.agent.AgentEvents
import com.gotcha.agent.ForegroundControlRequest
@@ -162,24 +163,34 @@ class CallSessionController(
fun startCall(): Boolean {
if (isActive()) return false
if (buildClient() == null) {
- onError("Set up your API key in Gotcha first.")
+ onError(appContext.getString(R.string.call_error_no_api_key))
return false
}
val micGranted = ContextCompat.checkSelfPermission(
appContext, android.Manifest.permission.RECORD_AUDIO
) == PackageManager.PERMISSION_GRANTED
if (!micGranted) {
- onError("Microphone permission not granted. Enable it in Gotcha → Settings → Permissions.")
+ onError(appContext.getString(R.string.call_error_no_mic))
return false
}
val s = settingsRepository.load()
- val sttError = audioConfigError("Speech-to-text", s.sttProvider, s.effectiveSttBaseUrl, s.sttApiModel)
+ val sttError = audioConfigError(
+ appContext.getString(R.string.call_stt_label),
+ s.sttProvider,
+ s.effectiveSttBaseUrl,
+ s.sttApiModel
+ )
if (sttError != null) {
onError(sttError)
return false
}
- val ttsError = audioConfigError("Text-to-speech", s.ttsProvider, s.effectiveTtsBaseUrl, s.ttsApiModel)
+ val ttsError = audioConfigError(
+ appContext.getString(R.string.call_tts_label),
+ s.ttsProvider,
+ s.effectiveTtsBaseUrl,
+ s.ttsApiModel
+ )
if (ttsError != null) {
onError(ttsError)
return false
@@ -224,7 +235,7 @@ class CallSessionController(
scope.launch {
val language = s.effectiveVoiceLanguage
if (!speakText(startGreeting(handsFree, language), language)) {
- reportError("Couldn't play voice audio — check your Text-to-Speech settings.")
+ reportError(appContext.getString(R.string.call_error_tts_playback))
}
_state.value = CallState.READY
if (!handsFree) {
@@ -451,7 +462,7 @@ class CallSessionController(
* untouched (still [READY] / [WAITING_USER]) so the user can tap again.
*/
internal fun onMicStartFailed() {
- reportError("Couldn't start the microphone — tap again to retry.")
+ reportError(appContext.getString(R.string.call_error_mic_start))
}
/** Stop the mic and send the recording for transcription + agent processing. */
@@ -544,7 +555,7 @@ class CallSessionController(
if (speakText(reply, language)) {
triggerEndVibration()
} else {
- reportError("Couldn't play the voice reply — check your Text-to-Speech settings.")
+ reportError(appContext.getString(R.string.call_error_reply_playback))
}
onActionRingColor(null)
if (autoEndOnReply) endCall() else _state.value = CallState.READY
@@ -678,7 +689,7 @@ class CallSessionController(
}
override fun onPermissionRequest(marker: String) {
- reportError("A permission is needed that can't be granted during a call — open Gotcha to grant it.")
+ reportError(appContext.getString(R.string.call_error_permission))
}
/**
@@ -717,7 +728,7 @@ class CallSessionController(
}
addTranscript(MessageKind.ASSISTANT, prompt)
if (!speakText(prompt, currentLanguage())) {
- reportError("Couldn't play voice audio — check your Text-to-Speech settings.")
+ reportError(appContext.getString(R.string.call_error_tts_playback))
}
val gate = CompletableDeferred<String>()
questionGate = gate
@@ -735,7 +746,7 @@ class CallSessionController(
* Denies on timeout after 90 seconds.
*/
override suspend fun awaitConfirmation(toolNames: List<String>, description: String): Boolean =
- askOverScreen("Confirmation needed: $description", description)
+ askOverScreen(appContext.getString(R.string.call_confirmation_needed, description), description)
/**
* The once-per-request ask before Gotcha controls another app (issue #98).
@@ -755,15 +766,15 @@ class CallSessionController(
private suspend fun askOverScreen(
transcript: String,
summary: String,
- title: String = "Gotcha — confirm action",
- allowLabel: String = "Allow",
- denyLabel: String = "Deny"
+ title: String = appContext.getString(R.string.confirmation_title),
+ allowLabel: String = appContext.getString(R.string.action_allow),
+ denyLabel: String = appContext.getString(R.string.action_deny)
): Boolean {
_state.value = CallState.WAITING_USER
addTranscript(MessageKind.ASSISTANT, transcript)
val language = currentLanguage()
if (!speakText(SpokenPhrases.confirmationNeeded(language), language)) {
- reportError("Couldn't play voice audio — check your Text-to-Speech settings.")
+ reportError(appContext.getString(R.string.call_error_tts_playback))
}
val gate = CompletableDeferred<Boolean>()
confirmationOverlay.show(
@@ -845,19 +856,19 @@ class CallSessionController(
*/
private fun audioConfigError(label: String, provider: AudioProvider, baseUrl: String, model: String): String? =
when (provider) {
- AudioProvider.NONE -> "$label is not configured. Set it up in Gotcha → Settings → Speech (TTS / STT)."
+ AudioProvider.NONE -> appContext.getString(R.string.call_audio_not_configured, label)
AudioProvider.SAMOSA_AI -> when {
baseUrl.isBlank() ->
- "$label Samosa AI is not configured. Sign in from Gotcha → Settings → Speech (TTS / STT)."
+ appContext.getString(R.string.call_audio_samosa_not_configured, label)
model.isBlank() ->
- "$label model is not selected. Choose one in Gotcha → Settings → Speech (TTS / STT)."
+ appContext.getString(R.string.call_audio_model_missing, label)
else -> null
}
AudioProvider.API -> when {
baseUrl.isBlank() || baseUrl.trim().toHttpUrlOrNull() == null ->
- "$label API URL is missing or invalid. Fix it in Gotcha → Settings → Speech (TTS / STT)."
+ appContext.getString(R.string.call_audio_url_invalid, label)
model.isBlank() ->
- "$label API model is not selected. Choose one in Gotcha → Settings → Speech (TTS / STT)."
+ appContext.getString(R.string.call_audio_api_model_missing, label)
else -> null
}
AudioProvider.ANDROID -> null
@@ -914,7 +925,7 @@ class CallSessionController(
internal fun onNarrationTtsFailed() {
if (!narrationErrorReported) {
narrationErrorReported = true
- reportError("Couldn't play voice audio — check your Text-to-Speech settings.")
+ reportError(appContext.getString(R.string.call_error_tts_playback))
} else {
Log.w(TAG, "TTS narration failed during a call (already reported once)")
}
diff --git a/app/src/main/java/com/gotcha/service/GotchaAccessibilityService.kt b/app/src/main/java/com/gotcha/service/GotchaAccessibilityService.kt
index f9ca326..e61ba5f 100644
--- a/app/src/main/java/com/gotcha/service/GotchaAccessibilityService.kt
+++ b/app/src/main/java/com/gotcha/service/GotchaAccessibilityService.kt
@@ -10,6 +10,7 @@ import android.view.Display
import android.view.accessibility.AccessibilityEvent
import android.view.accessibility.AccessibilityNodeInfo
import androidx.annotation.RequiresApi
+import com.gotcha.i18n.stringLookup
import com.gotcha.util.GotchaLog
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@@ -427,7 +428,8 @@ class GotchaAccessibilityService : AccessibilityService() {
fullText,
allowChat = false,
targetCurrency = prefCurr,
- targetLanguage = prefLang
+ targetLanguage = prefLang,
+ strings = stringLookup()
)
val placeable = discardOversizedBounds(locateEntities(entities, nodeRanges))
val selected = SmartActionDetector.selectForAnnotation(placeable.map { it.entity })
diff --git a/app/src/main/java/com/gotcha/service/GotchaNotificationListenerService.kt b/app/src/main/java/com/gotcha/service/GotchaNotificationListenerService.kt
index 3fb2332..d1f99ad 100644
--- a/app/src/main/java/com/gotcha/service/GotchaNotificationListenerService.kt
+++ b/app/src/main/java/com/gotcha/service/GotchaNotificationListenerService.kt
@@ -8,7 +8,9 @@ import android.os.Looper
import android.service.notification.NotificationListenerService
import android.service.notification.StatusBarNotification
import android.widget.Toast
+import com.gotcha.R
import com.gotcha.data.SettingsRepository
+import com.gotcha.i18n.stringLookup
/**
* Tier 3 — NotificationListenerService.
@@ -73,7 +75,8 @@ class GotchaNotificationListenerService : NotificationListenerService() {
fullText,
allowChat = false,
targetCurrency = settings.preferredCurrency,
- targetLanguage = settings.preferredLanguage
+ targetLanguage = settings.preferredLanguage,
+ strings = stringLookup()
)
if (entities.isEmpty()) return
@@ -86,7 +89,10 @@ class GotchaNotificationListenerService : NotificationListenerService() {
Handler(Looper.getMainLooper()).post {
Toast.makeText(
context,
- "🔑 OTP ${otpEntity.normalizedValue} copied to clipboard",
+ context.getString(
+ R.string.notification_listener_otp_copied_to_clipboard,
+ otpEntity.normalizedValue
+ ),
Toast.LENGTH_SHORT
).show()
}
diff --git a/app/src/main/java/com/gotcha/service/MediaProjectionService.kt b/app/src/main/java/com/gotcha/service/MediaProjectionService.kt
index 4ba1def..c42d795 100644
--- a/app/src/main/java/com/gotcha/service/MediaProjectionService.kt
+++ b/app/src/main/java/com/gotcha/service/MediaProjectionService.kt
@@ -21,6 +21,7 @@ import android.os.IBinder
import android.util.DisplayMetrics
import android.util.Log
import android.view.WindowManager
+import com.gotcha.R
import com.gotcha.util.GotchaLog
import java.io.ByteArrayOutputStream
import java.io.File
@@ -309,17 +310,17 @@ class MediaProjectionService : Service() {
private fun createNotificationChannel() {
val channel = NotificationChannel(
CHANNEL_ID,
- "Screenshot Capture",
+ getString(R.string.screenshot_channel),
NotificationManager.IMPORTANCE_LOW
- ).apply { description = "One-shot screen capture" }
+ ).apply { description = getString(R.string.screenshot_channel_description) }
val nm = getSystemService(NotificationManager::class.java)
nm.createNotificationChannel(channel)
}
private fun buildNotification(): Notification {
return Notification.Builder(this, CHANNEL_ID)
- .setContentTitle("Gotcha")
- .setContentText("Capturing screenshot…")
+ .setContentTitle(getString(R.string.app_name))
+ .setContentText(getString(R.string.screenshot_capturing))
.setSmallIcon(android.R.drawable.ic_menu_camera)
.build()
}
diff --git a/app/src/main/java/com/gotcha/service/QrCodeScanner.kt b/app/src/main/java/com/gotcha/service/QrCodeScanner.kt
index b2fa9b5..22af39a 100644
--- a/app/src/main/java/com/gotcha/service/QrCodeScanner.kt
+++ b/app/src/main/java/com/gotcha/service/QrCodeScanner.kt
@@ -5,6 +5,8 @@ import com.google.mlkit.vision.barcode.BarcodeScannerOptions
import com.google.mlkit.vision.barcode.BarcodeScanning
import com.google.mlkit.vision.barcode.common.Barcode
import com.google.mlkit.vision.common.InputImage
+import com.gotcha.R
+import com.gotcha.i18n.StringLookup
import kotlinx.coroutines.tasks.await
/**
@@ -22,17 +24,17 @@ object QrCodeScanner {
/**
* Scans [bitmap] for QR codes and 1D/2D barcodes using ML Kit on-device recognition.
*/
- suspend fun scanBitmap(bitmap: Bitmap): List<DetectedEntity> {
+ suspend fun scanBitmap(bitmap: Bitmap, strings: StringLookup): List<DetectedEntity> {
return try {
val image = InputImage.fromBitmap(bitmap, 0)
val barcodes = scanner.process(image).await()
- barcodes.mapNotNull { barcodeToEntity(it) }
+ barcodes.mapNotNull { barcodeToEntity(it, strings) }
} catch (_: Throwable) {
emptyList()
}
}
- fun barcodeToEntity(barcode: Barcode): DetectedEntity? {
+ fun barcodeToEntity(barcode: Barcode, strings: StringLookup): DetectedEntity? {
val rawValue = barcode.rawValue ?: barcode.displayValue ?: return null
if (rawValue.isBlank()) return null
@@ -40,7 +42,7 @@ object QrCodeScanner {
val type = if (isQr) EntityType.QR_CODE else EntityType.BARCODE
val actions = mutableListOf<SmartAction>()
- val displayTitle = buildQrActions(barcode, rawValue, isQr, actions)
+ val displayTitle = buildQrActions(barcode, rawValue, isQr, actions, strings)
return DetectedEntity(
type = type,
@@ -57,7 +59,8 @@ object QrCodeScanner {
barcode: Barcode,
rawValue: String,
isQr: Boolean,
- actions: MutableList<SmartAction>
+ actions: MutableList<SmartAction>,
+ strings: StringLookup
): String {
val clean = rawValue.trim()
@@ -68,7 +71,7 @@ object QrCodeScanner {
?.ifBlank { null } ?: SmartActionDetector.snippet(url, 24)
actions.add(
SmartAction(
- label = "🌐 Open QR Link: $domain",
+ label = strings(R.string.qr_open_qr_link, domain),
prompt = SmartActionDetector.encode(SmartActionDetector.TYPE_VIEW, url),
actionType = ActionType.NATIVE_BROWSE,
isPrimary = true
@@ -76,19 +79,19 @@ object QrCodeScanner {
)
actions.add(
SmartAction(
- label = "📝 Summarize",
+ label = strings(R.string.qr_summarize),
prompt = SmartActionDetector.encode(SmartActionDetector.TYPE_FETCH, url),
actionType = ActionType.LLM_SUMMARIZE
)
)
actions.add(
SmartAction(
- label = "📋 Copy URL",
+ label = strings(R.string.qr_copy_url),
prompt = SmartActionDetector.encode(SmartActionDetector.TYPE_COPY, url),
actionType = ActionType.NATIVE_COPY
)
)
- return "QR Link: $domain"
+ return strings(R.string.qr_qr_link, domain)
}
// 2. ML Kit recognized Wi-Fi
@@ -98,13 +101,13 @@ object QrCodeScanner {
val info = "SSID: $ssid, Password: $pwd"
actions.add(
SmartAction(
- label = "📶 Wi-Fi: $ssid",
+ label = strings(R.string.qr_wi_fi, ssid),
prompt = SmartActionDetector.encode(SmartActionDetector.TYPE_COPY, info),
actionType = ActionType.NATIVE_COPY,
isPrimary = true
)
)
- return "Wi-Fi QR: $ssid"
+ return strings(R.string.qr_wi_fi_qr, ssid)
}
// 3. ML Kit recognized Phone
@@ -112,13 +115,13 @@ object QrCodeScanner {
val phone = barcode.phone?.number ?: clean
actions.add(
SmartAction(
- label = "📞 Call: ${SmartActionDetector.snippet(phone, 16)}",
+ label = strings(R.string.qr_call, SmartActionDetector.snippet(phone, 16)),
prompt = SmartActionDetector.encode(SmartActionDetector.TYPE_DIAL, phone),
actionType = ActionType.NATIVE_DIAL,
isPrimary = true
)
)
- return "QR Phone: $phone"
+ return strings(R.string.qr_qr_phone, phone)
}
// 4. UPI Payment scheme (upi://pay?pa=...)
@@ -128,7 +131,7 @@ object QrCodeScanner {
?.let { android.net.Uri.decode(it) } ?: SmartActionDetector.snippet(clean, 20)
actions.add(
SmartAction(
- label = "💳 Pay via UPI: $payee",
+ label = strings(R.string.qr_pay_via_upi, payee),
prompt = SmartActionDetector.encode(SmartActionDetector.TYPE_VIEW, clean),
actionType = ActionType.NATIVE_BROWSE,
isPrimary = true
@@ -136,12 +139,12 @@ object QrCodeScanner {
)
actions.add(
SmartAction(
- label = "📋 Copy UPI Link",
+ label = strings(R.string.qr_copy_upi_link),
prompt = SmartActionDetector.encode(SmartActionDetector.TYPE_COPY, clean),
actionType = ActionType.NATIVE_COPY
)
)
- return "UPI Payment: $payee"
+ return strings(R.string.qr_upi_payment, payee)
}
// 5. Generic URI scheme (e.g. intent://, paytm://, phonepe://, geo:, mailto:, smsto:, market://)
@@ -154,7 +157,7 @@ object QrCodeScanner {
?.ifBlank { null } ?: schemeName
actions.add(
SmartAction(
- label = "🌐 Open QR Link: $displayDomain",
+ label = strings(R.string.qr_open_qr_link, displayDomain),
prompt = SmartActionDetector.encode(SmartActionDetector.TYPE_VIEW, clean),
actionType = ActionType.NATIVE_BROWSE,
isPrimary = true
@@ -162,12 +165,12 @@ object QrCodeScanner {
)
actions.add(
SmartAction(
- label = "📋 Copy Link",
+ label = strings(R.string.qr_copy_link),
prompt = SmartActionDetector.encode(SmartActionDetector.TYPE_COPY, clean),
actionType = ActionType.NATIVE_COPY
)
)
- return "QR Link: $displayDomain"
+ return strings(R.string.qr_qr_link, displayDomain)
}
// 6. Web URL without scheme (e.g. www.example.com/page, domain.com, sub.domain.org/path)
@@ -187,7 +190,7 @@ object QrCodeScanner {
?: SmartActionDetector.snippet(clean, 20)
actions.add(
SmartAction(
- label = "🌐 Open QR Link: $domain",
+ label = strings(R.string.qr_open_qr_link, domain),
prompt = SmartActionDetector.encode(SmartActionDetector.TYPE_VIEW, fullUrl),
actionType = ActionType.NATIVE_BROWSE,
isPrimary = true
@@ -195,19 +198,19 @@ object QrCodeScanner {
)
actions.add(
SmartAction(
- label = "📝 Summarize",
+ label = strings(R.string.qr_summarize),
prompt = SmartActionDetector.encode(SmartActionDetector.TYPE_FETCH, fullUrl),
actionType = ActionType.LLM_SUMMARIZE
)
)
actions.add(
SmartAction(
- label = "📋 Copy Link",
+ label = strings(R.string.qr_copy_link),
prompt = SmartActionDetector.encode(SmartActionDetector.TYPE_COPY, fullUrl),
actionType = ActionType.NATIVE_COPY
)
)
- return "QR Link: $domain"
+ return strings(R.string.qr_qr_link, domain)
}
// 7. If 1D Barcode
@@ -215,7 +218,7 @@ object QrCodeScanner {
val searchUrl = "https://www.google.com/search?q=${android.net.Uri.encode(clean)}"
actions.add(
SmartAction(
- label = "🔍 Search Barcode: ${SmartActionDetector.snippet(clean, 16)}",
+ label = strings(R.string.qr_search_barcode, SmartActionDetector.snippet(clean, 16)),
prompt = SmartActionDetector.encode(SmartActionDetector.TYPE_VIEW, searchUrl),
actionType = ActionType.NATIVE_BROWSE,
isPrimary = true
@@ -223,12 +226,12 @@ object QrCodeScanner {
)
actions.add(
SmartAction(
- label = "📋 Copy Barcode",
+ label = strings(R.string.qr_copy_barcode),
prompt = SmartActionDetector.encode(SmartActionDetector.TYPE_COPY, clean),
actionType = ActionType.NATIVE_COPY
)
)
- return "Barcode: ${SmartActionDetector.snippet(clean, 20)}"
+ return strings(R.string.qr_barcode, SmartActionDetector.snippet(clean, 20))
}
// 8. General QR content fallback:
@@ -240,7 +243,7 @@ object QrCodeScanner {
}
actions.add(
SmartAction(
- label = "🌐 Open QR Link: ${SmartActionDetector.snippet(clean, 18)}",
+ label = strings(R.string.qr_open_qr_link, SmartActionDetector.snippet(clean, 18)),
prompt = SmartActionDetector.encode(SmartActionDetector.TYPE_VIEW, searchUrl),
actionType = ActionType.NATIVE_BROWSE,
isPrimary = true
@@ -248,7 +251,7 @@ object QrCodeScanner {
)
actions.add(
SmartAction(
- label = "🤖 Ask Assistant",
+ label = strings(R.string.qr_ask_assistant),
prompt = "Here is the content of a QR code detected on screen:\n\n$clean\n\n" +
"Please process or act on this QR code content.",
actionType = ActionType.LLM_GENERAL
@@ -256,11 +259,11 @@ object QrCodeScanner {
)
actions.add(
SmartAction(
- label = "📋 Copy QR Content",
+ label = strings(R.string.qr_copy_qr_content),
prompt = SmartActionDetector.encode(SmartActionDetector.TYPE_COPY, clean),
actionType = ActionType.NATIVE_COPY
)
)
- return "QR: ${SmartActionDetector.snippet(clean, 20)}"
+ return strings(R.string.qr_qr, SmartActionDetector.snippet(clean, 20))
}
}
diff --git a/app/src/main/java/com/gotcha/service/ScreenCompanionController.kt b/app/src/main/java/com/gotcha/service/ScreenCompanionController.kt
index 35a9e2a..f1d2a34 100644
--- a/app/src/main/java/com/gotcha/service/ScreenCompanionController.kt
+++ b/app/src/main/java/com/gotcha/service/ScreenCompanionController.kt
@@ -9,8 +9,10 @@ import android.net.Uri
import android.os.Handler
import android.os.Looper
import android.provider.MediaStore
+import com.gotcha.R
import com.gotcha.agent.ScreenSnapshot
import com.gotcha.data.SettingsRepository
+import com.gotcha.i18n.stringLookup
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
@@ -92,9 +94,9 @@ class ScreenCompanionController(
if (triggerType == "Screenshot") {
val prefLang = settings?.preferredLanguage ?: "English"
onSmartActionPairReady(
- "📸 Screenshot taken. Extract text?",
+ context.getString(R.string.companion_screenshot_extract),
"Extract the text from this screenshot.",
- "🌐 Translate Screenshot",
+ context.getString(R.string.companion_screenshot_translate),
translateScreenshotPrompt(prefLang)
)
return
@@ -134,7 +136,7 @@ class ScreenCompanionController(
val visualQrEntities = try {
val bitmap = GotchaAccessibilityService.instance?.takeScreenshotBitmap()
if (bitmap != null) {
- val scanned = QrCodeScanner.scanBitmap(bitmap)
+ val scanned = QrCodeScanner.scanBitmap(bitmap, context.stringLookup())
bitmap.recycle()
scanned
} else {
@@ -151,7 +153,8 @@ class ScreenCompanionController(
screenText,
allowChat = false,
targetCurrency = prefCurrency,
- targetLanguage = prefLang
+ targetLanguage = prefLang,
+ strings = context.stringLookup()
)
} else {
emptyList()
diff --git a/app/src/main/java/com/gotcha/service/ScreenLensController.kt b/app/src/main/java/com/gotcha/service/ScreenLensController.kt
index 95b7d25..6f8ba52 100644
--- a/app/src/main/java/com/gotcha/service/ScreenLensController.kt
+++ b/app/src/main/java/com/gotcha/service/ScreenLensController.kt
@@ -12,6 +12,7 @@ import android.view.View
import android.view.WindowManager
import android.widget.TextView
import com.gotcha.R
+import com.gotcha.i18n.stringLookup
import com.gotcha.ui.MaxHeightScrollView
import com.gotcha.ui.ScreenCropOverlayView
import com.gotcha.ui.applyOverlayCard
@@ -127,7 +128,7 @@ class ScreenLensController(
rotationWatcher.start()
} catch (_: Exception) {
cropOverlay = null
- onError("Couldn't start Lens mode")
+ onError(appContext.getString(R.string.lens_couldn_t_start_lens_mode))
}
}
}
@@ -154,7 +155,9 @@ class ScreenLensController(
scope.launch {
val service = GotchaAccessibilityService.instance
if (service == null) {
- withContext(Dispatchers.Main) { onError("Accessibility service not available") }
+ withContext(
+ Dispatchers.Main
+ ) { onError(appContext.getString(R.string.lens_accessibility_service_not_available)) }
return@launch
}
val snapped = service.snapRegionToElements(padded).also {
@@ -169,7 +172,12 @@ class ScreenLensController(
val preferredLang = settings?.preferredLanguage ?: "English"
val preferredCurr = settings?.preferredCurrency ?: "USD"
val contextualActions = regionText?.let {
- SmartActionDetector.detectContextual(it, targetCurrency = preferredCurr, targetLanguage = preferredLang)
+ SmartActionDetector.detectContextual(
+ it,
+ targetCurrency = preferredCurr,
+ targetLanguage = preferredLang,
+ strings = appContext.stringLookup()
+ )
} ?: emptyList()
withContext(Dispatchers.Main) {
@@ -190,7 +198,7 @@ class ScreenLensController(
if (full == null) {
withContext(Dispatchers.Main) {
removeCropOverlay()
- onError("Screenshot failed — try again")
+ onError(appContext.getString(R.string.lens_screenshot_failed_try_again))
}
return@launch
}
@@ -199,7 +207,7 @@ class ScreenLensController(
if (cropped == null) {
withContext(Dispatchers.Main) {
removeCropOverlay()
- onError("Selection was empty")
+ onError(appContext.getString(R.string.lens_selection_was_empty))
}
return@launch
}
@@ -252,14 +260,14 @@ class ScreenLensController(
if (!cleanText.isNullOrBlank()) {
chipsLayout.addView(
- chipButton("Select", colors, R.drawable.ic_lens_select) {
+ chipButton(appContext.getString(R.string.lens_select), colors, R.drawable.ic_lens_select) {
showSelectableTextCard(cleanText)
}
)
}
chipsLayout.addView(
- chipButton("Copy", colors, R.drawable.ic_lens_copy) {
+ chipButton(appContext.getString(R.string.lens_copy), colors, R.drawable.ic_lens_copy) {
val crop = pendingCrop
if (crop != null && !crop.isRecycled) {
val cropCopy = runCatching { crop.copy(crop.config, false) }.getOrNull()
@@ -277,7 +285,7 @@ class ScreenLensController(
if (!isAlreadyInPreferredLang) {
chipsLayout.addView(
- chipButton("Translate", colors, R.drawable.ic_lens_translate) {
+ chipButton(appContext.getString(R.string.lens_translate), colors, R.drawable.ic_lens_translate) {
val prompt = "Extract text from this screenshot, translate it to $preferredLang, " +
"and display both original and translated text."
encodePendingCrop { base64 -> onImagePrompt(base64, prompt) }
@@ -287,7 +295,7 @@ class ScreenLensController(
}
chipsLayout.addView(
- chipButton("Save", colors, R.drawable.ic_lens_save) {
+ chipButton(appContext.getString(R.string.lens_save), colors, R.drawable.ic_lens_save) {
val crop = pendingCrop
if (crop != null && !crop.isRecycled) {
val cropCopy = runCatching { crop.copy(crop.config, false) }.getOrNull()
@@ -300,7 +308,7 @@ class ScreenLensController(
)
chipsLayout.addView(
- chipButton("Ask", colors, R.drawable.ic_lens_ask) {
+ chipButton(appContext.getString(R.string.lens_ask), colors, R.drawable.ic_lens_ask) {
encodePendingCrop { base64 -> onAskAboutCrop(base64) }
cancel()
}
@@ -418,7 +426,7 @@ class ScreenLensController(
}
val titleView = TextView(appContext).apply {
- this.text = "Extracted Text"
+ this.text = appContext.getString(R.string.lens_extracted_text)
textSize = colors.titleSp
setTypeface(colors.sans, android.graphics.Typeface.BOLD)
setTextColor(colors.onSurface)
@@ -451,19 +459,19 @@ class ScreenLensController(
}
btnRow.addView(
- chipButton("Copy Selected", colors, filled = true) {
+ chipButton(appContext.getString(R.string.lens_copy_selected), colors, filled = true) {
copyTextSelection(textView, text)
}
)
btnRow.addView(
- chipButton("Copy All", colors, R.drawable.ic_lens_copy, filled = true) {
+ chipButton(appContext.getString(R.string.lens_copy_all), colors, R.drawable.ic_lens_copy, filled = true) {
copyTextToClipboard(text)
}
)
btnRow.addView(
- chipButton("Close", colors, filled = true) {
+ chipButton(appContext.getString(R.string.lens_close), colors, filled = true) {
cancel()
}
)
@@ -500,7 +508,7 @@ class ScreenLensController(
} else {
android.widget.Toast.makeText(
appContext,
- "Select some text first, then tap Copy Selected",
+ appContext.getString(R.string.lens_select_some_text_first_then),
android.widget.Toast.LENGTH_SHORT
).show()
}
@@ -513,7 +521,7 @@ class ScreenLensController(
clipManager?.setPrimaryClip(android.content.ClipData.newPlainText("Extracted Text", content))
android.widget.Toast.makeText(
appContext,
- "Copied to clipboard",
+ appContext.getString(R.string.lens_copied_to_clipboard),
android.widget.Toast.LENGTH_SHORT
).show()
cancel()
@@ -622,13 +630,13 @@ class ScreenLensController(
withContext(Dispatchers.Main) {
android.widget.Toast.makeText(
appContext,
- "Saved image to $location",
+ appContext.getString(R.string.lens_saved_image_to, location),
android.widget.Toast.LENGTH_SHORT
).show()
}
} catch (e: Exception) {
withContext(Dispatchers.Main) {
- onError("Failed to save image: ${e.message}")
+ onError(appContext.getString(R.string.lens_failed_to_save_image, e.message))
}
} finally {
if (!bitmap.isRecycled) bitmap.recycle()
@@ -667,7 +675,9 @@ class ScreenLensController(
if (base64 != null) {
withContext(Dispatchers.Main) { onEncoded(base64) }
} else {
- withContext(Dispatchers.Main) { onError("Couldn't prepare the image") }
+ withContext(
+ Dispatchers.Main
+ ) { onError(appContext.getString(R.string.lens_couldn_t_prepare_the_image)) }
}
}
}
diff --git a/app/src/main/java/com/gotcha/service/SmartActionDetector.kt b/app/src/main/java/com/gotcha/service/SmartActionDetector.kt
index fc06e06..39fd48c 100644
--- a/app/src/main/java/com/gotcha/service/SmartActionDetector.kt
+++ b/app/src/main/java/com/gotcha/service/SmartActionDetector.kt
@@ -1,5 +1,10 @@
package com.gotcha.service
+import androidx.annotation.StringRes
+import com.gotcha.R
+import com.gotcha.i18n.Language
+import com.gotcha.i18n.StringLookup
+import com.gotcha.ui.nameRes
import java.time.DayOfWeek
import java.time.LocalDate
import java.time.LocalDateTime
@@ -268,38 +273,39 @@ object SmartActionDetector {
allowChat: Boolean = false,
targetCurrency: String = "USD",
targetLanguage: String = "English",
- now: LocalDateTime = LocalDateTime.now()
+ now: LocalDateTime = LocalDateTime.now(),
+ strings: StringLookup
): List<DetectedEntity> {
if (text.isBlank()) return emptyList()
val rawEntities = mutableListOf<DetectedEntity>()
// 0. QR & Barcode patterns in text
- detectQrAndBarcodes(text, rawEntities)
+ detectQrAndBarcodes(text, rawEntities, strings)
// 1. OTP
- detectOtps(text, rawEntities)
+ detectOtps(text, rawEntities, strings)
// 2. Phone
- detectPhones(text, rawEntities)
+ detectPhones(text, rawEntities, strings)
// 3. Address
- detectAddresses(text, rawEntities)
+ detectAddresses(text, rawEntities, strings)
// 4. Email
- detectEmails(text, rawEntities)
+ detectEmails(text, rawEntities, strings)
// 5. URL
- detectUrls(text, rawEntities)
+ detectUrls(text, rawEntities, strings)
// 6. Currency
- detectCurrencies(text, rawEntities, targetCurrency)
+ detectCurrencies(text, rawEntities, targetCurrency, strings)
// 7. Calendar
- detectCalendars(text, rawEntities, now)
+ detectCalendars(text, rawEntities, now, strings)
// 8. Tracking numbers
- detectTracking(text, rawEntities)
+ detectTracking(text, rawEntities, strings)
// 9. Chat reply fallback (if allowChat set)
if (allowChat && looksLikeChatMessage(text, targetLanguage)) {
@@ -310,7 +316,10 @@ object SmartActionDetector {
if (!isAlreadyTargetLang) {
actions.add(
SmartAction(
- label = "🌐 Translate to $targetLanguage",
+ label = strings(
+ R.string.smart_translate_to,
+ strings(Language.fromLabel(targetLanguage).nameRes)
+ ),
prompt = "Translate the following text to $targetLanguage:\n\n$text",
actionType = ActionType.LLM_TRANSLATE,
isPrimary = true
@@ -319,7 +328,7 @@ object SmartActionDetector {
}
actions.add(
SmartAction(
- label = "💬 Draft reply: ${snippet(normalized, 24)}",
+ label = strings(R.string.smart_draft_reply, snippet(normalized, 24)),
prompt = "Draft a short, friendly reply to this message. Return only the reply text:\n\n$text",
actionType = ActionType.LLM_CHAT_REPLY,
isPrimary = isAlreadyTargetLang
@@ -327,7 +336,7 @@ object SmartActionDetector {
)
actions.add(
SmartAction(
- label = "📋 Copy text",
+ label = strings(R.string.smart_copy_text),
prompt = encode(TYPE_COPY, normalized),
actionType = ActionType.NATIVE_COPY
)
@@ -357,9 +366,10 @@ object SmartActionDetector {
text: String,
allowChat: Boolean = false,
targetCurrency: String = "USD",
- targetLanguage: String = "English"
+ targetLanguage: String = "English",
+ strings: StringLookup
): SmartAction? {
- val entities = detectAll(text, allowChat, targetCurrency, targetLanguage)
+ val entities = detectAll(text, allowChat, targetCurrency, targetLanguage, strings = strings)
// Proactive detect historically excluded currency & calendar unless in Lens mode
val filtered = entities.filter { it.type != EntityType.CURRENCY && it.type != EntityType.CALENDAR }
return filtered.firstOrNull()?.primaryAction
@@ -372,13 +382,15 @@ object SmartActionDetector {
fun detectContextual(
text: String,
targetCurrency: String = "USD",
- targetLanguage: String = "English"
+ targetLanguage: String = "English",
+ strings: StringLookup
): List<SmartAction> {
val entities = detectAll(
text = text,
allowChat = false,
targetCurrency = targetCurrency,
- targetLanguage = targetLanguage
+ targetLanguage = targetLanguage,
+ strings = strings
)
return entities.mapNotNull { it.primaryAction }
}
@@ -444,9 +456,9 @@ object SmartActionDetector {
* same word on every chip of a type, and it is what made the chips wide
* enough to bury the screen underneath them.
*/
- fun chipLabel(entity: DetectedEntity, groupCount: Int = 1): String {
+ fun chipLabel(entity: DetectedEntity, groupCount: Int = 1, strings: StringLookup): String {
val icon = iconFor(entity.type)
- if (groupCount > 1) return "$icon $groupCount ${pluralFor(entity.type)}"
+ if (groupCount > 1) return "$icon ${strings(groupLabelFor(entity.type), groupCount)}"
return "$icon ${snippet(entity.normalizedValue, CHIP_LABEL_MAX)}"
}
@@ -464,21 +476,23 @@ object SmartActionDetector {
EntityType.GENERIC_TEXT -> "✨"
}
- private fun pluralFor(type: EntityType): String = when (type) {
- EntityType.QR_CODE, EntityType.BARCODE -> "codes"
- EntityType.OTP -> "codes"
- EntityType.PHONE -> "numbers"
- EntityType.ADDRESS -> "addresses"
- EntityType.EMAIL -> "emails"
- EntityType.URL -> "links"
- EntityType.CALENDAR -> "dates"
- EntityType.CURRENCY -> "prices"
- EntityType.TRACKING_NUMBER -> "packages"
- EntityType.CHAT_REPLY -> "messages"
- EntityType.GENERIC_TEXT -> "items"
+ /** "%1$d links" and the like, for a chip standing for several matches. */
+ @StringRes
+ private fun groupLabelFor(type: EntityType): Int = when (type) {
+ EntityType.QR_CODE, EntityType.BARCODE -> R.string.smart_group_codes
+ EntityType.OTP -> R.string.smart_group_codes
+ EntityType.PHONE -> R.string.smart_group_numbers
+ EntityType.ADDRESS -> R.string.smart_group_addresses
+ EntityType.EMAIL -> R.string.smart_group_emails
+ EntityType.URL -> R.string.smart_group_links
+ EntityType.CALENDAR -> R.string.smart_group_dates
+ EntityType.CURRENCY -> R.string.smart_group_prices
+ EntityType.TRACKING_NUMBER -> R.string.smart_group_packages
+ EntityType.CHAT_REPLY -> R.string.smart_group_messages
+ EntityType.GENERIC_TEXT -> R.string.smart_group_items
}
- private fun detectOtps(text: String, out: MutableList<DetectedEntity>) {
+ private fun detectOtps(text: String, out: MutableList<DetectedEntity>, strings: StringLookup) {
val m = potentialCodePattern.matcher(text)
while (m.find()) {
val code = m.group(1)?.trim() ?: continue
@@ -493,13 +507,13 @@ object SmartActionDetector {
if (otpKeywordCheckPattern.matcher(windowText).find()) {
val actions = listOf(
SmartAction(
- label = "🔑 Copy code ${snippet(code, 10)}",
+ label = strings(R.string.smart_copy_code, snippet(code, 10)),
prompt = encode(TYPE_COPY, code),
actionType = ActionType.NATIVE_COPY,
isPrimary = true
),
SmartAction(
- label = "📤 Share code",
+ label = strings(R.string.smart_share_code),
prompt = encode(TYPE_SHARE, code),
actionType = ActionType.NATIVE_SHARE
)
@@ -519,35 +533,35 @@ object SmartActionDetector {
}
}
- private fun detectPhones(text: String, out: MutableList<DetectedEntity>) {
+ private fun detectPhones(text: String, out: MutableList<DetectedEntity>, strings: StringLookup) {
val m = phonePattern.matcher(text)
while (m.find()) {
val raw = m.group().trim()
val normalized = raw.replace(Regex("[^0-9+]"), "")
val actions = listOf(
SmartAction(
- label = "📞 Dial ${snippet(raw, 20)}",
+ label = strings(R.string.smart_dial, snippet(raw, 20)),
prompt = encode(TYPE_DIAL, raw),
actionType = ActionType.NATIVE_DIAL,
isPrimary = true
),
SmartAction(
- label = "💬 SMS",
+ label = strings(R.string.smart_sms),
prompt = encode(TYPE_SMS, raw),
actionType = ActionType.NATIVE_SMS
),
SmartAction(
- label = "💬 WhatsApp",
+ label = strings(R.string.smart_whatsapp),
prompt = encode(TYPE_WHATSAPP, normalized),
actionType = ActionType.NATIVE_WHATSAPP
),
SmartAction(
- label = "👤 Save contact",
+ label = strings(R.string.smart_save_contact),
prompt = encode(TYPE_CONTACT, raw),
actionType = ActionType.NATIVE_ADD_CONTACT
),
SmartAction(
- label = "📋 Copy number",
+ label = strings(R.string.smart_copy_number),
prompt = encode(TYPE_COPY, raw),
actionType = ActionType.NATIVE_COPY
)
@@ -565,25 +579,25 @@ object SmartActionDetector {
}
}
- private fun detectAddresses(text: String, out: MutableList<DetectedEntity>) {
+ private fun detectAddresses(text: String, out: MutableList<DetectedEntity>, strings: StringLookup) {
val m = addressPattern.matcher(text)
while (m.find()) {
val raw = m.group().trim().trimEnd(',')
val normalized = raw.replace(Regex("[\\r\\n]+"), " ").replace(Regex("\\s+"), " ").trim()
val actions = listOf(
SmartAction(
- label = "📍 Navigate: ${snippet(normalized, 24)}",
+ label = strings(R.string.smart_navigate, snippet(normalized, 24)),
prompt = encode(TYPE_NAVIGATE, normalized),
actionType = ActionType.NATIVE_NAVIGATE,
isPrimary = true
),
SmartAction(
- label = "📋 Copy address",
+ label = strings(R.string.smart_copy_address),
prompt = encode(TYPE_COPY, normalized),
actionType = ActionType.NATIVE_COPY
),
SmartAction(
- label = "📤 Share address",
+ label = strings(R.string.smart_share_address),
prompt = encode(TYPE_SHARE, normalized),
actionType = ActionType.NATIVE_SHARE
)
@@ -601,24 +615,24 @@ object SmartActionDetector {
}
}
- private fun detectEmails(text: String, out: MutableList<DetectedEntity>) {
+ private fun detectEmails(text: String, out: MutableList<DetectedEntity>, strings: StringLookup) {
val m = emailPattern.matcher(text)
while (m.find()) {
val email = m.group().trim()
val actions = listOf(
SmartAction(
- label = "📧 Compose: ${snippet(email, 22)}",
+ label = strings(R.string.smart_compose, snippet(email, 22)),
prompt = encode(TYPE_MAILTO, email),
actionType = ActionType.NATIVE_COMPOSE_MAIL,
isPrimary = true
),
SmartAction(
- label = "📋 Copy email",
+ label = strings(R.string.smart_copy_email),
prompt = encode(TYPE_COPY, email),
actionType = ActionType.NATIVE_COPY
),
SmartAction(
- label = "📤 Share email",
+ label = strings(R.string.smart_share_email),
prompt = encode(TYPE_SHARE, email),
actionType = ActionType.NATIVE_SHARE
)
@@ -636,7 +650,7 @@ object SmartActionDetector {
}
}
- private fun detectUrls(text: String, out: MutableList<DetectedEntity>) {
+ private fun detectUrls(text: String, out: MutableList<DetectedEntity>, strings: StringLookup) {
val m = urlPattern.matcher(text)
while (m.find()) {
val raw = m.group().trim()
@@ -644,23 +658,23 @@ object SmartActionDetector {
val pretty = prettyUrl(cleanUrl)
val actions = listOf(
SmartAction(
- label = "🌐 Open: ${snippet(pretty, 24)}",
+ label = strings(R.string.smart_open, snippet(pretty, 24)),
prompt = encode(TYPE_VIEW, cleanUrl),
actionType = ActionType.NATIVE_BROWSE,
isPrimary = true
),
SmartAction(
- label = "📝 Summarize",
+ label = strings(R.string.smart_summarize),
prompt = encode(TYPE_FETCH, cleanUrl),
actionType = ActionType.LLM_SUMMARIZE
),
SmartAction(
- label = "📋 Copy link",
+ label = strings(R.string.smart_copy_link),
prompt = encode(TYPE_COPY, cleanUrl),
actionType = ActionType.NATIVE_COPY
),
SmartAction(
- label = "📤 Share link",
+ label = strings(R.string.smart_share_link),
prompt = encode(TYPE_SHARE, cleanUrl),
actionType = ActionType.NATIVE_SHARE
)
@@ -693,7 +707,8 @@ object SmartActionDetector {
private fun detectCurrencies(
text: String,
out: MutableList<DetectedEntity>,
- targetCurrency: String = "USD"
+ targetCurrency: String = "USD",
+ strings: StringLookup
) {
val m = currencyPattern.matcher(text)
val targetCode = targetCurrency.uppercase().take(3)
@@ -706,7 +721,7 @@ object SmartActionDetector {
if (priceCode.isNotBlank() && !priceCode.equals(targetCode, ignoreCase = true)) {
actions.add(
SmartAction(
- label = "💵 Convert to $targetCode",
+ label = strings(R.string.smart_convert_to, targetCode),
prompt = encode(TYPE_CONVERT, "$price|$targetCode"),
actionType = ActionType.LLM_CONVERT_CURRENCY,
isPrimary = true
@@ -715,7 +730,7 @@ object SmartActionDetector {
}
actions.add(
SmartAction(
- label = "📋 Copy price",
+ label = strings(R.string.smart_copy_price),
prompt = encode(TYPE_COPY, price),
actionType = ActionType.NATIVE_COPY,
isPrimary = actions.isEmpty()
@@ -828,7 +843,7 @@ object SmartActionDetector {
private fun isStillAhead(date: LocalDate, time: LocalTime?, now: LocalDateTime): Boolean =
if (time != null) date.atTime(time).isAfter(now) else !date.isBefore(now.toLocalDate())
- private fun detectCalendars(text: String, out: MutableList<DetectedEntity>, now: LocalDateTime) {
+ private fun detectCalendars(text: String, out: MutableList<DetectedEntity>, now: LocalDateTime, strings: StringLookup) {
val today = now.toLocalDate()
val m = calendarPattern.matcher(text)
while (m.find()) {
@@ -854,13 +869,13 @@ object SmartActionDetector {
val actions = listOf(
SmartAction(
- label = "📅 Add to calendar: ${snippet(event, 24)}",
+ label = strings(R.string.smart_add_to_calendar, snippet(event, 24)),
prompt = encode(TYPE_CALENDAR, calendarPayload(event, date, timeOfDay)),
actionType = ActionType.NATIVE_CALENDAR,
isPrimary = true
),
SmartAction(
- label = "📋 Copy event",
+ label = strings(R.string.smart_copy_event),
prompt = encode(TYPE_COPY, event),
actionType = ActionType.NATIVE_COPY
)
@@ -878,7 +893,7 @@ object SmartActionDetector {
}
}
- private fun detectTracking(text: String, out: MutableList<DetectedEntity>) {
+ private fun detectTracking(text: String, out: MutableList<DetectedEntity>, strings: StringLookup) {
val m = trackingPattern.matcher(text)
while (m.find()) {
val trackNum = m.group().trim()
@@ -890,13 +905,13 @@ object SmartActionDetector {
}
val actions = listOf(
SmartAction(
- label = "📦 Track $carrier: ${snippet(trackNum, 16)}",
+ label = strings(R.string.smart_track, carrier, snippet(trackNum, 16)),
prompt = encode(TYPE_VIEW, trackingUrl),
actionType = ActionType.NATIVE_BROWSE,
isPrimary = true
),
SmartAction(
- label = "📋 Copy tracking number",
+ label = strings(R.string.smart_copy_tracking_number),
prompt = encode(TYPE_COPY, trackNum),
actionType = ActionType.NATIVE_COPY
)
@@ -965,7 +980,7 @@ object SmartActionDetector {
fun encode(type: String, payload: String): String =
"$ACTION_PREFIX$type$PAYLOAD_SEP$payload"
- private fun detectQrAndBarcodes(text: String, out: MutableList<DetectedEntity>) {
+ private fun detectQrAndBarcodes(text: String, out: MutableList<DetectedEntity>, strings: StringLookup) {
if (text.isBlank()) return
val wifiPattern = Pattern.compile("WIFI:S:([^;]+);(?:T:([^;]+);)?(?:P:([^;]+);)?", Pattern.CASE_INSENSITIVE)
val mWifi = wifiPattern.matcher(text)
@@ -975,7 +990,7 @@ object SmartActionDetector {
val fullMatch = mWifi.group(0) ?: text
val actions = listOf(
SmartAction(
- label = "📶 Connect Wi-Fi: $ssid",
+ label = strings(R.string.smart_connect_wi_fi, ssid),
prompt = encode(TYPE_COPY, "SSID: $ssid, Password: $pass"),
actionType = ActionType.NATIVE_COPY,
isPrimary = true
@@ -995,9 +1010,9 @@ object SmartActionDetector {
}
/** Build a native "fetch this URL and summarize" action. */
- fun fetchAction(url: String): SmartAction =
+ fun fetchAction(url: String, strings: StringLookup): SmartAction =
SmartAction(
- label = "🔗 Summarize: ${snippet(prettyUrl(url), 30)}",
+ label = strings(R.string.smart_summarize_2, snippet(prettyUrl(url), 30)),
prompt = encode(TYPE_FETCH, url.trim()),
actionType = ActionType.LLM_SUMMARIZE,
isPrimary = true
diff --git a/app/src/main/java/com/gotcha/service/WakeWordDetector.kt b/app/src/main/java/com/gotcha/service/WakeWordDetector.kt
index cc8ddc4..2416b86 100644
--- a/app/src/main/java/com/gotcha/service/WakeWordDetector.kt
+++ b/app/src/main/java/com/gotcha/service/WakeWordDetector.kt
@@ -13,6 +13,7 @@ import android.os.Process
import android.util.Log
import androidx.core.content.ContextCompat
import com.gotcha.BuildConfig
+import com.gotcha.R
import com.gotcha.util.GotchaLog
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@@ -110,7 +111,7 @@ class WakeWordDetector(
if (ContextCompat.checkSelfPermission(appContext, Manifest.permission.RECORD_AUDIO) !=
PackageManager.PERMISSION_GRANTED
) {
- lastError = "Microphone permission is not granted."
+ lastError = appContext.getString(R.string.wake_word_no_mic)
return false
}
synchronized(stateLock) {
@@ -458,7 +459,7 @@ class WakeWordDetector(
return
}
} catch (e: Exception) {
- if (running.get()) fail("Wake word listening stopped unexpectedly.", e, generation)
+ if (running.get()) fail(appContext.getString(R.string.wake_word_stopped), e, generation)
} finally {
Process.setThreadPriority(callerPriority)
}
@@ -583,9 +584,9 @@ class WakeWordDetector(
}
private fun startupError(error: Exception): String = when (error) {
- is SecurityException -> "Microphone permission is not available."
- is IOException -> "The bundled wake-word model could not be loaded."
- else -> "Wake word could not start."
+ is SecurityException -> appContext.getString(R.string.wake_word_mic_unavailable)
+ is IOException -> appContext.getString(R.string.wake_word_model_failed)
+ else -> appContext.getString(R.string.wake_word_start_failed)
}
companion object {
diff --git a/app/src/main/java/com/gotcha/ui/ScreenCropOverlayView.kt b/app/src/main/java/com/gotcha/ui/ScreenCropOverlayView.kt
index 9029216..2f0d7e7 100644
--- a/app/src/main/java/com/gotcha/ui/ScreenCropOverlayView.kt
+++ b/app/src/main/java/com/gotcha/ui/ScreenCropOverlayView.kt
@@ -15,6 +15,7 @@ import android.view.MotionEvent
import android.view.View
import androidx.core.graphics.ColorUtils
import com.gotcha.R
+import com.gotcha.i18n.stringLookup
import com.gotcha.service.AnnotatedEntity
import com.gotcha.service.SmartActionDetector
import com.gotcha.ui.theme.OverlaySkin
@@ -407,7 +408,7 @@ class ScreenCropOverlayView(
val labelStr = if (index == 0 && item.groupCount == 1) {
action.label
} else {
- SmartActionDetector.chipLabel(item.entity, item.groupCount)
+ SmartActionDetector.chipLabel(item.entity, item.groupCount, strings = context.stringLookup())
}
val chipW = entityChipTextPaint.measureText(labelStr) + padding * 2f
val chipH = CHIP_HEIGHT_DP * density
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index a11ff92..67643b7 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1225,4 +1225,146 @@
<string name="action_stop">Stop</string>
<string name="channel_run">Task in progress</string>
<string name="channel_run_description">Shown while Gotcha works on a task, so Android keeps it running when you switch to another app</string>
+
+ <!-- Voice call errors -->
+ <string name="call_error_no_api_key">Set up your API key in Gotcha first.</string>
+ <string name="call_error_no_mic">Microphone permission not granted. Enable it in Gotcha → Settings → Permissions.</string>
+ <string name="call_error_tts_playback">Couldn\'t play voice audio — check your Text-to-Speech settings.</string>
+ <string name="call_error_mic_start">Couldn\'t start the microphone — tap again to retry.</string>
+ <string name="call_error_reply_playback">Couldn\'t play the voice reply — check your Text-to-Speech settings.</string>
+ <string name="call_error_permission">A permission is needed that can\'t be granted during a call — open Gotcha to grant it.</string>
+ <string name="call_confirmation_needed">Confirmation needed: %1$s</string>
+ <string name="call_stt_label">Speech-to-text</string>
+ <string name="call_tts_label">Text-to-speech</string>
+ <string name="call_audio_not_configured">%1$s is not configured. Set it up in Gotcha → Settings → Speech (TTS / STT).</string>
+ <string name="call_audio_samosa_not_configured">%1$s Samosa AI is not configured. Sign in from Gotcha → Settings → Speech (TTS / STT).</string>
+ <string name="call_audio_model_missing">%1$s model is not selected. Choose one in Gotcha → Settings → Speech (TTS / STT).</string>
+ <string name="call_audio_url_invalid">%1$s API URL is missing or invalid. Fix it in Gotcha → Settings → Speech (TTS / STT).</string>
+ <string name="call_audio_api_model_missing">%1$s API model is not selected. Choose one in Gotcha → Settings → Speech (TTS / STT).</string>
+ <string name="screenshot_channel">Screenshot Capture</string>
+ <string name="screenshot_channel_description">One-shot screen capture</string>
+ <string name="screenshot_capturing">Capturing screenshot…</string>
+ <string name="wake_word_no_mic">Microphone permission is not granted.</string>
+ <string name="wake_word_mic_unavailable">Microphone permission is not available.</string>
+ <string name="wake_word_model_failed">The bundled wake-word model could not be loaded.</string>
+ <string name="wake_word_start_failed">Wake word could not start.</string>
+ <string name="wake_word_stopped">Wake word listening stopped unexpectedly.</string>
+
+ <!-- Smart actions (chips over other apps) -->
+ <string name="smart_translate_to">🌐 Translate to %1$s</string>
+ <string name="smart_draft_reply">💬 Draft reply: %1$s</string>
+ <string name="smart_copy_text">📋 Copy text</string>
+ <string name="smart_copy_code">🔑 Copy code %1$s</string>
+ <string name="smart_share_code">📤 Share code</string>
+ <string name="smart_dial">📞 Dial %1$s</string>
+ <string name="smart_sms">💬 SMS</string>
+ <string name="smart_whatsapp">💬 WhatsApp</string>
+ <string name="smart_save_contact">👤 Save contact</string>
+ <string name="smart_copy_number">📋 Copy number</string>
+ <string name="smart_navigate">📍 Navigate: %1$s</string>
+ <string name="smart_copy_address">📋 Copy address</string>
+ <string name="smart_share_address">📤 Share address</string>
+ <string name="smart_compose">📧 Compose: %1$s</string>
+ <string name="smart_copy_email">📋 Copy email</string>
+ <string name="smart_share_email">📤 Share email</string>
+ <string name="smart_open">🌐 Open: %1$s</string>
+ <string name="smart_summarize">📝 Summarize</string>
+ <string name="smart_copy_link">📋 Copy link</string>
+ <string name="smart_share_link">📤 Share link</string>
+ <string name="smart_convert_to">💵 Convert to %1$s</string>
+ <string name="smart_copy_price">📋 Copy price</string>
+ <string name="smart_add_to_calendar">📅 Add to calendar: %1$s</string>
+ <string name="smart_copy_event">📋 Copy event</string>
+ <string name="smart_track">📦 Track %1$s: %2$s</string>
+ <string name="smart_copy_tracking_number">📋 Copy tracking number</string>
+ <string name="smart_connect_wi_fi">📶 Connect Wi-Fi: %1$s</string>
+ <string name="smart_summarize_2">🔗 Summarize: %1$s</string>
+ <string name="smart_group_codes">%1$d codes</string>
+ <string name="smart_group_numbers">%1$d numbers</string>
+ <string name="smart_group_addresses">%1$d addresses</string>
+ <string name="smart_group_emails">%1$d emails</string>
+ <string name="smart_group_links">%1$d links</string>
+ <string name="smart_group_dates">%1$d dates</string>
+ <string name="smart_group_prices">%1$d prices</string>
+ <string name="smart_group_packages">%1$d packages</string>
+ <string name="smart_group_messages">%1$d messages</string>
+ <string name="smart_group_items">%1$d items</string>
+
+ <!-- QR codes and barcodes -->
+ <string name="qr_open_qr_link">🌐 Open QR Link: %1$s</string>
+ <string name="qr_summarize">📝 Summarize</string>
+ <string name="qr_copy_url">📋 Copy URL</string>
+ <string name="qr_wi_fi">📶 Wi-Fi: %1$s</string>
+ <string name="qr_call">📞 Call: %1$s</string>
+ <string name="qr_pay_via_upi">💳 Pay via UPI: %1$s</string>
+ <string name="qr_copy_upi_link">📋 Copy UPI Link</string>
+ <string name="qr_copy_link">📋 Copy Link</string>
+ <string name="qr_search_barcode">🔍 Search Barcode: %1$s</string>
+ <string name="qr_copy_barcode">📋 Copy Barcode</string>
+ <string name="qr_ask_assistant">🤖 Ask Assistant</string>
+ <string name="qr_copy_qr_content">📋 Copy QR Content</string>
+ <string name="qr_qr_link">QR Link: %1$s</string>
+ <string name="qr_wi_fi_qr">Wi-Fi QR: %1$s</string>
+ <string name="qr_qr_phone">QR Phone: %1$s</string>
+ <string name="qr_upi_payment">UPI Payment: %1$s</string>
+ <string name="qr_barcode">Barcode: %1$s</string>
+ <string name="qr_qr">QR: %1$s</string>
+
+ <!-- ScreenLensController -->
+ <string name="lens_couldn_t_start_lens_mode">Couldn\'t start Lens mode</string>
+ <string name="lens_accessibility_service_not_available">Accessibility service not available</string>
+ <string name="lens_screenshot_failed_try_again">Screenshot failed — try again</string>
+ <string name="lens_selection_was_empty">Selection was empty</string>
+ <string name="lens_failed_to_save_image">Failed to save image: %1$s</string>
+ <string name="lens_couldn_t_prepare_the_image">Couldn\'t prepare the image</string>
+ <string name="lens_select">Select</string>
+ <string name="lens_copy">Copy</string>
+ <string name="lens_translate">Translate</string>
+ <string name="lens_save">Save</string>
+ <string name="lens_ask">Ask</string>
+ <string name="lens_copy_selected">Copy Selected</string>
+ <string name="lens_copy_all">Copy All</string>
+ <string name="lens_close">Close</string>
+ <string name="lens_select_some_text_first_then">Select some text first, then tap Copy Selected</string>
+ <string name="lens_copied_to_clipboard">Copied to clipboard</string>
+ <string name="lens_saved_image_to">Saved image to %1$s</string>
+ <string name="lens_extracted_text">Extracted Text</string>
+
+ <!-- Assistive ball: clipboard and Screen Companion -->
+ <string name="ball_translate_clip">🌐 Translate: %1$s</string>
+ <string name="ball_summarize_clip">📋 Summarize: %1$s</string>
+ <string name="companion_screenshot_extract">📸 Screenshot taken. Extract text?</string>
+ <string name="companion_screenshot_translate">🌐 Translate Screenshot</string>
+ <string name="companion_no_response">No response</string>
+ <string name="companion_error">Error: %1$s</string>
+ <string name="companion_summarize_link">Summarize link:\n%1$s</string>
+ <string name="companion_fetching">Fetching %1$s …</string>
+ <string name="companion_fetch_failed">Couldn\'t fetch the link: %1$s</string>
+ <string name="companion_summarizing">Summarizing …</string>
+
+ <!-- Assistive ball: clipboard and Screen Companion -->
+
+ <!-- AssistiveBallService -->
+ <string name="ball_could_not_fetch_exchange_rate">Could not fetch exchange rate for %1$s</string>
+ <string name="ball_couldn_t_open_action">Couldn\'t open action: %1$s</string>
+ <string name="ball_microphone_permission_not_granted">Microphone permission not granted.</string>
+ <string name="ball_failed_to_start_speech_recognition">Failed to start speech recognition.</string>
+ <string name="ball_failed_to_start_recording">Failed to start recording.</string>
+ <string name="ball_no_stt_provider_configured_enable">No STT provider configured. Enable one in settings.</string>
+ <string name="ball_transcription_failed">Transcription failed: %1$s</string>
+ <string name="ball_no_tts_provider_configured_enable">No TTS provider configured. Enable one in settings.</string>
+ <string name="ball_accessibility_service_not_available">Accessibility service not available</string>
+ <string name="ball_screenshot_failed_try_again">Screenshot failed — try again</string>
+ <string name="ball_screenshot_error">Screenshot error: %1$s</string>
+ <string name="ball_region_attached_ask_a_question">📸 Region attached — ask a question about it below.</string>
+ <string name="ball_region_attached">📸 Region attached</string>
+ <string name="ball_ask_me_anything_about_the">Ask me anything about the selected region.</string>
+ <string name="ball_thinking">Thinking...</string>
+ <string name="ball_no_text_found_in_selection">No text found in selection</string>
+ <string name="ball_copied_to_clipboard">Copied to clipboard</string>
+ <string name="ball_couldn_t_read_text">Couldn\'t read text: %1$s</string>
+ <string name="ball_error">Error: %1$s</string>
+
+ <!-- GotchaNotificationListenerService -->
+ <string name="notification_listener_otp_copied_to_clipboard">🔑 OTP %1$s copied to clipboard</string>
</resources>
diff --git a/app/src/test/java/com/gotcha/service/SmartActionDetectorTest.kt b/app/src/test/java/com/gotcha/service/SmartActionDetectorTest.kt
index 30503c7..7a2c46d 100644
--- a/app/src/test/java/com/gotcha/service/SmartActionDetectorTest.kt
+++ b/app/src/test/java/com/gotcha/service/SmartActionDetectorTest.kt
@@ -1,15 +1,24 @@
package com.gotcha.service
+import android.content.Context
+import androidx.test.core.app.ApplicationProvider
+import com.gotcha.i18n.stringLookup
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.RobolectricTestRunner
import java.time.LocalDate
+@RunWith(RobolectricTestRunner::class)
class SmartActionDetectorTest {
+ /** Chip labels are string resources; Robolectric reads the English ones. */
+ private val strings = ApplicationProvider.getApplicationContext<Context>().stringLookup()
+
// ---- Multi-Entity detectAll() ----
@Test
@@ -21,7 +30,7 @@ class SmartActionDetectorTest {
Your verification OTP code is 849201.
""".trimIndent()
- val entities = SmartActionDetector.detectAll(text)
+ val entities = SmartActionDetector.detectAll(text, strings = strings)
assertTrue(entities.isNotEmpty())
val types = entities.map { it.type }
@@ -45,7 +54,7 @@ class SmartActionDetectorTest {
Mountain View, CA 94043
""".trimIndent()
- val entities = SmartActionDetector.detectAll(text)
+ val entities = SmartActionDetector.detectAll(text, strings = strings)
val address = entities.firstOrNull { it.type == EntityType.ADDRESS }
assertNotNull(address)
assertTrue(address!!.normalizedValue.contains("Amphitheatre Pkwy"))
@@ -64,14 +73,18 @@ class SmartActionDetectorTest {
@Test
fun `detectAll finds INR and dollar currency prices`() {
val text = "Item price is ₹1250 ($15.00 USD)"
- val entities = SmartActionDetector.detectAll(text)
+ val entities = SmartActionDetector.detectAll(text, strings = strings)
val currencies = entities.filter { it.type == EntityType.CURRENCY }
assertTrue(currencies.isNotEmpty())
}
@Test
fun `detectCurrencies omits conversion when price is already in target currency`() {
- val entitiesUsd = SmartActionDetector.detectAll("Price is $50.00 USD", targetCurrency = "USD")
+ val entitiesUsd = SmartActionDetector.detectAll(
+ "Price is $50.00 USD",
+ targetCurrency = "USD",
+ strings = strings
+ )
val currencyUsd = entitiesUsd.firstOrNull { it.type == EntityType.CURRENCY }
assertNotNull(currencyUsd)
assertFalse(
@@ -79,7 +92,7 @@ class SmartActionDetectorTest {
currencyUsd!!.actions.any { it.label.contains("Convert to USD") }
)
- val entitiesEur = SmartActionDetector.detectAll("Price is €50.00", targetCurrency = "USD")
+ val entitiesEur = SmartActionDetector.detectAll("Price is €50.00", targetCurrency = "USD", strings = strings)
val currencyEur = entitiesEur.firstOrNull { it.type == EntityType.CURRENCY }
assertNotNull(currencyEur)
assertTrue(
@@ -90,7 +103,7 @@ class SmartActionDetectorTest {
@Test
fun `detectAll finds Indian-format comma-grouped currency INR`() {
- val entities = SmartActionDetector.detectAll("Total is INR1,23,456")
+ val entities = SmartActionDetector.detectAll("Total is INR1,23,456", strings = strings)
val currency = entities.firstOrNull { it.type == EntityType.CURRENCY }
assertNotNull("Should detect INR1,23,456 as a currency", currency)
assertTrue("rawValue should contain the full number", currency!!.rawValue.contains("1,23,456"))
@@ -99,7 +112,7 @@ class SmartActionDetectorTest {
@Test
fun `detectAll finds rupee symbol with Indian comma grouping and decimal`() {
- val entities = SmartActionDetector.detectAll("Price is ₹12,34,567.89")
+ val entities = SmartActionDetector.detectAll("Price is ₹12,34,567.89", strings = strings)
val currency = entities.firstOrNull { it.type == EntityType.CURRENCY }
assertNotNull("Should detect ₹12,34,567.89 as a currency", currency)
assertTrue(currency!!.rawValue.contains("12,34,567.89"))
@@ -108,14 +121,14 @@ class SmartActionDetectorTest {
@Test
fun `detectAll finds western comma-formatted dollar amount`() {
- val entities = SmartActionDetector.detectAll("Total is $1,234,567.89 USD")
+ val entities = SmartActionDetector.detectAll("Total is $1,234,567.89 USD", strings = strings)
val currency = entities.firstOrNull { it.type == EntityType.CURRENCY }
assertNotNull("Should detect $1,234,567.89 USD as a currency", currency)
}
@Test
fun `detectAll finds Rs format with Indian comma grouping`() {
- val entities = SmartActionDetector.detectAll("Cost Rs. 12,34,567")
+ val entities = SmartActionDetector.detectAll("Cost Rs. 12,34,567", strings = strings)
val currency = entities.firstOrNull { it.type == EntityType.CURRENCY }
assertNotNull("Should detect Rs. 12,34,567 as a currency", currency)
assertTrue(currency!!.rawValue.contains("12,34,567"))
@@ -123,7 +136,7 @@ class SmartActionDetectorTest {
@Test
fun `detectAll finds euro symbol with comma-grouped thousands`() {
- val entities = SmartActionDetector.detectAll("Price is €1,234.56", targetCurrency = "USD")
+ val entities = SmartActionDetector.detectAll("Price is €1,234.56", targetCurrency = "USD", strings = strings)
val currency = entities.firstOrNull { it.type == EntityType.CURRENCY }
assertNotNull("Should detect €1,234.56 as a currency", currency)
assertTrue(currency!!.actions.any { it.label.contains("Convert") })
@@ -131,7 +144,7 @@ class SmartActionDetectorTest {
@Test
fun `detectAll still finds plain digit currency amounts`() {
- val entities = SmartActionDetector.detectAll("Price is ₹1250")
+ val entities = SmartActionDetector.detectAll("Price is ₹1250", strings = strings)
val currency = entities.firstOrNull { it.type == EntityType.CURRENCY }
assertNotNull("Should still detect plain ₹1250", currency)
}
@@ -156,7 +169,7 @@ class SmartActionDetectorTest {
@Test
fun `detectAll finds email addresses and generates compose mail actions`() {
- val entities = SmartActionDetector.detectAll("Contact [email protected] for details")
+ val entities = SmartActionDetector.detectAll("Contact [email protected] for details", strings = strings)
val email = entities.firstOrNull { it.type == EntityType.EMAIL }
assertNotNull(email)
assertEquals("[email protected]", email!!.normalizedValue)
@@ -165,7 +178,7 @@ class SmartActionDetectorTest {
@Test
fun `detectAll suppresses URL detection when domain is part of an email address`() {
- val entities = SmartActionDetector.detectAll("Reach out at [email protected]")
+ val entities = SmartActionDetector.detectAll("Reach out at [email protected]", strings = strings)
val emails = entities.filter { it.type == EntityType.EMAIL }
val urls = entities.filter { it.type == EntityType.URL }
assertEquals(1, emails.size)
@@ -175,7 +188,10 @@ class SmartActionDetectorTest {
@Test
fun `detectAll finds tracking numbers`() {
- val entities = SmartActionDetector.detectAll("Your package 1Z9999999999999999 is out for delivery")
+ val entities = SmartActionDetector.detectAll(
+ "Your package 1Z9999999999999999 is out for delivery",
+ strings = strings
+ )
val tracking = entities.firstOrNull { it.type == EntityType.TRACKING_NUMBER }
assertNotNull(tracking)
assertEquals("1Z9999999999999999", tracking!!.normalizedValue)
@@ -186,7 +202,7 @@ class SmartActionDetectorTest {
@Test
fun `detects punctuated phone number and encodes a dial action`() {
- val action = SmartActionDetector.detect("Call me at (415) 555-2671 tomorrow")
+ val action = SmartActionDetector.detect("Call me at (415) 555-2671 tomorrow", strings = strings)
assertNotNull(action)
assertTrue(action!!.label.contains("Dial"))
assertTrue(SmartActionDetector.isNativeAction(action.prompt))
@@ -197,31 +213,31 @@ class SmartActionDetectorTest {
@Test
fun `detects dashed phone number`() {
- val action = SmartActionDetector.detect("Reach us on 415-555-2671")
+ val action = SmartActionDetector.detect("Reach us on 415-555-2671", strings = strings)
assertNotNull(action)
assertEquals(SmartActionDetector.TYPE_DIAL, SmartActionDetector.decode(action!!.prompt)!!.first)
}
@Test
fun `detects international phone number`() {
- val action = SmartActionDetector.detect("Ring +44 20 7946 0958 for support")
+ val action = SmartActionDetector.detect("Ring +44 20 7946 0958 for support", strings = strings)
assertNotNull(action)
assertEquals(SmartActionDetector.TYPE_DIAL, SmartActionDetector.decode(action!!.prompt)!!.first)
}
@Test
fun `does not treat a bare digit run as a phone number`() {
- assertNull(SmartActionDetector.detect("Your order 4155552671 has shipped"))
+ assertNull(SmartActionDetector.detect("Your order 4155552671 has shipped", strings = strings))
}
@Test
fun `does not match digits embedded in a longer number`() {
- assertNull(SmartActionDetector.detect("SKU 004155552671003 in stock"))
+ assertNull(SmartActionDetector.detect("SKU 004155552671003 in stock", strings = strings))
}
@Test
fun `detects street address and encodes a navigate action`() {
- val action = SmartActionDetector.detect("Meet at 1600 Amphitheatre Parkway Way for lunch")
+ val action = SmartActionDetector.detect("Meet at 1600 Amphitheatre Parkway Way for lunch", strings = strings)
assertNotNull(action)
assertTrue(action!!.label.contains("Navigate"))
val (type, _) = SmartActionDetector.decode(action.prompt)!!
@@ -230,38 +246,38 @@ class SmartActionDetectorTest {
@Test
fun `proactive detect never offers currency`() {
- assertNull(SmartActionDetector.detect("The jacket costs €89.99 in Berlin"))
+ assertNull(SmartActionDetector.detect("The jacket costs €89.99 in Berlin", strings = strings))
}
@Test
fun `proactive detect never offers calendar`() {
- assertNull(SmartActionDetector.detect("Let's schedule a meeting on Monday"))
+ assertNull(SmartActionDetector.detect("Let's schedule a meeting on Monday", strings = strings))
}
@Test
fun `chat reply only fires when allowChat is set`() {
val text = "Hey, are you free later?"
- assertNull(SmartActionDetector.detect(text, allowChat = false))
- val action = SmartActionDetector.detect(text, allowChat = true)
+ assertNull(SmartActionDetector.detect(text, allowChat = false, strings = strings))
+ val action = SmartActionDetector.detect(text, allowChat = true, strings = strings)
assertNotNull(action)
assertTrue(action!!.label.contains("Draft reply"))
}
@Test
fun `plain prose returns no action`() {
- assertNull(SmartActionDetector.detect("The quick brown fox jumps over the lazy dog."))
+ assertNull(SmartActionDetector.detect("The quick brown fox jumps over the lazy dog.", strings = strings))
}
@Test
fun `blank input returns no action`() {
- assertNull(SmartActionDetector.detect(" "))
+ assertNull(SmartActionDetector.detect(" ", strings = strings))
}
// ---- Lens-mode detectContextual() ----
@Test
fun `contextual detection finds currency`() {
- val actions = SmartActionDetector.detectContextual("The jacket costs €89.99")
+ val actions = SmartActionDetector.detectContextual("The jacket costs €89.99", strings = strings)
assertTrue(actions.any { it.label.contains("Convert") })
val currency = actions.first { it.label.contains("Convert") }
// Currency conversion now uses the native TYPE_CONVERT action (not an LLM prompt)
@@ -271,7 +287,7 @@ class SmartActionDetectorTest {
@Test
fun `contextual detection finds calendar event`() {
- val actions = SmartActionDetector.detectContextual("Team meeting on Monday")
+ val actions = SmartActionDetector.detectContextual("Team meeting on Monday", strings = strings)
val cal = actions.firstOrNull { it.label.contains("calendar") }
assertNotNull(cal)
assertEquals(SmartActionDetector.TYPE_CALENDAR, SmartActionDetector.decode(cal!!.prompt)!!.first)
@@ -279,7 +295,7 @@ class SmartActionDetectorTest {
@Test
fun `contextual detection finds month-day time event`() {
- val actions = SmartActionDetector.detectContextual("Flight on July 20 at 9:10 a.m.")
+ val actions = SmartActionDetector.detectContextual("Flight on July 20 at 9:10 a.m.", strings = strings)
val cal = actions.firstOrNull { it.label.contains("calendar") }
assertNotNull(cal)
assertEquals(SmartActionDetector.TYPE_CALENDAR, SmartActionDetector.decode(cal!!.prompt)!!.first)
@@ -287,7 +303,7 @@ class SmartActionDetectorTest {
@Test
fun `contextual detection finds address with city and zip`() {
- val actions = SmartActionDetector.detectContextual("Ship to 350 5th Ave, New York, NY 10118")
+ val actions = SmartActionDetector.detectContextual("Ship to 350 5th Ave, New York, NY 10118", strings = strings)
val addr = actions.firstOrNull { it.label.contains("Navigate") }
assertNotNull(addr)
assertEquals(SmartActionDetector.TYPE_NAVIGATE, SmartActionDetector.decode(addr!!.prompt)!!.first)
@@ -295,7 +311,7 @@ class SmartActionDetectorTest {
@Test
fun `contextual detection returns empty for plain prose`() {
- assertTrue(SmartActionDetector.detectContextual("just some words here").isEmpty())
+ assertTrue(SmartActionDetector.detectContextual("just some words here", strings = strings).isEmpty())
}
// ---- Snippets in labels ----
@@ -309,7 +325,7 @@ class SmartActionDetectorTest {
@Test
fun `fetch action label shows a url snippet`() {
- val action = SmartActionDetector.fetchAction("https://www.example.com/very/long/path/here")
+ val action = SmartActionDetector.fetchAction("https://www.example.com/very/long/path/here", strings)
assertTrue(action.label.contains("example.com"))
assertEquals(
"https://www.example.com/very/long/path/here",
@@ -325,7 +341,7 @@ class SmartActionDetectorTest {
@Test
fun `qr code and barcode entities have highest priority over OTP and phone`() {
val text = "Your OTP is 123456. Connect to WIFI:S:HomeNet;P:secret123;T:WPA;;"
- val entities = SmartActionDetector.detectAll(text)
+ val entities = SmartActionDetector.detectAll(text, strings = strings)
assertTrue(entities.isNotEmpty())
assertEquals(EntityType.QR_CODE, entities.first().type)
assertTrue(entities.first().normalizedValue.contains("HomeNet"))
@@ -337,7 +353,8 @@ class SmartActionDetectorTest {
fun `past dates are not calendar events`() {
val entities = SmartActionDetector.detectAll(
"Rebase #53 by DevUser2 was merged Jul 26, 2026",
- now = NOON_AUG_1
+ now = NOON_AUG_1,
+ strings = strings
)
assertTrue(
"A merge timestamp is not something to put on a calendar",
@@ -349,7 +366,8 @@ class SmartActionDetectorTest {
fun `future dates are still calendar events`() {
val entities = SmartActionDetector.detectAll(
"Design review Aug 14, 2026",
- now = NOON_AUG_1
+ now = NOON_AUG_1,
+ strings = strings
)
assertTrue(entities.any { it.type == EntityType.CALENDAR })
}
@@ -372,9 +390,9 @@ class SmartActionDetectorTest {
@Test
fun `an event word outranks a bare time`() {
- val worded = SmartActionDetector.detectAll("Dinner tomorrow", now = NOON_AUG_1)
+ val worded = SmartActionDetector.detectAll("Dinner tomorrow", now = NOON_AUG_1, strings = strings)
.first { it.type == EntityType.CALENDAR }
- val bare = SmartActionDetector.detectAll("Doors open 8 pm", now = NOON_AUG_1)
+ val bare = SmartActionDetector.detectAll("Doors open 8 pm", now = NOON_AUG_1, strings = strings)
.first { it.type == EntityType.CALENDAR }
assertTrue(bare.confidence < worded.confidence)
}
@@ -385,7 +403,8 @@ class SmartActionDetectorTest {
// which is not before today, so a date-only check let it through.
val entities = SmartActionDetector.detectAll(
"rebase #64 by DevUser2 was merged Aug 1, 2026, 9:14 a.m.",
- now = NOON_AUG_1
+ now = NOON_AUG_1,
+ strings = strings
)
assertTrue(
"A merge from this morning is not an event this afternoon",
@@ -395,7 +414,7 @@ class SmartActionDetectorTest {
@Test
fun `an event later today survives`() {
- val entities = SmartActionDetector.detectAll("Dinner today at 8 pm", now = NOON_AUG_1)
+ val entities = SmartActionDetector.detectAll("Dinner today at 8 pm", now = NOON_AUG_1, strings = strings)
assertTrue(entities.any { it.type == EntityType.CALENDAR })
}
@@ -405,7 +424,8 @@ class SmartActionDetectorTest {
// there is nothing to compare against, so the day is the granularity.
val entities = SmartActionDetector.detectAll(
"Lunch today",
- now = LocalDate.of(2026, 8, 1).atTime(23, 30)
+ now = LocalDate.of(2026, 8, 1).atTime(23, 30),
+ strings = strings
)
assertTrue(entities.any { it.type == EntityType.CALENDAR })
}
@@ -427,7 +447,7 @@ class SmartActionDetectorTest {
@Test
fun `a list of merge timestamps produces no calendar annotations`() {
- val entities = SmartActionDetector.detectAll(pullRequestList, now = NOON_AUG_1)
+ val entities = SmartActionDetector.detectAll(pullRequestList, now = NOON_AUG_1, strings = strings)
val selected = SmartActionDetector.selectForAnnotation(entities)
assertTrue(
"Merge timestamps should not be annotated at all",
@@ -439,7 +459,7 @@ class SmartActionDetectorTest {
@Test
fun `annotations are capped however busy the screen is`() {
- val entities = SmartActionDetector.detectAll(pullRequestList, now = NOON_AUG_1)
+ val entities = SmartActionDetector.detectAll(pullRequestList, now = NOON_AUG_1, strings = strings)
val selected = SmartActionDetector.selectForAnnotation(entities)
assertTrue(
"Expected at most ${SmartActionDetector.MAX_ANNOTATIONS}, got ${selected.size}",
@@ -450,7 +470,7 @@ class SmartActionDetectorTest {
@Test
fun `a repeated type collapses to a single grouped annotation`() {
val catalogue = (1..12).joinToString("\n") { "Item $it — €${it * 10}.00" }
- val entities = SmartActionDetector.detectAll(catalogue)
+ val entities = SmartActionDetector.detectAll(catalogue, strings = strings)
val prices = entities.filter { it.type == EntityType.CURRENCY }
assertTrue("Fixture should detect many prices", prices.size >= 10)
@@ -458,7 +478,10 @@ class SmartActionDetectorTest {
val currency = selected.filter { it.entity.type == EntityType.CURRENCY }
assertEquals("Twelve prices are a catalogue, not twelve calls to action", 1, currency.size)
assertEquals(prices.size, currency.first().groupCount)
- assertEquals("💵 ${prices.size} prices", SmartActionDetector.chipLabel(currency.first().entity, prices.size))
+ assertEquals(
+ "💵 ${prices.size} prices",
+ SmartActionDetector.chipLabel(currency.first().entity, prices.size, strings = strings)
+ )
}
@Test
@@ -468,7 +491,7 @@ class SmartActionDetectorTest {
Visit https://example.com/help
""".trimIndent()
- val selected = SmartActionDetector.selectForAnnotation(SmartActionDetector.detectAll(text))
+ val selected = SmartActionDetector.selectForAnnotation(SmartActionDetector.detectAll(text, strings = strings))
val perType = selected.groupBy { it.entity.type }
for ((type, group) in perType) {
assertTrue(
@@ -482,7 +505,7 @@ class SmartActionDetectorTest {
@Test
fun `identical values collapse before ranking`() {
val text = "Ping [email protected] — again, [email protected] — once more, [email protected]"
- val selected = SmartActionDetector.selectForAnnotation(SmartActionDetector.detectAll(text))
+ val selected = SmartActionDetector.selectForAnnotation(SmartActionDetector.detectAll(text, strings = strings))
val emails = selected.filter { it.entity.type == EntityType.EMAIL }
assertEquals(1, emails.size)
assertEquals(3, emails.first().groupCount)
@@ -490,9 +513,9 @@ class SmartActionDetectorTest {
@Test
fun `chip labels drop the verb and keep the value`() {
- val entity = SmartActionDetector.detectAll("Visit https://example.com/help")
+ val entity = SmartActionDetector.detectAll("Visit https://example.com/help", strings = strings)
.first { it.type == EntityType.URL }
- val label = SmartActionDetector.chipLabel(entity)
+ val label = SmartActionDetector.chipLabel(entity, strings = strings)
assertTrue(label.startsWith("🌐"))
assertFalse("The verb belongs in the menu, not the chip", label.contains("Open:"))
}
@@ -505,7 +528,7 @@ class SmartActionDetectorTest {
@Test
fun `a grouped candidate carries every member, not just a count`() {
val catalogue = (1..12).joinToString("\n") { "Item $it — €${it * 10}.00" }
- val entities = SmartActionDetector.detectAll(catalogue)
+ val entities = SmartActionDetector.detectAll(catalogue, strings = strings)
val grouped = SmartActionDetector.selectForAnnotation(entities)
.first { it.entity.type == EntityType.CURRENCY }
@@ -522,7 +545,7 @@ class SmartActionDetectorTest {
// ---- Calendar payloads carry a resolved start ----
private fun calendarPayload(text: String, now: java.time.LocalDateTime): String {
- val entity = SmartActionDetector.detectAll(text, now = now)
+ val entity = SmartActionDetector.detectAll(text, now = now, strings = strings)
.first { it.type == EntityType.CALENDAR }
return SmartActionDetector.decode(entity.primaryAction!!.prompt)!!.second
}
@@ -564,7 +587,7 @@ class SmartActionDetectorTest {
fun `detectAll respects a French target language for currency labels`() {
// USD string with EUR target: the conversion action should mention EUR
// (the EUR label is what a French-user sees in the proactive action).
- val entities = SmartActionDetector.detectAll("Prix: \$50,00", targetCurrency = "EUR")
+ val entities = SmartActionDetector.detectAll("Prix: \$50,00", targetCurrency = "EUR", strings = strings)
val currency = entities.firstOrNull { it.type == EntityType.CURRENCY }
assertNotNull("USD-string should be detected as CURRENCY", currency)
assertTrue(
@@ -575,7 +598,7 @@ class SmartActionDetectorTest {
@Test
fun `detectAll respects a EUR target when source is USD`() {
- val entities = SmartActionDetector.detectAll("Total: \$50.00", targetCurrency = "EUR")
+ val entities = SmartActionDetector.detectAll("Total: \$50.00", targetCurrency = "EUR", strings = strings)
val currency = entities.firstOrNull { it.type == EntityType.CURRENCY }
assertNotNull(currency)
assertTrue(
@@ -586,7 +609,7 @@ class SmartActionDetectorTest {
@Test
fun `detectAll default target currency is USD when not specified`() {
- val entities = SmartActionDetector.detectAll("Price is €50")
+ val entities = SmartActionDetector.detectAll("Price is €50", strings = strings)
val currency = entities.firstOrNull { it.type == EntityType.CURRENCY }
assertNotNull(currency)
assertTrue(
@@ -597,7 +620,7 @@ class SmartActionDetectorTest {
@Test
fun `detectAll GBP target suppresses GBP conversion action`() {
- val entities = SmartActionDetector.detectAll("Price is £25.00", targetCurrency = "GBP")
+ val entities = SmartActionDetector.detectAll("Price is £25.00", targetCurrency = "GBP", strings = strings)
val currency = entities.firstOrNull { it.type == EntityType.CURRENCY }
assertNotNull(currency)
assertFalse(
@@ -614,7 +637,8 @@ class SmartActionDetectorTest {
val entities = SmartActionDetector.detectAll(
"Hola, ¿cómo estás?",
allowChat = true,
- targetLanguage = "French"
+ targetLanguage = "French",
+ strings = strings
)
val chat = entities.firstOrNull { it.type == EntityType.CHAT_REPLY }
assertNotNull("Should detect Spanish chat text with allowChat=true", chat)
@@ -630,7 +654,8 @@ class SmartActionDetectorTest {
val entities = SmartActionDetector.detectAll(
"How are you doing today?",
allowChat = true,
- targetLanguage = "English"
+ targetLanguage = "English",
+ strings = strings
)
val chat = entities.firstOrNull { it.type == EntityType.CHAT_REPLY }
assertNotNull(chat)
@@ -644,11 +669,12 @@ class SmartActionDetectorTest {
fun `call sites propagate the same targetCurrency and targetLanguage`() {
// Pin the shape of the call signature so any change to detectAll's
// parameter list surfaces here, not in a runtime ClassCastException.
- val a = SmartActionDetector.detectAll("100 USD", targetCurrency = "USD")
+ val a = SmartActionDetector.detectAll("100 USD", targetCurrency = "USD", strings = strings)
val b = SmartActionDetector.detectAll(
"100 EUR",
targetCurrency = "USD",
- targetLanguage = "English"
+ targetLanguage = "English",
+ strings = strings
)
assertNotNull(a.firstOrNull { it.type == EntityType.CURRENCY })
assertNotNull(b.firstOrNull { it.type == EntityType.CURRENCY })