Colota - Android GPS Location tracker
refactor(i18n): move Geofences into the catalog (#905)
Max Dietrichacc7b312f557
diff --git a/apps/mobile/src/i18n/locales/en.json b/apps/mobile/src/i18n/locales/en.jsonindex 336b1fe7..e24e1457 100644--- a/apps/mobile/src/i18n/locales/en.json+++ b/apps/mobile/src/i18n/locales/en.json@@ -399,5 +399,57 @@"profileEditor.deactivation": "Deactivation delay","profileEditor.deactivation.hint": "How long the profile stays on after its condition ends. Longer rides out a brief gap.","profileEditor.save": "Save changes",- "profileEditor.create": "Create profile"+ "profileEditor.create": "Create profile",+ "zone.pausedHere": "Paused here",+ "zone.recordingContinues": "recording continues",+ "zone.wifiPause": "WiFi pause",+ "zone.motionlessPause": "motionless pause",+ "geofences.shareFailed": "Failed to share geofences.",+ "geofences.share": "Share all geofences",+ "geofences.create": "Create geofence",+ "geofences.fit": "Fit geofences",+ "geofences.centre": "Centre map on my position",+ "geofences.empty.title": "No geofences yet",+ "geofences.empty.hint": "A geofence stops recording while you are inside it.",+ "geofenceEditor.loadFailed": "Failed to load geofence data.",+ "geofenceEditor.missingName.title": "Missing Name",+ "geofenceEditor.missingName.message": "Please enter a name.",+ "geofenceEditor.invalidRadius.title": "Invalid Radius",+ "geofenceEditor.invalidRadius.message": "Please enter a valid radius.",+ "geofenceEditor.noLocation.title": "No location",+ "geofenceEditor.noLocation.message": "Place the zone on the map first.",+ "geofenceEditor.saveFailed": "Failed to save geofence.",+ "geofenceEditor.deleteFailed": "Failed to delete geofence.",+ "geofenceEditor.delete.title": "Delete geofence",+ "geofenceEditor.delete.message": "Delete \"{{name}}\"?",+ "geofenceEditor.section.general": "General",+ "geofenceEditor.section.pause": "GPS pause options",+ "geofenceEditor.name": "Name",+ "geofenceEditor.name.placeholder": "Home, Work...",+ "geofenceEditor.radius": "Radius ({{unit}})",+ "geofenceEditor.radius.a11y": "Radius",+ "geofenceEditor.location": "Location",+ "geofenceEditor.location.notPlaced": "Not placed yet",+ "geofenceEditor.newZone": "New zone",+ "geofenceEditor.pause": "Don't record in zone",+ "geofenceEditor.pause.hint": "Pause saving and syncing",+ "geofenceEditor.wifi": "WiFi/Ethernet pause",+ "geofenceEditor.wifi.hint": "Stop GPS on unmetered networks",+ "geofenceEditor.motionless": "Motionless pause",+ "geofenceEditor.motionless.hint": "Stop GPS after no motion for a set time",+ "geofenceEditor.timeout": "Timeout (min)",+ "geofenceEditor.timeout.hint": "Minutes without motion before GPS stops",+ "geofenceEditor.timeout.a11y": "Timeout in minutes",+ "geofenceEditor.atLeastMinute": "Must be at least 1 minute",+ "geofenceEditor.heartbeat": "Stationary heartbeat",+ "geofenceEditor.heartbeat.hint": "Periodic point at the zone center while paused",+ "geofenceEditor.heartbeatInterval": "Interval (min)",+ "geofenceEditor.heartbeatInterval.hint": "How often to record a point",+ "geofenceEditor.heartbeatInterval.a11y": "Interval in minutes",+ "geofenceEditor.combined": "GPS resumes only when both WiFi is disconnected and motion is detected",+ "geofenceEditor.save": "Save geofence",+ "placeZone.here": "Place zone at my position",+ "placeZone.readout": "{{coord}} · {{radius}} radius",+ "placeZone.tap": "Tap the map to place the zone",+ "placeZone.use": "Use this location"}diff --git a/apps/mobile/src/screens/GeofenceEditorScreen.tsx b/apps/mobile/src/screens/GeofenceEditorScreen.tsxindex 80508cc0..b644403a 100644--- a/apps/mobile/src/screens/GeofenceEditorScreen.tsx+++ b/apps/mobile/src/screens/GeofenceEditorScreen.tsx@@ -26,12 +26,15 @@ import { shortDistanceUnit, inputToMeters, metersToInput } from "../utils/geo"import { parsePositiveInt, isPositiveInt } from "../utils/settingsValidation"import type { RootScreenProps } from "../types/navigation"import { size, space } from "../constants"+import { useTranslation } from "../i18n/useTranslation"+import { t as translate } from "../i18n/t"declare function requestIdleCallback(callback: () => void): numberdeclare function cancelIdleCallback(handle: number): voidexport function GeofenceEditorScreen({ navigation, route }: RootScreenProps<"Geofence Editor">) {const { colors } = useTheme()+ const { t } = useTranslation()const geofenceId = route?.params?.geofenceId as number | undefinedconst isEditing = !!geofenceId@@ -127,7 +130,8 @@ export function GeofenceEditorScreen({ navigation, route }: RootScreenProps<"Geo.catch((err) => {if (cancelled) returnlogger.error("[GeofenceEditor] Failed to load geofence:", err)- showAlert("Error", "Failed to load geofence data.", "error")+ // The non-hook t, so a language change never re-runs the load over unsaved edits.+ showAlert(translate("common.error"), translate("geofenceEditor.loadFailed"), "error")navigation.goBack()})})@@ -151,11 +155,11 @@ export function GeofenceEditorScreen({ navigation, route }: RootScreenProps<"Geoconst handleSave = useCallback(async () => {if (!name.trim()) {- showAlert("Missing Name", "Please enter a name.", "warning")+ showAlert(t("geofenceEditor.missingName.title"), t("geofenceEditor.missingName.message"), "warning")return}if (radius <= 0) {- showAlert("Invalid Radius", "Please enter a valid radius.", "warning")+ showAlert(t("geofenceEditor.invalidRadius.title"), t("geofenceEditor.invalidRadius.message"), "warning")return}const effectiveHeartbeat = parsePositiveInt(heartbeatIntervalStr, 15)@@ -179,7 +183,7 @@ export function GeofenceEditorScreen({ navigation, route }: RootScreenProps<"Geo})} else {if (!coord) {- showAlert("No location", "Place the zone on the map first.", "warning")+ showAlert(t("geofenceEditor.noLocation.title"), t("geofenceEditor.noLocation.message"), "warning")setSaving(false)return}@@ -201,7 +205,7 @@ export function GeofenceEditorScreen({ navigation, route }: RootScreenProps<"Geonavigation.goBack()} catch (err) {logger.error("[GeofenceEditor] Save failed:", err)- showAlert("Error", "Failed to save geofence.", "error")+ showAlert(t("common.error"), t("geofenceEditor.saveFailed"), "error")} finally {setSaving(false)}@@ -217,15 +221,16 @@ export function GeofenceEditorScreen({ navigation, route }: RootScreenProps<"GeoheartbeatIntervalStr,isEditing,geofenceId,- navigation+ navigation,+ t])const handleDelete = useCallback(async () => {if (!geofenceId) returnconst confirmed = await showConfirm({- title: "Delete geofence",- message: `Delete "${name}"?`,- confirmText: "Delete",+ title: t("geofenceEditor.delete.title"),+ message: t("geofenceEditor.delete.message", { name }),+ confirmText: t("common.delete"),destructive: true})if (!confirmed) return@@ -235,29 +240,29 @@ export function GeofenceEditorScreen({ navigation, route }: RootScreenProps<"Geonavigation.goBack()} catch (err) {logger.error("[GeofenceEditor] Delete failed:", err)- showAlert("Error", "Failed to delete geofence.", "error")+ showAlert(t("common.error"), t("geofenceEditor.deleteFailed"), "error")}- }, [geofenceId, name, navigation])+ }, [geofenceId, name, navigation, t])return (<Container><ScrollView contentContainerStyle={styles.content} showsVerticalScrollIndicator={false}>- <SectionTitle>General</SectionTitle>+ <SectionTitle>{t("geofenceEditor.section.general")}</SectionTitle><Card rows style={styles.card}>- <SettingRow label="Name">+ <SettingRow label={t("geofenceEditor.name")}><TextFieldtestID="geofence-name-input"- accessibilityLabel="Name"+ accessibilityLabel={t("geofenceEditor.name")}style={styles.nameInput}value={name}onChangeText={setName}- placeholder="Home, Work..."+ placeholder={t("geofenceEditor.name.placeholder")}/></SettingRow>- <SettingRow label={`Radius (${shortDistanceUnit()})`}>+ <SettingRow label={t("geofenceEditor.radius", { unit: shortDistanceUnit() })}><TextFieldtestID="geofence-radius-input"- accessibilityLabel="Radius"+ accessibilityLabel={t("geofenceEditor.radius.a11y")}figurestyle={styles.numInput}value={radiusStr}@@ -268,11 +273,11 @@ export function GeofenceEditorScreen({ navigation, route }: RootScreenProps<"Geo</SettingRow><ListItemtestID="place-zone-row"- label="Location"- sub={coord ? `${coord.lat.toFixed(5)}, ${coord.lon.toFixed(5)}` : "Not placed yet"}+ label={t("geofenceEditor.location")}+ sub={coord ? `${coord.lat.toFixed(5)}, ${coord.lon.toFixed(5)}` : t("geofenceEditor.location.notPlaced")}onPress={() =>navigation.navigate("Place Zone", {- name: name.trim() || "New zone",+ name: name.trim() || t("geofenceEditor.newZone"),radius,lat: coord?.lat,lon: coord?.lon@@ -281,20 +286,20 @@ export function GeofenceEditorScreen({ navigation, route }: RootScreenProps<"Geo/></Card>- <SectionTitle>GPS pause options</SectionTitle>+ <SectionTitle>{t("geofenceEditor.section.pause")}</SectionTitle><Card rows style={[styles.card, styles.cardTail]}>- <SettingRow label="Don't record in zone" hint="Pause saving and syncing">+ <SettingRow label={t("geofenceEditor.pause")} hint={t("geofenceEditor.pause.hint")}><Toggle- accessibilityLabel="Don't record in zone"+ accessibilityLabel={t("geofenceEditor.pause")}testID="pause-tracking-toggle"value={pauseTracking}onValueChange={setPauseTracking}/></SettingRow>- <SettingRow label="WiFi/Ethernet pause" hint="Stop GPS on unmetered networks" disabled={!pauseTracking}>+ <SettingRow label={t("geofenceEditor.wifi")} hint={t("geofenceEditor.wifi.hint")} disabled={!pauseTracking}><Toggle- accessibilityLabel="WiFi/Ethernet pause"+ accessibilityLabel={t("geofenceEditor.wifi")}testID="pause-wifi-toggle"value={pauseOnWifi}onValueChange={setPauseOnWifi}@@ -302,9 +307,13 @@ export function GeofenceEditorScreen({ navigation, route }: RootScreenProps<"Geo/></SettingRow>- <SettingRow label="Motionless pause" hint="Stop GPS after no motion for a set time" disabled={!pauseTracking}>+ <SettingRow+ label={t("geofenceEditor.motionless")}+ hint={t("geofenceEditor.motionless.hint")}+ disabled={!pauseTracking}+ ><Toggle- accessibilityLabel="Motionless pause"+ accessibilityLabel={t("geofenceEditor.motionless")}testID="pause-motionless-toggle"value={pauseOnMotionless}onValueChange={setPauseOnMotionless}@@ -314,10 +323,10 @@ export function GeofenceEditorScreen({ navigation, route }: RootScreenProps<"Geo{pauseTracking && pauseOnMotionless && (<View style={styles.nestedSetting}>- <SettingRow label="Timeout (min)" hint="Minutes without motion before GPS stops">+ <SettingRow label={t("geofenceEditor.timeout")} hint={t("geofenceEditor.timeout.hint")}><TextFieldtestID="motionless-timeout-input"- accessibilityLabel="Timeout in minutes"+ accessibilityLabel={t("geofenceEditor.timeout.a11y")}figurestyle={styles.numInput}value={motionlessTimeoutStr}@@ -327,18 +336,18 @@ export function GeofenceEditorScreen({ navigation, route }: RootScreenProps<"Geo/></SettingRow>{!isPositiveInt(motionlessTimeoutStr) && (- <FieldMessage variant="error">Must be at least 1 minute</FieldMessage>+ <FieldMessage variant="error">{t("geofenceEditor.atLeastMinute")}</FieldMessage>)}</View>)}<SettingRow- label="Stationary heartbeat"- hint="Periodic point at the zone center while paused"+ label={t("geofenceEditor.heartbeat")}+ hint={t("geofenceEditor.heartbeat.hint")}disabled={!pauseTracking}><Toggle- accessibilityLabel="Stationary heartbeat"+ accessibilityLabel={t("geofenceEditor.heartbeat")}testID="heartbeat-toggle"value={heartbeatEnabled}onValueChange={setHeartbeatEnabled}@@ -348,10 +357,13 @@ export function GeofenceEditorScreen({ navigation, route }: RootScreenProps<"Geo{pauseTracking && heartbeatEnabled && (<View style={styles.nestedSetting}>- <SettingRow label="Interval (min)" hint="How often to record a point">+ <SettingRow+ label={t("geofenceEditor.heartbeatInterval")}+ hint={t("geofenceEditor.heartbeatInterval.hint")}+ ><TextFieldtestID="heartbeat-interval-input"- accessibilityLabel="Interval in minutes"+ accessibilityLabel={t("geofenceEditor.heartbeatInterval.a11y")}figurestyle={styles.numInput}value={heartbeatIntervalStr}@@ -361,7 +373,7 @@ export function GeofenceEditorScreen({ navigation, route }: RootScreenProps<"Geo/></SettingRow>{!isPositiveInt(heartbeatIntervalStr) && (- <FieldMessage variant="error">Must be at least 1 minute</FieldMessage>+ <FieldMessage variant="error">{t("geofenceEditor.atLeastMinute")}</FieldMessage>)}</View>)}@@ -369,14 +381,14 @@ export function GeofenceEditorScreen({ navigation, route }: RootScreenProps<"Geo{pauseTracking && pauseOnWifi && pauseOnMotionless && (<View style={[styles.combinedNote, { borderTopColor: colors.divider }]}><Text style={[styles.combinedNoteText, { color: colors.textSecondary }]}>- GPS resumes only when both WiFi is disconnected and motion is detected+ {t("geofenceEditor.combined")}</Text></View>)}</Card><Button- title="Save geofence"+ title={t("geofenceEditor.save")}loading={saving}onPress={handleSave}disabled={@@ -387,7 +399,9 @@ export function GeofenceEditorScreen({ navigation, route }: RootScreenProps<"Geo}icon={Check}/>- {isEditing && <Button title="Delete geofence" onPress={handleDelete} variant="danger" icon={Trash2} />}+ {isEditing && (+ <Button title={t("geofenceEditor.delete.title")} onPress={handleDelete} variant="danger" icon={Trash2} />+ )}</ScrollView></Container>)diff --git a/apps/mobile/src/screens/GeofenceScreen.tsx b/apps/mobile/src/screens/GeofenceScreen.tsxindex fe5e2c0b..6f8b8037 100644--- a/apps/mobile/src/screens/GeofenceScreen.tsx+++ b/apps/mobile/src/screens/GeofenceScreen.tsx@@ -22,6 +22,7 @@ import {size,space} from "../constants"+import { useTranslation } from "../i18n/useTranslation"import { MapActionButton } from "../components/features/map/MapActionButton"import { ColotaMapView, ColotaMapRef } from "../components/features/map/ColotaMapView"import { buildGeofencesGeoJSON, geofenceBounds } from "../components/features/map/mapUtils"@@ -43,6 +44,7 @@ export function GeofenceScreen({ navigation }: ScreenProps) {const { tracking } = useTracking()const coords = useCoords()const { colors } = useTheme()+ const { t } = useTranslation()const [geofences, setGeofences] = useState<Geofence[] | null>(null)const [currentPauseZone, setCurrentPauseZone] = useState<string | null>(null)@@ -153,9 +155,9 @@ export function GeofenceScreen({ navigation }: ScreenProps) {await Share.share({ message: buildGeofencesLink(geofences) })} catch (err) {logger.error("[GeofenceScreen] Failed to share geofences:", err)- showAlert("Error", "Failed to share geofences.", "error")+ showAlert(t("common.error"), t("geofences.shareFailed"), "error")}- }, [geofences])+ }, [geofences, t])const openEditor = useCallback((geofenceId?: number) => {@@ -171,15 +173,20 @@ export function GeofenceScreen({ navigation }: ScreenProps) {{hasZones && (<HeaderActionicon={Share2}- label="Share all geofences"+ label={t("geofences.share")}onPress={handleShareGeofences}testID="share-geofences-btn"/>)}- <HeaderAction icon={Plus} label="Create geofence" onPress={() => openEditor()} testID="add-geofence-btn" />+ <HeaderAction+ icon={Plus}+ label={t("geofences.create")}+ onPress={() => openEditor()}+ testID="add-geofence-btn"+ /></View>),- [hasZones, handleShareGeofences, openEditor]+ [hasZones, handleShareGeofences, openEditor, t])useLayoutEffect(() => {navigation.setOptions({ headerRight: renderHeaderActions })@@ -235,7 +242,7 @@ export function GeofenceScreen({ navigation }: ScreenProps) {anchored={false}style={[styles.disc, { bottom: controlsBottom + size.iconColumn + space.lg, right: edgeEnd }]}accessibilityRole="button"- accessibilityLabel={hasZones ? "Fit geofences" : "Centre map on my position"}+ accessibilityLabel={hasZones ? t("geofences.fit") : t("geofences.centre")}onPress={handleFit}testID="fit-geofences-btn">@@ -266,9 +273,9 @@ export function GeofenceScreen({ navigation }: ScreenProps) {) : (<EmptyStateicon={MapPinHouse}- title="No geofences yet"- hint="A geofence stops recording while you are inside it."- action={{ label: "Create geofence", onPress: () => openEditor() }}+ title={t("geofences.empty.title")}+ hint={t("geofences.empty.hint")}+ action={{ label: t("geofences.create"), onPress: () => openEditor() }}style={styles.empty}/>)}diff --git a/apps/mobile/src/screens/PlaceZoneScreen.tsx b/apps/mobile/src/screens/PlaceZoneScreen.tsxindex bc49f189..d6b04d76 100644--- a/apps/mobile/src/screens/PlaceZoneScreen.tsx+++ b/apps/mobile/src/screens/PlaceZoneScreen.tsx@@ -17,6 +17,7 @@ import { MapActionButton, mapActionStyles } from "../components/features/map/Mapimport { buildGeofencesGeoJSON } from "../components/features/map/mapUtils"import { fontSizes, fonts } from "../styles/typography"import { DEFAULT_MAP_ZOOM, MAP_ANIMATION_DURATION_MS, WORLD_MAP_ZOOM, size, space } from "../constants"+import { useTranslation } from "../i18n/useTranslation"import { formatShortDistance } from "../utils/geo"import { logger } from "../utils/logger"import { RootScreenProps } from "../types/navigation"@@ -26,6 +27,7 @@ const WORLD_CENTER: [number, number] = [0, 0]export function PlaceZoneScreen({ navigation, route }: RootScreenProps<"Place Zone">) {const { colors } = useTheme()+ const { t } = useTranslation()const { tracking } = useTracking()const coords = useCoords()const mapRef = useRef<ColotaMapRef>(null)@@ -116,7 +118,7 @@ export function PlaceZoneScreen({ navigation, route }: RootScreenProps<"Place Zo<MapActionButtonstyle={[mapActionStyles.right, styles.locate]}accessibilityRole="button"- accessibilityLabel="Place zone at my position"+ accessibilityLabel={t("placeZone.here")}onPress={handlePlaceAtFix}testID="place-at-fix-btn">@@ -128,10 +130,13 @@ export function PlaceZoneScreen({ navigation, route }: RootScreenProps<"Place Zo<View style={styles.footer}><Text style={[styles.readout, { color: picked ? colors.text : colors.textSecondary }]}>{picked- ? `${picked.lat.toFixed(5)}, ${picked.lon.toFixed(5)} · ${formatShortDistance(radius)} radius`- : "Tap the map to place the zone"}+ ? t("placeZone.readout", {+ coord: `${picked.lat.toFixed(5)}, ${picked.lon.toFixed(5)}`,+ radius: formatShortDistance(radius)+ })+ : t("placeZone.tap")}</Text>- <Button title="Use this location" onPress={handleConfirm} disabled={!picked} />+ <Button title={t("placeZone.use")} onPress={handleConfirm} disabled={!picked} /></View></Container>)diff --git a/apps/mobile/src/screens/__tests__/GeofenceEditorScreen.test.tsx b/apps/mobile/src/screens/__tests__/GeofenceEditorScreen.test.tsxindex f1c1be36..1daac57f 100644--- a/apps/mobile/src/screens/__tests__/GeofenceEditorScreen.test.tsx+++ b/apps/mobile/src/screens/__tests__/GeofenceEditorScreen.test.tsx@@ -287,6 +287,15 @@ describe("GeofenceEditorScreen", () => {})})+ it("refuses to save a zone with no name and says why", async () => {+ const { getByText, getByDisplayValue } = renderNew()++ fireEvent.changeText(getByDisplayValue("New Zone"), " ")+ fireEvent.press(getByText("Save geofence"))++ await waitFor(() => expect(mockShowAlert).toHaveBeenCalledWith("Missing Name", "Please enter a name.", "warning"))+ })+it("saves a moved zone, which delete-and-recreate was the only way to do before", async () => {const { getByText } = renderEditAt(40.7, -74)diff --git a/apps/mobile/src/utils/geofenceRow.ts b/apps/mobile/src/utils/geofenceRow.tsindex 6a7fe9e3..acb811c7 100644--- a/apps/mobile/src/utils/geofenceRow.ts+++ b/apps/mobile/src/utils/geofenceRow.ts@@ -5,18 +5,19 @@import type { Geofence } from "../types/global"import { formatShortDistance } from "./geo"+import { t } from "../i18n/t"/** The caption under a zone's name: what it does, and "Paused here" first when you stand in it. */export function zoneRowSub(zone: Geofence, pausedHere: boolean): string {const parts: string[] = []- if (pausedHere) parts.push("Paused here")+ if (pausedHere) parts.push(t("zone.pausedHere"))parts.push(formatShortDistance(zone.radius))if (!zone.pauseTracking) {// The pause modes are inert without the master switch, so naming them would promise a pause that never comes.- parts.push("recording continues")+ parts.push(t("zone.recordingContinues"))} else {- if (zone.pauseOnWifi) parts.push("WiFi pause")- if (zone.pauseOnMotionless) parts.push("motionless pause")+ if (zone.pauseOnWifi) parts.push(t("zone.wifiPause"))+ if (zone.pauseOnMotionless) parts.push(t("zone.motionlessPause"))}return parts.join(" · ")}