Skip to content

Colota - Android GPS Location tracker

refactor(i18n): move Trip detail and Summary into the catalog (#908)

Max Dietrichbc8db7a516c6
diff --git a/apps/mobile/src/i18n/locales/en.json b/apps/mobile/src/i18n/locales/en.json
index e5b01140..2e1e1c82 100644
--- a/apps/mobile/src/i18n/locales/en.json
+++ b/apps/mobile/src/i18n/locales/en.json
@@ -601,5 +601,53 @@
"history.merge.confirmTitle_one": "Merge {{n}} trips?",
"history.merge.confirmTitle_other": "Merge {{n}} trips?",
"table.fact.delta_one": "{{n}} second after the previous point",
- "table.fact.delta_other": "{{n}} seconds after the previous point"
+ "table.fact.delta_other": "{{n}} seconds after the previous point",
+ "split.notATrip": "This point is not part of a trip. Colota leaves out runs that never travel more than 100 m.",
+ "split.alreadyBoundary": "This point already starts a trip.",
+ "split.tripTooShort": "This trip is too short to split. Splitting makes two trips, and each one needs at least two points.",
+ "split.tooShort": "A split needs at least two points on each side, so the first two and last two points of a trip cannot start a new one.",
+ "tripDetail.cannotSplit": "Cannot Split Here",
+ "tripDetail.stillLoading": "Still loading this trip's edits. Try again in a moment.",
+ "tripDetail.split.titleAt": "Start a new trip at {{time}}?",
+ "tripDetail.split.title": "Split Trip?",
+ "tripDetail.split.message": "Everything from this point onwards becomes a separate trip. Your location data is not changed, and you can undo this by merging the two trips again.",
+ "tripDetail.split.confirm": "Split",
+ "tripDetail.split.failed.title": "Split Failed",
+ "tripDetail.split.failed.message": "Unable to split the trip here. Please try again.",
+ "tripDetail.delete.title": "Delete {{name}}?",
+ "tripDetail.delete.message_one": "This permanently removes {{n}} location point from this device. Unsent points will not be uploaded.",
+ "tripDetail.delete.message_other": "This permanently removes {{n}} location points from this device. Unsent points will not be uploaded.",
+ "tripDetail.delete.failed": "Unable to delete trip. Please try again.",
+ "tripDetail.export": "Export trip",
+ "tripDetail.exportTitle": "Export {{name}}",
+ "tripDetail.deleteTrip": "Delete trip",
+ "tripDetail.previous": "Previous trip",
+ "tripDetail.next": "Next trip",
+ "tripDetail.distance": "Distance",
+ "tripDetail.duration": "Duration",
+ "tripDetail.avgSpeed": "Avg speed",
+ "tripDetail.points": "Points",
+ "tripDetail.elevGain": "Elev. gain",
+ "tripDetail.elevLoss": "Elev. loss",
+ "tripDetail.speed": "Speed",
+ "tripDetail.elevation": "Elevation",
+ "tripDetail.speedChart": "Speed over the trip, average {{avg}}, maximum {{max}}",
+ "summary.week": "Week",
+ "summary.month": "Month",
+ "summary.previous.week": "Previous week",
+ "summary.next.week": "Next week",
+ "summary.previous.month": "Previous month",
+ "summary.next.month": "Next month",
+ "summary.empty": "Nothing recorded",
+ "summary.distance": "Distance",
+ "summary.trips": "Trips",
+ "summary.activeDays": "Active days",
+ "summary.avgPerDay": "Avg / day",
+ "summary.opensDay": "Opens the day in Location History",
+ "summary.thisWeek": "This week",
+ "summary.lastWeek": "Last week",
+ "summary.weekOf": "Week of {{date}}",
+ "summary.thisMonth": "This month",
+ "summary.lastMonth": "Last month",
+ "tripDetail.maxSpeed": "max {{value}}"
}
diff --git a/apps/mobile/src/screens/LocationSummaryScreen.tsx b/apps/mobile/src/screens/LocationSummaryScreen.tsx
index 8a14ef67..def8b20d 100644
--- a/apps/mobile/src/screens/LocationSummaryScreen.tsx
+++ b/apps/mobile/src/screens/LocationSummaryScreen.tsx
@@ -16,23 +16,22 @@ import { formatDistance, formatDuration } from "../utils/geo"
import { logger } from "../utils/logger"
import { space } from "../constants"
import { dateOfDayKey, daysInRange, periodRange, periodTotals, rangeBounds, type Period } from "../utils/summaryPeriod"
+import { useTranslation } from "../i18n/useTranslation"
+import type { TranslationKey } from "../i18n/options"
// A year or all time would walk every row in the database; they return with a native daily rollup.
-const PERIODS: Array<{ value: Period; label: string }> = [
- { value: "week", label: "Week" },
- { value: "month", label: "Month" }
+const PERIODS: Array<{ value: Period; labelKey: TranslationKey }> = [
+ { value: "week", labelKey: "summary.week" },
+ { value: "month", labelKey: "summary.month" }
]
-function count(n: number, noun: string): string {
- return `${n} ${noun}${n === 1 ? "" : "s"}`
-}
-
function dayLabel(day: string): string {
return dateOfDayKey(day).toLocaleDateString(undefined, { weekday: "short", month: "short", day: "numeric" })
}
export function LocationSummaryScreen({ navigation }: { navigation: any }) {
const { colors } = useTheme()
+ const { t } = useTranslation()
const [period, setPeriod] = useState<Period>("week")
const [offset, setOffset] = useState(0)
// One read per shown period: the native daily stats walk every row in their window, so all
@@ -89,8 +88,8 @@ export function LocationSummaryScreen({ navigation }: { navigation: any }) {
caption={range.caption}
onPrevious={() => setOffset((o) => o + 1)}
onNext={() => setOffset((o) => Math.max(0, o - 1))}
- previousLabel={`Previous ${period}`}
- nextLabel={`Next ${period}`}
+ previousLabel={t(`summary.previous.${period}`)}
+ nextLabel={t(`summary.next.${period}`)}
nextDisabled={offset === 0}
testID="period"
/>
@@ -98,7 +97,7 @@ export function LocationSummaryScreen({ navigation }: { navigation: any }) {
{PERIODS.map((p) => (
<Tab
key={p.value}
- label={p.label}
+ label={t(p.labelKey)}
active={period === p.value}
onPress={() => choosePeriod(p.value)}
colors={colors}
@@ -111,17 +110,17 @@ export function LocationSummaryScreen({ navigation }: { navigation: any }) {
<ActivityIndicator size="large" color={colors.primary} />
</View>
) : days.length === 0 ? (
- <EmptyState icon={CalendarX} title="Nothing recorded" hint={range.caption} />
+ <EmptyState icon={CalendarX} title={t("summary.empty")} hint={range.caption} />
) : (
<ScrollView contentContainerStyle={styles.content}>
<Card rows testID="period-ledger">
- <StatRow icon={Route} label="Distance" value={formatDistance(totals.distanceMeters)} />
+ <StatRow icon={Route} label={t("summary.distance")} value={formatDistance(totals.distanceMeters)} />
<Divider tight inset />
- <StatRow icon={MapPin} label="Trips" value={String(totals.trips)} />
+ <StatRow icon={MapPin} label={t("summary.trips")} value={String(totals.trips)} />
<Divider tight inset />
- <StatRow icon={Calendar} label="Active days" value={String(totals.activeDays)} />
+ <StatRow icon={Calendar} label={t("summary.activeDays")} value={String(totals.activeDays)} />
<Divider tight inset />
- <StatRow icon={TrendingUp} label="Avg / day" value={formatDistance(totals.avgPerDay)} />
+ <StatRow icon={TrendingUp} label={t("summary.avgPerDay")} value={formatDistance(totals.avgPerDay)} />
</Card>
{
<Card rows testID="period-days">
@@ -131,9 +130,9 @@ export function LocationSummaryScreen({ navigation }: { navigation: any }) {
<ListItem
icon={Calendar}
label={dayLabel(day.day)}
- sub={`${formatDistance(day.distanceMeters)} · ${count(day.tripCount, "trip")} · ${count(day.count, "point")} · ${formatDuration(day.endTime - day.startTime)}`}
+ sub={`${formatDistance(day.distanceMeters)} · ${t("history.trips", { count: day.tripCount, n: day.tripCount })} · ${t("history.points", { count: day.count, n: day.count.toLocaleString() })} · ${formatDuration(day.endTime - day.startTime)}`}
onPress={() => openDay(day.day)}
- accessibilityHint="Opens the day in Location History"
+ accessibilityHint={t("summary.opensDay")}
testID={`day-${day.day}`}
/>
</React.Fragment>
diff --git a/apps/mobile/src/screens/TripDetailScreen.tsx b/apps/mobile/src/screens/TripDetailScreen.tsx
index be7f30d5..332b3965 100644
--- a/apps/mobile/src/screens/TripDetailScreen.tsx
+++ b/apps/mobile/src/screens/TripDetailScreen.tsx
@@ -33,6 +33,7 @@ import NativeLocationService from "../services/NativeLocationService"
import { BOUNDARY_ACTION_SPLIT } from "../types/global"
import type { Trip, BoundaryAction } from "../types/global"
import type { RootScreenProps } from "../types/navigation"
+import { useTranslation } from "../i18n/useTranslation"
const MAX_BARS = 120
@@ -57,6 +58,7 @@ const DOCK_MAP_SHARE = 0.6
export function TripDetailScreen({ route, navigation }: RootScreenProps<"Trip Detail">) {
const { colors } = useTheme()
+ const { t } = useTranslation()
const insets = useSafeAreaInsets()
const { height: viewportHeight } = useWindowDimensions()
const mapHeight = Math.round(viewportHeight * MAP_VIEWPORT_SHARE)
@@ -73,7 +75,7 @@ export function TripDetailScreen({ route, navigation }: RootScreenProps<"Trip De
const stats = useMemo(() => computeTripStats(trip.locations), [trip])
const duration = trip.endTime - trip.startTime
- const displayName = `Trip ${trip.index}`
+ const displayName = t("history.trip", { index: trip.index })
const [exportOpen, setExportOpen] = useState(false)
const [chartActiveIndex, setChartActiveIndex] = useState<number | null>(null)
@@ -110,7 +112,7 @@ export function TripDetailScreen({ route, navigation }: RootScreenProps<"Trip De
}
}, [])
- const currentIdx = trips.findIndex((t) => t.index === trip.index)
+ const currentIdx = trips.findIndex((candidate) => candidate.index === trip.index)
const prevTrip = currentIdx > 0 ? trips[currentIdx - 1] : null
const nextTrip = currentIdx >= 0 && currentIdx < trips.length - 1 ? trips[currentIdx + 1] : null
@@ -129,22 +131,25 @@ export function TripDetailScreen({ route, navigation }: RootScreenProps<"Trip De
[navigation]
)
- const handlePointNoteChange = useCallback(async (id: number, note: string | null) => {
- try {
- await NativeLocationService.updateLocationNote(id, note)
- setNoteOverrides((prev) => ({ ...prev, [id]: note ?? undefined }))
- } catch (error) {
- logger.error("[TripDetail] Note update failed:", error)
- showAlert("Save Failed", "Unable to save note. Please try again.", "error")
- }
- }, [])
+ const handlePointNoteChange = useCallback(
+ async (id: number, note: string | null) => {
+ try {
+ await NativeLocationService.updateLocationNote(id, note)
+ setNoteOverrides((prev) => ({ ...prev, [id]: note ?? undefined }))
+ } catch (error) {
+ logger.error("[TripDetail] Note update failed:", error)
+ showAlert(t("history.note.failed.title"), t("history.note.failed.message"), "error")
+ }
+ },
+ [t]
+ )
const splittingRef = useRef(false)
const handlePointSplit = useCallback(
async (id: number) => {
if (splittingRef.current) return
if (!boundariesLoaded) {
- showAlert("Cannot Split Here", "Still loading this trip's edits. Try again in a moment.", "info")
+ showAlert(t("tripDetail.cannotSplit"), t("tripDetail.stillLoading"), "info")
return
}
// A trip's locations are a contiguous run of the day, so the preceding point is the one
@@ -152,16 +157,15 @@ export function TripDetailScreen({ route, navigation }: RootScreenProps<"Trip De
const idx = trip.locations.findIndex((l) => l.id === id)
const blocked = splitBlockedReason(trip.locations, idx, boundaryOverrides)
if (blocked) {
- showAlert("Cannot Split Here", blocked, "info")
+ showAlert(t("tripDetail.cannotSplit"), t(blocked), "info")
return
}
const at = trip.locations[idx].timestamp
const confirmed = await showConfirm({
// The confirm covers the popup, so name the point in it
- title: at ? `Start a new trip at ${formatTime(at, true)}?` : "Split Trip?",
- message:
- "Everything from this point onwards becomes a separate trip. Your location data is not changed, and you can undo this by merging the two trips again.",
- confirmText: "Split"
+ title: at ? t("tripDetail.split.titleAt", { time: formatTime(at, true) }) : t("tripDetail.split.title"),
+ message: t("tripDetail.split.message"),
+ confirmText: t("tripDetail.split.confirm")
})
if (!confirmed) return
splittingRef.current = true
@@ -178,12 +182,12 @@ export function TripDetailScreen({ route, navigation }: RootScreenProps<"Trip De
navigation.goBack()
} catch (error) {
logger.error("[TripDetail] Split failed:", error)
- showAlert("Split Failed", "Unable to split the trip here. Please try again.", "error")
+ showAlert(t("tripDetail.split.failed.title"), t("tripDetail.split.failed.message"), "error")
} finally {
splittingRef.current = false
}
},
- [trip, boundaryOverrides, boundariesLoaded, navigation]
+ [trip, boundaryOverrides, boundariesLoaded, navigation, t]
)
const handleExport = useCallback(
@@ -199,23 +203,24 @@ export function TripDetailScreen({ route, navigation }: RootScreenProps<"Trip De
await NativeLocationService.shareFile(
filePath,
EXPORT_FORMATS[format].mimeType,
- `Colota ${displayName} - ${dateStr}`
+ t("history.shareSubject", { label: displayName, date: dateStr })
)
} catch (error) {
logger.error("[TripDetail] Export failed:", error)
- showAlert("Export Failed", "Unable to export. Please try again.", "error")
+ showAlert(t("history.exportFailed.title"), t("history.exportFailed.message"), "error")
}
},
- [trip, displayName]
+ [trip, displayName, t]
)
const handleDelete = useCallback(async () => {
const confirmed = await showConfirm({
- title: `Delete ${displayName}?`,
- message: `This permanently removes ${trip.locationCount} location point${
- trip.locationCount === 1 ? "" : "s"
- } from this device. Unsent points will not be uploaded.`,
- confirmText: "Delete",
+ title: t("tripDetail.delete.title", { name: displayName }),
+ message: t("tripDetail.delete.message", {
+ count: trip.locationCount,
+ n: trip.locationCount.toLocaleString()
+ }),
+ confirmText: t("common.delete"),
destructive: true
})
if (!confirmed) return
@@ -225,18 +230,23 @@ export function TripDetailScreen({ route, navigation }: RootScreenProps<"Trip De
navigation.goBack()
} catch (error) {
logger.error("[TripDetail] Delete failed:", error)
- showAlert("Delete Failed", "Unable to delete trip. Please try again.", "error")
+ showAlert(t("history.delete.failed.title"), t("tripDetail.delete.failed"), "error")
setDeleting(false)
}
- }, [trip, displayName, navigation])
+ }, [trip, displayName, navigation, t])
const headerRight = useCallback(
() => (
<View style={styles.headerActions}>
- <HeaderAction icon={Upload} label="Export trip" onPress={() => setExportOpen(true)} testID="export-trip-btn" />
+ <HeaderAction
+ icon={Upload}
+ label={t("tripDetail.export")}
+ onPress={() => setExportOpen(true)}
+ testID="export-trip-btn"
+ />
<HeaderAction
icon={Trash2}
- label="Delete trip"
+ label={t("tripDetail.deleteTrip")}
color={colors.error}
disabled={deleting}
onPress={handleDelete}
@@ -244,7 +254,7 @@ export function TripDetailScreen({ route, navigation }: RootScreenProps<"Trip De
/>
</View>
),
- [handleDelete, deleting, colors.error]
+ [handleDelete, deleting, colors.error, t]
)
useLayoutEffect(() => {
@@ -295,8 +305,8 @@ export function TripDetailScreen({ route, navigation }: RootScreenProps<"Trip De
leading={<TripSwatch index={trip.index} />}
onPrevious={() => goToTrip(prevTrip)}
onNext={() => goToTrip(nextTrip)}
- previousLabel="Previous trip"
- nextLabel="Next trip"
+ previousLabel={t("tripDetail.previous")}
+ nextLabel={t("tripDetail.next")}
previousDisabled={!prevTrip}
nextDisabled={!nextTrip}
testID="trip"
@@ -336,23 +346,31 @@ export function TripDetailScreen({ route, navigation }: RootScreenProps<"Trip De
<ScrollView contentContainerStyle={styles.content}>
<View style={styles.section}>
<Card rows>
- <StatRow icon={Route} label="Distance" value={formatDistance(trip.distance)} />
+ <StatRow icon={Route} label={t("tripDetail.distance")} value={formatDistance(trip.distance)} />
<Divider tight inset />
- <StatRow icon={Clock} label="Duration" value={formatDuration(duration)} />
+ <StatRow icon={Clock} label={t("tripDetail.duration")} value={formatDuration(duration)} />
<Divider tight inset />
- <StatRow icon={Gauge} label="Avg speed" value={formatSpeed(stats.avgSpeed)} />
+ <StatRow icon={Gauge} label={t("tripDetail.avgSpeed")} value={formatSpeed(stats.avgSpeed)} />
<Divider tight inset />
- <StatRow icon={MapPin} label="Points" value={String(trip.locationCount)} />
+ <StatRow icon={MapPin} label={t("tripDetail.points")} value={String(trip.locationCount)} />
{stats.elevationGain > 0 && (
<>
<Divider tight inset />
- <StatRow icon={TrendingUp} label="Elev. gain" value={`${Math.round(stats.elevationGain)}m`} />
+ <StatRow
+ icon={TrendingUp}
+ label={t("tripDetail.elevGain")}
+ value={`${Math.round(stats.elevationGain)}m`}
+ />
</>
)}
{stats.elevationLoss > 0 && (
<>
<Divider tight inset />
- <StatRow icon={TrendingDown} label="Elev. loss" value={`${Math.round(stats.elevationLoss)}m`} />
+ <StatRow
+ icon={TrendingDown}
+ label={t("tripDetail.elevLoss")}
+ value={`${Math.round(stats.elevationLoss)}m`}
+ />
</>
)}
</Card>
@@ -362,13 +380,18 @@ export function TripDetailScreen({ route, navigation }: RootScreenProps<"Trip De
{speedProfile.length > 2 && (
<View style={styles.section}>
<View style={styles.chartTitleRow}>
- <SectionTitle>Speed</SectionTitle>
- <Text style={[styles.chartRange, { color: colors.textSecondary }]}>max {formatSpeed(maxSpeed)}</Text>
+ <SectionTitle>{t("tripDetail.speed")}</SectionTitle>
+ <Text style={[styles.chartRange, { color: colors.textSecondary }]}>
+ {t("tripDetail.maxSpeed", { value: formatSpeed(maxSpeed) })}
+ </Text>
</View>
<Card style={styles.chartCard}>
<View
accessibilityRole="image"
- accessibilityLabel={`Speed over the trip, average ${formatSpeed(stats.avgSpeed)}, maximum ${formatSpeed(maxSpeed)}`}
+ accessibilityLabel={t("tripDetail.speedChart", {
+ avg: formatSpeed(stats.avgSpeed),
+ max: formatSpeed(maxSpeed)
+ })}
>
<InteractiveLineChart
data={speedProfile}
@@ -395,7 +418,7 @@ export function TripDetailScreen({ route, navigation }: RootScreenProps<"Trip De
{elevationProfile.length > 2 && elevationRange > 0 && (
<View style={styles.section}>
<View style={styles.chartTitleRow}>
- <SectionTitle>Elevation</SectionTitle>
+ <SectionTitle>{t("tripDetail.elevation")}</SectionTitle>
<Text style={[styles.chartRange, { color: colors.textSecondary }]}>
{Math.round(minElevation)}m - {Math.round(maxElevation)}m
</Text>
@@ -423,7 +446,7 @@ export function TripDetailScreen({ route, navigation }: RootScreenProps<"Trip De
</ScrollView>
<ExportFormatDialog
visible={exportOpen}
- title={`Export ${displayName}`}
+ title={t("tripDetail.exportTitle", { name: displayName })}
message={`${formatDate(trip.startTime)} · ${formatDistance(trip.distance)} · ${formatDuration(duration)}`}
onSelect={(format) => {
setExportOpen(false)
diff --git a/apps/mobile/src/screens/__tests__/TripDetailScreen.test.tsx b/apps/mobile/src/screens/__tests__/TripDetailScreen.test.tsx
index 0b6a7de1..7e48436c 100644
--- a/apps/mobile/src/screens/__tests__/TripDetailScreen.test.tsx
+++ b/apps/mobile/src/screens/__tests__/TripDetailScreen.test.tsx
@@ -222,7 +222,11 @@ describe("TripDetailScreen - split from the map", () => {
splitAt(getByTestId, "select-point-last")
// Says why instead of doing nothing
- expect(showAlert).toHaveBeenCalledWith("Cannot Split Here", expect.any(String), "info")
+ expect(showAlert).toHaveBeenCalledWith(
+ "Cannot Split Here",
+ expect.stringMatching(/^This trip is too short to split/),
+ "info"
+ )
expect(showConfirm).not.toHaveBeenCalled()
expect(NativeLocationService.addBoundaryOverrides).not.toHaveBeenCalled()
})
diff --git a/apps/mobile/src/utils/__tests__/summaryPeriod.test.ts b/apps/mobile/src/utils/__tests__/summaryPeriod.test.ts
index d80e149a..ae1b3576 100644
--- a/apps/mobile/src/utils/__tests__/summaryPeriod.test.ts
+++ b/apps/mobile/src/utils/__tests__/summaryPeriod.test.ts
@@ -24,6 +24,8 @@ describe("periodRange", () => {
title: "Last week"
})
expect(periodRange("week", 3, now).title).toMatch(/Aug 17 - Aug 23/)
+ // Past last week the title is the span, so the caption names the week by its Monday instead.
+ expect(periodRange("week", 3, now).caption).toMatch(/^Week of Aug 17$/)
})
it("steps months whole, so a range never straddles two of them", () => {
diff --git a/apps/mobile/src/utils/__tests__/trips.test.ts b/apps/mobile/src/utils/__tests__/trips.test.ts
index 794b2a49..b2b5e3e7 100644
--- a/apps/mobile/src/utils/__tests__/trips.test.ts
+++ b/apps/mobile/src/utils/__tests__/trips.test.ts
@@ -11,6 +11,7 @@ import {
SPLIT_BLOCKED_TOO_SHORT,
SPLIT_BLOCKED_TRIP_TOO_SHORT
} from "../trips"
+import { t } from "../../i18n/t"
import { formatDuration, formatTime, formatDate, computeTotalDistance } from "../geo"
import { BOUNDARY_ACTION_MERGE, BOUNDARY_ACTION_SPLIT, type TripBoundaryOverride } from "../../types/global"
@@ -223,7 +224,7 @@ describe("manual trip boundary overrides", () => {
expect(split).toHaveLength(2)
expect(split[1].locationCount).toBe(2)
// Re-indexed contiguously, so the UI never shows a gap in trip numbering
- expect(split.map((t) => t.index)).toEqual([1, 2])
+ expect(split.map((trip) => trip.index)).toEqual([1, 2])
})
it("drops a one-point segment even though a split forces it", () => {
@@ -669,3 +670,13 @@ describe("formatDate", () => {
expect(formatDate(ts1)).not.toBe(formatDate(ts2))
})
})
+
+describe("split refusal wording", () => {
+ it("says why a split was refused in words, since the map cannot show it on the point", () => {
+ expect(t(SPLIT_BLOCKED_TRIP_TOO_SHORT)).toBe(
+ "This trip is too short to split. Splitting makes two trips, and each one needs at least two points."
+ )
+ expect(t(SPLIT_BLOCKED_ALREADY_BOUNDARY)).toBe("This point already starts a trip.")
+ expect(t(SPLIT_BLOCKED_TOO_SHORT)).toMatch(/^A split needs at least two points on each side/)
+ })
+})
diff --git a/apps/mobile/src/utils/summaryPeriod.ts b/apps/mobile/src/utils/summaryPeriod.ts
index 6347a0d0..b64df4f0 100644
--- a/apps/mobile/src/utils/summaryPeriod.ts
+++ b/apps/mobile/src/utils/summaryPeriod.ts
@@ -4,6 +4,7 @@
*/
import type { DailyStat } from "../types/global"
+import { t } from "../i18n/t"
export type Period = "week" | "month"
@@ -47,8 +48,8 @@ export function periodRange(period: Period, offset: number, now: Date): PeriodRa
const start = startOfWeek(now)
start.setDate(start.getDate() - offset * 7)
const end = new Date(start.getFullYear(), start.getMonth(), start.getDate() + 6)
- const title = offset === 0 ? "This week" : offset === 1 ? "Last week" : span(start, end, now)
- const caption = offset < 2 ? span(start, end, now) : `Week of ${shortDate(start, false)}`
+ const title = offset === 0 ? t("summary.thisWeek") : offset === 1 ? t("summary.lastWeek") : span(start, end, now)
+ const caption = offset < 2 ? span(start, end, now) : t("summary.weekOf", { date: shortDate(start, false) })
return { firstDay: dayKeyOf(start), lastDay: dayKeyOf(end), title, caption }
}
const start = new Date(now.getFullYear(), now.getMonth() - offset, 1)
@@ -57,7 +58,7 @@ export function periodRange(period: Period, offset: number, now: Date): PeriodRa
month: "long",
...(start.getFullYear() !== now.getFullYear() && { year: "numeric" })
})
- const title = offset === 0 ? "This month" : offset === 1 ? "Last month" : named
+ const title = offset === 0 ? t("summary.thisMonth") : offset === 1 ? t("summary.lastMonth") : named
const caption = offset < 2 ? named : span(start, end, now)
return { firstDay: dayKeyOf(start), lastDay: dayKeyOf(end), title, caption }
}
diff --git a/apps/mobile/src/utils/trips.ts b/apps/mobile/src/utils/trips.ts
index cc04aa8a..fea57798 100644
--- a/apps/mobile/src/utils/trips.ts
+++ b/apps/mobile/src/utils/trips.ts
@@ -6,6 +6,7 @@
import { computeTotalDistance, haversine } from "./geo"
import { BOUNDARY_ACTION_MERGE, BOUNDARY_ACTION_SPLIT } from "../types/global"
import type { Trip, LocationCoords, BoundaryAction, TripBoundaryOverride } from "../types/global"
+import type { TranslationKey } from "../i18n/options"
export const TRIP_COLORS = ["#3B82F6", "#10B981", "#F59E0B", "#EF4444", "#8B5CF6", "#EC4899"]
@@ -90,13 +91,10 @@ export function segmentTrips(
return filtered.map((s, i) => ({ ...s.trip, index: i + 1 }))
}
-export const SPLIT_BLOCKED_NOT_A_TRIP =
- "This point is not part of a trip. Colota leaves out runs that never travel more than 100 m."
-export const SPLIT_BLOCKED_ALREADY_BOUNDARY = "This point already starts a trip."
-export const SPLIT_BLOCKED_TRIP_TOO_SHORT =
- "This trip is too short to split. Splitting makes two trips, and each one needs at least two points."
-export const SPLIT_BLOCKED_TOO_SHORT =
- "A split needs at least two points on each side, so the first two and last two points of a trip cannot start a new one."
+export const SPLIT_BLOCKED_NOT_A_TRIP: TranslationKey = "split.notATrip"
+export const SPLIT_BLOCKED_ALREADY_BOUNDARY: TranslationKey = "split.alreadyBoundary"
+export const SPLIT_BLOCKED_TRIP_TOO_SHORT: TranslationKey = "split.tripTooShort"
+export const SPLIT_BLOCKED_TOO_SHORT: TranslationKey = "split.tooShort"
/** First and last index of the run of points containing index, bounded by the trip boundaries. */
function runBounds(
@@ -130,7 +128,7 @@ export function splitBlockedReason(
index: number,
overrides?: Map<string, BoundaryAction>,
gapThresholdSeconds: number = DEFAULT_GAP_SECONDS
-): string | null {
+): TranslationKey | null {
if (index < 0 || index >= locations.length) return SPLIT_BLOCKED_ALREADY_BOUNDARY
const ts = (i: number) => locations[i].timestamp ?? 0
const splits = (i: number) => boundarySplits(ts(i), ts(i + 1), overrides, gapThresholdSeconds)