Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1054,3 +1054,23 @@ English up in `assets/i18n/pt-BR.json`, falling back to the English when there i
value, or leave it English. Many still are; templates and service-layer text (insights,
notifications) are the known gaps.
- The coach answers in the app's language through `L10n.coachInstruction()`, appended to its prompts.

## A voice is a catalog layered on a language — and it stops at anything serious

**F*cking Health** (Settings → Language) is English with attitude: `AppLanguage.FUCKING_HEALTH_EN`
reads `assets/i18n/en-FH.json` first and falls back to the plain English key, and `Voice.FUNNY`
gives the coach and its notifications the persona through `L10n.coachInstruction()`.

- **A voice rewrites only some strings, on purpose.** A missing entry shows plain English, which is
right for settings, units, metric names and anything technical.
- **Safety text is never rewritten.** Crisis lines, clinician/pharmacist advice, warnings,
disclaimers, pregnancy/postpartum, medication and alcohol-support text keep their plain wording;
`FuckingHealthCatalogTest` fails if one appears in the catalog. The coach drops the act for the
same topics (`FUNNY_VOICE`).
- **The joke wraps the content.** Same facts, same values (`{0}` placeholders), same advice.
Roast habits, never the person. Swearing is censored (`f*cking`), and the test checks that too.
- **Adding the Portuguese version** is one enum entry and one file: `FUCKING_HEALTH_PT` with
`localeTag = "pt-BR"` and `catalogs = listOf("i18n/pt-BR-FH.json", "i18n/pt-BR.json")`, so a
string the Portuguese voice doesn't rewrite reads as plain Portuguese. Write the catalog in
Brazilian Portuguese (Brazilian censored swearing: p*rra, c*ralho, m*rda), not as a translation
of the English jokes, and extend `FuckingHealthCatalogTest` to cover it.
462 changes: 462 additions & 0 deletions app/src/main/assets/i18n/en-FH.json

Large diffs are not rendered by default.

741 changes: 719 additions & 22 deletions app/src/main/assets/i18n/pt-BR.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.pulseloop.health.accuracy

import com.pulseloop.ui.i18n.tr

import androidx.health.connect.client.permission.HealthPermission
import androidx.health.connect.client.records.ActiveCaloriesBurnedRecord
import androidx.health.connect.client.records.DistanceRecord
Expand All @@ -16,15 +18,16 @@ import kotlin.reflect.KClass
* What the accuracy check can compare, one entry per Health Connect record type it reads
* (docs/accuracy-check-plan.md, "Per metric"). Display order.
*/
enum class ReferenceMetric(val label: String, val recordType: KClass<out Record>) {
enum class ReferenceMetric(private val labelEn: String, val recordType: KClass<out Record>) {
STEPS("Steps", StepsRecord::class),
DISTANCE("Distance", DistanceRecord::class),
ACTIVE_CALORIES("Active calories", ActiveCaloriesBurnedRecord::class),
HEART_RATE("Heart rate", HeartRateRecord::class),
RESTING_HEART_RATE("Resting heart rate", RestingHeartRateRecord::class),
SLEEP("Sleep", SleepSessionRecord::class),
OXYGEN_SATURATION("Blood oxygen", OxygenSaturationRecord::class),
HRV("HRV", HeartRateVariabilityRmssdRecord::class),
HRV("HRV", HeartRateVariabilityRmssdRecord::class);
val label: String get() = tr(labelEn)
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.pulseloop.health.accuracy

import com.pulseloop.ui.i18n.tr

import com.pulseloop.data.entity.AccuracyCheckDayEntity
import java.time.Instant
import java.time.ZoneId
Expand All @@ -14,7 +16,7 @@ import kotlin.math.sqrt
* are computed differently by every vendor; sleep timing and stages are described, not adjusted).
*/
enum class ComparisonMetric(
val label: String,
private val labelEn: String,
val unit: String,
val kind: Kind,
val source: ReferenceMetric,
Expand All @@ -39,6 +41,7 @@ enum class ComparisonMetric(
SPO2("Blood oxygen", "%", Kind.PAIRED, ReferenceMetric.OXYGEN_SATURATION, 2.0, false, CorrectionKind.OFFSET, 3, 30),
HRV("HRV", "ms", Kind.DAILY, ReferenceMetric.HRV, 10.0, false, null, 3),
;
val label: String get() = tr(labelEn)

enum class Kind { DAILY, PAIRED, STAGES }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.pulseloop.notifications

import com.pulseloop.ui.i18n.tr

import android.Manifest
import android.app.NotificationChannel
import android.app.NotificationManager
Expand Down Expand Up @@ -31,7 +33,7 @@ object BatteryNotifications {
val channel = NotificationChannel(
CHANNEL_ID, "Ring Battery", NotificationManager.IMPORTANCE_DEFAULT
).apply {
description = "Alerts when your ring's battery runs low"
description = tr("Alerts when your ring's battery runs low")
}
val nm = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
nm.createNotificationChannel(channel)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.pulseloop.notifications

import com.pulseloop.ui.i18n.tr
import com.pulseloop.ui.i18n.trf

import android.content.Context
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.ProcessLifecycleOwner
Expand Down Expand Up @@ -525,7 +528,7 @@ private class CoachSlotProductionEngine(
val input = JsonArray(listOf(
JsonObject(mapOf(
"role" to JsonPrimitive("system"),
"content" to JsonPrimitive(NotificationPromptBuilder.systemPrompt(slot)),
"content" to JsonPrimitive(NotificationPromptBuilder.systemPrompt(slot) + com.pulseloop.ui.i18n.L10n.coachInstruction()),
)),
JsonObject(mapOf(
"role" to JsonPrimitive("developer"),
Expand Down Expand Up @@ -574,29 +577,29 @@ private class CoachSlotProductionEngine(
val h = sleep.totalMin / 60
val m = sleep.totalMin % 60
CoachNotificationContent(
title = "Good morning$name",
body = "You logged ${h}h ${m}m of sleep. Here's to a strong day — get moving when you can.",
title = trf("Good morning{0}", name),
body = trf("You logged {0}h {1}m of sleep. Here's to a strong day — get moving when you can.", h, m),
)
} else {
CoachNotificationContent(
title = "Good morning$name",
body = "Ready to start the day? Take a measurement and I'll help you plan it.",
title = trf("Good morning{0}", name),
body = tr("Ready to start the day? Take a measurement and I'll help you plan it."),
)
}
}
CoachNotificationSlot.EVENING -> {
val steps = packet.today.steps
if (steps != null) {
val goal = packet.goals.stepsDaily
val hit = if (steps >= goal) "You hit your $goal step goal — nice work." else "${goal - steps} steps to your goal."
val hit = if (steps >= goal) trf("You hit your {0} step goal — nice work.", goal) else trf("{0} steps to your goal.", goal - steps)
CoachNotificationContent(
title = "Evening check-in",
body = "$steps steps today. $hit Time to start winding down.",
title = tr("Evening check-in"),
body = trf("{0} steps today. {1} Time to start winding down.", steps, hit),
)
} else {
CoachNotificationContent(
title = "Evening check-in",
body = "How did today feel? Sync your ring and I'll recap your day.",
title = tr("Evening check-in"),
body = tr("How did today feel? Sync your ring and I'll recap your day."),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.pulseloop.notifications

import com.pulseloop.ui.i18n.tr

import android.Manifest
import android.app.NotificationChannel
import android.app.NotificationManager
Expand Down Expand Up @@ -33,7 +35,7 @@ object CoachNotifications {
val channel = NotificationChannel(
CHANNEL_ID, "Coach Check-ins", NotificationManager.IMPORTANCE_DEFAULT
).apply {
description = "Daily AI-generated health insights based on your ring data"
description = tr("Daily AI-generated health insights based on your ring data")
}
val nm = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
nm.createNotificationChannel(channel)
Expand Down
22 changes: 12 additions & 10 deletions app/src/main/java/com/pulseloop/notifications/GuidanceWorker.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.pulseloop.notifications

import com.pulseloop.ui.i18n.tr
import com.pulseloop.ui.i18n.trf

import android.Manifest
import android.app.NotificationChannel
import android.app.NotificationManager
Expand Down Expand Up @@ -141,8 +144,7 @@ class GuidanceWorker(context: Context, params: WorkerParameters) : CoroutineWork
// Drinks, for users who track them: the week that is ending, in one line.
val drinks = if (com.pulseloop.service.DrinkPrefs.enabled) runCatching {
val d = com.pulseloop.service.DrinksRepository.load(db, now, zone)
" Drinks: ${com.pulseloop.service.DrinkInsights.fmt(d.week.standardDrinks)} of ${com.pulseloop.service.DrinkInsights.fmt(d.weeklyLimit)}, " +
"${d.week.dryDays} dry day${if (d.week.dryDays == 1) "" else "s"}."
trf(" Drinks: {0} of {1}, {2} dry day{3}.", com.pulseloop.service.DrinkInsights.fmt(d.week.standardDrinks), com.pulseloop.service.DrinkInsights.fmt(d.weeklyLimit), d.week.dryDays, if (d.week.dryDays == 1) "" else "s")
}.getOrNull().orEmpty() else ""
val body = report + drinks
notify(ctx, ID_WEEKLY, title, body)
Expand All @@ -156,8 +158,8 @@ class GuidanceWorker(context: Context, params: WorkerParameters) : CoroutineWork
val minsToBed = minutesUntil(local.toLocalTime(), g.bedtime)
if (minsToBed in 15..45) {
notify(
ctx, ID_BEDTIME, "Time to wind down",
"Aim to be in bed by ${BedtimeGuidance.fmt(g.bedtime)} to get your ${inputs.sleepGoalMinutes / 60} hours before your usual ${BedtimeGuidance.fmt(g.usualWake)} wake-up.",
ctx, ID_BEDTIME, tr("Time to wind down"),
trf("Aim to be in bed by {0} to get your {1} hours before your usual {2} wake-up.", BedtimeGuidance.fmt(g.bedtime), inputs.sleepGoalMinutes / 60, BedtimeGuidance.fmt(g.usualWake)),
)
prefs.lastBedtimeReminderDay = today.toString()
}
Expand All @@ -169,7 +171,7 @@ class GuidanceWorker(context: Context, params: WorkerParameters) : CoroutineWork
val battery = db.deviceDao().currentReal()?.batteryPercent
val minsToBed = bedtime?.let { minutesUntil(local.toLocalTime(), it) }
if (Nudges.chargeBeforeBed(battery, minsToBed)) {
notify(ctx, ID_BATTERY, "Charge your ring before bed", "It's at $battery%. A short charge now keeps tonight's sleep tracked.")
notify(ctx, ID_BATTERY, tr("Charge your ring before bed"), trf("It's at {0}%. A short charge now keeps tonight's sleep tracked.", battery))
prefs.lastBatteryReminderDay = today.toString()
}
}
Expand All @@ -183,7 +185,7 @@ class GuidanceWorker(context: Context, params: WorkerParameters) : CoroutineWork
val fresh = device?.lastSyncAt?.let { now - it <= 40 * 60_000L } == true && buckets.isNotEmpty()
val lastHour = buckets.filter { it.startEpoch >= now - 3_600_000L }.sumOf { it.steps }
if (Nudges.inactive(local.hour, lastHour, fresh)) {
notify(ctx, ID_INACTIVE, "Time to move", "Under 100 steps in the last hour. A few minutes on your feet helps your energy and your sleep.")
notify(ctx, ID_INACTIVE, tr("Time to move"), tr("Under 100 steps in the last hour. A few minutes on your feet helps your energy and your sleep."))
prefs.lastInactivityAt = now
}
}
Expand All @@ -206,8 +208,8 @@ class GuidanceWorker(context: Context, params: WorkerParameters) : CoroutineWork
val fresh = due.filter { it.id !in prefs.remindedDoses }
if (fresh.isNotEmpty()) {
val names = fresh.joinToString(", ") { it.med.name + (it.med.dose?.let { d -> " $d" } ?: "") }
notify(ctx, ID_MEDS, "Time for ${fresh.first().med.name}" + if (fresh.size > 1) " and more" else "",
"$names. Open PulseLoop to mark it taken or skipped.")
notify(ctx, ID_MEDS, trf("Time for {0}", fresh.first().med.name) + if (fresh.size > 1) " and more" else "",
trf("{0}. Open PulseLoop to mark it taken or skipped.", names))
prefs.remindedDoses = (prefs.remindedDoses + fresh.map { it.id }).toList().takeLast(50).toSet()
}
}
Expand Down Expand Up @@ -256,7 +258,7 @@ class GuidanceWorker(context: Context, params: WorkerParameters) : CoroutineWork
private fun createChannel(context: Context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(CHANNEL_ID, "Daily guidance", NotificationManager.IMPORTANCE_DEFAULT).apply {
description = "Unusual-signal alerts, your weekly report and wind-down reminders"
description = tr("Unusual-signal alerts, your weekly report and wind-down reminders")
}
(context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).createNotificationChannel(channel)
}
Expand Down Expand Up @@ -302,7 +304,7 @@ object Nudges {
val left = goal - steps
val minutes = (left / 100.0).let { kotlin.math.ceil(it).toInt() }
return "${"%,d".format(left)} steps to your goal" to
"You're at ${"%,d".format(steps)} of ${"%,d".format(goal)}. About $minutes minutes of walking closes it."
trf("You're at {0} of {1}. About {2} minutes of walking closes it.", "%,d".format(steps), "%,d".format(goal), minutes)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.pulseloop.notifications

import com.pulseloop.ui.i18n.tr

import com.pulseloop.coach.context.EnvironmentContext
import com.pulseloop.ring.MeasurementKind
import com.pulseloop.data.PulseLoopDatabase
Expand Down Expand Up @@ -71,16 +73,16 @@ object NotificationContextBuilder {
val warnings = mutableListOf<String>()
val profileComplete = profile != null && profile.name != null && profile.age != null && profile.heightCm != null && profile.weightKg != null
if (!profileComplete) {
warnings.add("User profile is incomplete — insights may be less personalized.")
warnings.add(tr("User profile is incomplete — insights may be less personalized."))
}
// lastFullSyncAt (not lastSyncAt, which the ring re-stamps on every bare CONNECT before
// any data streams) — iOS #61c's freshness-gate fix.
val lastFullSync = device?.lastFullSyncAt
if (lastFullSync != null && (now - lastFullSync) > 12 * 3600_000L) {
warnings.add("Ring hasn't synced in >12h — today's data may be stale.")
warnings.add(tr("Ring hasn't synced in >12h — today's data may be stale."))
}
if (hrRows.size < 10) {
warnings.add("Limited HR data available for today.")
warnings.add(tr("Limited HR data available for today."))
}

return NotificationContextPacket(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.pulseloop.notifications

import com.pulseloop.ui.i18n.tr

import com.pulseloop.coach.context.EnvironmentContext

/**
Expand All @@ -10,9 +12,10 @@ import com.pulseloop.coach.context.EnvironmentContext
/**
* Notification slot types — ported from CoachNotificationSlot.swift.
*/
enum class CoachNotificationSlot(val label: String) {
enum class CoachNotificationSlot(private val labelEn: String) {
MORNING("Morning"),
EVENING("Evening");
val label: String get() = tr(labelEn)

companion object {
fun current(
Expand Down
11 changes: 7 additions & 4 deletions app/src/main/java/com/pulseloop/service/ActivityDetection.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.pulseloop.service

import com.pulseloop.ui.i18n.tr
import com.pulseloop.ui.i18n.trf

import android.content.Context
import com.pulseloop.data.PulseLoopDatabase
import com.pulseloop.ring.MeasurementKind
Expand Down Expand Up @@ -36,7 +39,7 @@ object ActivityDetection {
val s = runStart ?: return
if (count >= 2) {
val kind = if (fast * 2 > count) Proposal.Kind.RUN else Proposal.Kind.WALK
out += Proposal(kind, s, last + WINDOW, "%,d steps".format(total))
out += Proposal(kind, s, last + WINDOW, tr("%,d steps").format(total))
}
runStart = null; total = 0; fast = 0; count = 0
}
Expand All @@ -63,7 +66,7 @@ object ActivityDetection {
var start: Long? = null; var last = 0L; var peak = 0.0
fun close() {
val s = start ?: return
if (last - s >= 20 * 60_000L) out += Proposal(Proposal.Kind.CARDIO, s, last, "Heart rate up to ${peak.toInt()} bpm")
if (last - s >= 20 * 60_000L) out += Proposal(Proposal.Kind.CARDIO, s, last, trf("Heart rate up to {0} bpm", peak.toInt()))
start = null; peak = 0.0
}
for ((t, bpm) in hr.sortedBy { it.first }) {
Expand All @@ -88,7 +91,7 @@ object ActivityDetection {
fun close() {
val s = start ?: return
if (last - s >= 25 * 60_000L && n >= 4 && stepsBetween(s, last) < 60) {
out += Proposal(Proposal.Kind.NAP, s, last, "Heart rate stayed at your quiet level with no steps")
out += Proposal(Proposal.Kind.NAP, s, last, tr("Heart rate stayed at your quiet level with no steps"))
}
start = null; n = 0
}
Expand Down Expand Up @@ -160,7 +163,7 @@ suspend fun ActivityDetection.accept(c: Context, db: PulseLoopDatabase, p: Activ
val tag = JournalInsights.Tag.NAP.key
db.journalDao().upsert(com.pulseloop.data.entity.JournalEntryEntity(com.pulseloop.data.entity.JournalEntryEntity.idFor(day, tag), day, tag))
} else {
ManualActivityService.create(db, type, p.startAt, p.minutes.toDouble(), notes = "Detected by PulseLoop and confirmed")
ManualActivityService.create(db, type, p.startAt, p.minutes.toDouble(), notes = tr("Detected by PulseLoop and confirmed"))
}
answer(c, p)
}
Loading
Loading