Skip to content

Colota - Android GPS Location tracker

refactor(i18n): move Backup & restore and Offline maps into the catalog (#914)

Max Dietrich0f16d4f0d12e
diff --git a/apps/mobile/src/i18n/locales/en.json b/apps/mobile/src/i18n/locales/en.json
index 6046f4c9..9053fda3 100644
--- a/apps/mobile/src/i18n/locales/en.json
+++ b/apps/mobile/src/i18n/locales/en.json
@@ -941,5 +941,127 @@
"autoExport.section.history": "Export history",
"autoExport.share": "Share {{name}}",
"autoExport.formatDialog.message": "Every scheduled run writes this format.",
- "autoExport.running": "Export running. It continues if you leave this screen."
+ "autoExport.running": "Export running. It continues if you leave this screen.",
+ "backup.locations_one": "{{n}} location",
+ "backup.locations_other": "{{n}} locations",
+ "backup.scope_one": "Writes {{n}} location, your geofences, profiles, settings and your stored server credentials to a file you pick.",
+ "backup.scope_other": "Writes {{n}} locations, your geofences, profiles, settings and your stored server credentials to a file you pick.",
+ "backup.replace.title_one": "Replace all {{n}} location?",
+ "backup.replace.title_other": "Replace all {{n}} locations?",
+ "backup.caption": "Database: {{locations}}, {{size}}",
+ "backup.last": "You last backed up {{when}}",
+ "backup.never": "You have never backed up",
+ "backup.row.last": "Last backed up {{when}}",
+ "backup.row.never": "Never backed up",
+ "backup.password.checkFailed": "Could not check this password. Try again.",
+ "backup.password.label": "{{label}}.",
+ "backup.password.labelAdvice": "{{label}}. {{advice}}",
+ "backup.password.longer": "Make it longer.",
+ "backup.password.longerOrLess": "Make it longer or less predictable.",
+ "backup.blocked.choose": "Choose a password first.",
+ "backup.blocked.weak": "This password is too easy to guess.",
+ "backup.blocked.confirm": "Type the password a second time.",
+ "backup.blocked.mismatch": "The two passwords do not match.",
+ "backup.excludesCert": "Your client certificate is not included. Its private key cannot leave this device's keystore.",
+ "backup.noRecovery": "Nobody can open this file without the password, and there is no way to reset it.",
+ "backup.written": "Backup written. Keep it somewhere you can reach without this phone.",
+ "backup.restoreIdle": "Replaces everything on this device. Nothing is merged.",
+ "backup.pickedNotOpened": "Not opened yet.",
+ "backup.openFile": "Checks the password and reads what the file holds. Nothing on this device changes.",
+ "backup.unknownDate": "an unknown date",
+ "backup.from": "Backup from {{date}}",
+ "backup.openedWith": "Colota {{version}} · opened with your password",
+ "backup.restoreCaveat": "Your client certificate stays as it is. A backup carries none, and a restore does not replace it.",
+ "backup.replace.message": "Replaces everything on this device with the backup from {{date}}: locations, geofences, tracking profiles, trip splits, settings, the upload queue and your stored server credentials. Nothing is merged and nothing is kept. Recording stops and stays off until you turn it back on. The file and the password have already been checked, so your data is replaced in one step at the end, and that step cannot be undone.",
+ "backup.replace.confirm": "Replace",
+ "backup.restored.title": "Your data is restored",
+ "backup.restored.message": "Recording is off. Turn it back on when you are ready.",
+ "backup.restored.secrets": "Your server credentials could not be applied. Enter them again on Connection. Recording is off until you turn it back on.",
+ "backup.restored.incomplete": "Something failed after the swap, so some settings may not have been applied. Check Connection and Tracking. Recording is off until you turn it back on.",
+ "backup.restoreFailed": "Restore failed",
+ "backup.unchanged": "Nothing on this device was changed.",
+ "backup.err.wrongPassword": "That password did not open this file.",
+ "backup.err.notBackup": "This is not a Colota backup.",
+ "backup.err.truncated": "This file is incomplete, so it was probably never finished being written.",
+ "backup.err.tampered": "This file is damaged and cannot be trusted.",
+ "backup.err.migration": "The file is intact but this version of Colota could not read its database.",
+ "backup.err.newer": "This backup was made by a newer version of Colota. Update the app first.",
+ "backup.err.missingEntry": "This file is missing part of a backup.",
+ "backup.err.noSpace": "There is not enough free space to unpack this backup.",
+ "backup.err.busy": "Another backup or restore is already running.",
+ "backup.err.passwordEmpty": "Type the backup's password first.",
+ "backup.err.restoreGeneric": "The backup could not be restored.",
+ "backup.err.writeGeneric": "The backup could not be written. Try a different location.",
+ "backup.noReset.title": "You cannot reset this password",
+ "backup.noReset.store": "Store it somewhere you can reach without this phone.",
+ "backup.noReset.confirm": "I have stored it",
+ "backup.restart": "Restart app",
+ "backup.section.backup": "Backup",
+ "backup.password": "Password",
+ "backup.confirmPassword": "Confirm password",
+ "backup.create": "Create backup",
+ "backup.section.restore": "Restore",
+ "backup.choose": "Choose a backup file",
+ "backup.choose.hint": "Opens the file picker",
+ "backup.restorePassword": "Backup password",
+ "backup.open": "Open this file",
+ "backup.chooseDifferent": "Choose a different file",
+ "backup.replaceAll": "Replace all data",
+ "backup.writing": "Writing the backup",
+ "backup.opening": "Opening the backup",
+ "backup.restoring": "Restoring",
+ "backup.keepOpen": "Keep Colota open until this finishes.",
+ "offline.rowHint": "Shows it on the map",
+ "offline.duplicate": "An area named \"{{name}}\" already exists.",
+ "offline.atLeast": "At least {{size}}.",
+ "offline.estimated": "{{size}} estimated.",
+ "offline.waiting": "Waiting for the map.",
+ "offline.zoomIn": "Zoom in to download less.",
+ "offline.nameIt": "Name the area to download it.",
+ "offline.starting": "Starting download…",
+ "offline.downloadingPct": "Downloading · {{pct}}%",
+ "offline.soFar": "{{size}} so far",
+ "offline.downloading": "Downloading…",
+ "offline.unreadable": "Could not read this area",
+ "offline.incomplete": "Incomplete",
+ "offline.styleChanged": "Map style changed",
+ "offline.cap": "The estimate stops counting at 100,000 tiles and the download does not.",
+ "offline.metered": "You are on mobile data, not WiFi.",
+ "offline.download.title": "Download \"{{name}}\"?",
+ "offline.download.confirm": "Download",
+ "offline.redownload.title": "Download \"{{name}}\" again?",
+ "offline.redownload.lead": "Replaces its tiles with a fresh download.",
+ "offline.redownload.confirm": "Download again",
+ "offline.delete.title": "Delete \"{{name}}\"?",
+ "offline.delete.size": "Removes {{size}} of map tiles from this device.",
+ "offline.delete.noSize": "Removes its map tiles from this device.",
+ "offline.delete.last": "It is the last saved area, so the map's online tile cache is cleared too.",
+ "offline.storage.atLeast": "At least {{size}} is needed and the device has {{free}} MB free.",
+ "offline.storage": "{{size}} is needed and the device has {{free}} MB free.",
+ "offline.noConnection.title": "No connection",
+ "offline.noConnection.message": "Downloading map tiles needs a network. Saved areas still work.",
+ "offline.startFailed.title": "Could not start the download",
+ "offline.startFailed.message": "Nothing was downloaded. Try again.",
+ "offline.noStorage": "Not enough storage",
+ "offline.stopFailed.title": "Could not stop the download",
+ "offline.stopFailed.message": "The download may still be running. Try again.",
+ "offline.cannotRedownload.title": "Cannot download again",
+ "offline.cannotRedownload.message": "This area's extent could not be read. Delete it and download it again.",
+ "offline.redownloadFailed.title": "Could not download again",
+ "offline.redownloadFailed.message": "The old tiles could not be removed, so nothing was downloaded. Try again.",
+ "offline.deleteFailed.title": "Could not delete the area",
+ "offline.deleteFailed.message": "Its tiles are still on the device. Try again.",
+ "offline.section.new": "New area",
+ "offline.name": "Name",
+ "offline.name.placeholder": "Home area, Trail…",
+ "offline.downloadArea": "Download area",
+ "offline.downloadingName": "Downloading {{name}}",
+ "offline.cancel": "Cancel download",
+ "offline.section.saved": "Saved areas",
+ "offline.stopName": "Stop downloading {{name}}",
+ "offline.againName": "Download {{name}} again",
+ "offline.deleteName": "Delete {{name}}",
+ "offline.empty.title": "No saved areas yet",
+ "offline.empty.hint": "Download map tiles to browse your tracks offline while hiking or camping",
+ "backup.pickedFallback": "the file you chose"
}
diff --git a/apps/mobile/src/screens/BackupRestoreScreen.tsx b/apps/mobile/src/screens/BackupRestoreScreen.tsx
index e60c024c..1ead208e 100644
--- a/apps/mobile/src/screens/BackupRestoreScreen.tsx
+++ b/apps/mobile/src/screens/BackupRestoreScreen.tsx
@@ -30,21 +30,24 @@ import {
backupExcludesLine,
backupScopeLine,
backupState,
- BACKUP_WRITTEN_LINE,
- NO_RECOVERY_LINE,
- OPEN_FILE_LINE,
+ backupWrittenLine,
+ noRecoveryLine,
+ openFileLine,
passwordLine,
- PICKED_NOT_OPENED_CAPTION,
+ pickedNotOpenedCaption,
restoreCaveat,
restoreConfirm,
restoreErrorMessage,
- RESTORE_IDLE_LINE,
+ restoreIdleLine,
restoreOutcome,
submitBlockedReason
} from "../utils/backupState"
import { fonts, fontSizes, lineHeights } from "../styles/typography"
import { space } from "../constants"
import type { ScreenProps } from "../types/global"
+import { useTranslation } from "../i18n/useTranslation"
+// Handlers use the non-hook t, so no callback list carries it.
+import { t as translate } from "../i18n/t"
type Busy = "backup" | "open" | "restore" | null
type Picked = { uri: string; displayName: string }
@@ -55,6 +58,7 @@ const EMPTY_STATS = { total: 0, databaseSizeMB: 0 }
export function BackupRestoreScreen({}: ScreenProps) {
const { colors } = useTheme()
+ const { t } = useTranslation()
const [stats, setStats] = useState(EMPTY_STATS)
const [lastBackupAt, setLastBackupAt] = useState<number | null>(null)
@@ -113,9 +117,9 @@ export function BackupRestoreScreen({}: ScreenProps) {
if (busyRef.current || blocked) return
if (
!(await showConfirm({
- title: "You cannot reset this password",
- message: `${NO_RECOVERY_LINE} Store it somewhere you can reach without this phone.`,
- confirmText: "I have stored it",
+ title: translate("backup.noReset.title"),
+ message: `${noRecoveryLine()} ${translate("backup.noReset.store")}`,
+ confirmText: translate("backup.noReset.confirm"),
destructive: false
}))
) {
@@ -136,7 +140,7 @@ export function BackupRestoreScreen({}: ScreenProps) {
setPassword("")
setConfirm("")
setStrength(EMPTY_STRENGTH)
- setBackupMessage({ text: BACKUP_WRITTEN_LINE })
+ setBackupMessage({ text: backupWrittenLine() })
} catch (e) {
logger.error("[BackupRestoreScreen] backup failed", e)
const err = e as { code?: string; message?: string }
@@ -151,7 +155,7 @@ export function BackupRestoreScreen({}: ScreenProps) {
if (busyRef.current) return
const source = await BackupService.pickBackupSource()
if (!source) return
- setPicked({ uri: source.uri, displayName: source.displayName ?? "the file you chose" })
+ setPicked({ uri: source.uri, displayName: source.displayName ?? translate("backup.pickedFallback") })
setManifest(null)
setRestorePassword("")
setRestoreMessage(null)
@@ -203,7 +207,7 @@ export function BackupRestoreScreen({}: ScreenProps) {
title: outcome.title,
message: outcome.message,
variant: outcome.variant === "warning" ? "warning" : "success",
- buttons: [{ text: "Restart app", style: "primary" }]
+ buttons: [{ text: translate("backup.restart"), style: "primary" }]
})
// The row lives in the settings table, so it arrived from inside the archive and is one backup stale.
const madeAt = Date.parse(manifest.createdAt)
@@ -236,7 +240,7 @@ export function BackupRestoreScreen({}: ScreenProps) {
)}
<View style={styles.section}>
- <SectionTitle>Backup</SectionTitle>
+ <SectionTitle>{t("backup.section.backup")}</SectionTitle>
<Card testID="backup-form">
<View style={styles.fields}>
{loaded ? (
@@ -253,7 +257,7 @@ export function BackupRestoreScreen({}: ScreenProps) {
) : null}
<View>
<TextField
- label="Password"
+ label={t("backup.password")}
secure
testID="backup-password"
value={password}
@@ -266,24 +270,24 @@ export function BackupRestoreScreen({}: ScreenProps) {
</View>
<View>
<TextField
- label="Confirm password"
+ label={t("backup.confirmPassword")}
secure
testID="backup-password-confirm"
value={confirm}
onChangeText={setConfirm}
autoCapitalize="none"
autoCorrect={false}
- error={confirm.length > 0 && confirm !== password ? "The two passwords do not match." : undefined}
+ error={confirm.length > 0 && confirm !== password ? t("backup.blocked.mismatch") : undefined}
disabled={busy !== null}
/>
- {!(confirm.length > 0 && confirm !== password) && <FieldMessage>{NO_RECOVERY_LINE}</FieldMessage>}
+ {!(confirm.length > 0 && confirm !== password) && <FieldMessage>{noRecoveryLine()}</FieldMessage>}
</View>
</View>
</Card>
<Button
variant="primary"
icon={Upload}
- title="Create backup"
+ title={t("backup.create")}
testID="create-backup-btn"
loading={busy === "backup"}
disabled={busy !== null || blocked !== null}
@@ -299,7 +303,7 @@ export function BackupRestoreScreen({}: ScreenProps) {
</View>
<View style={styles.section}>
- <SectionTitle>Restore</SectionTitle>
+ <SectionTitle>{t("backup.section.restore")}</SectionTitle>
{!picked && (
<Card rows>
@@ -307,10 +311,10 @@ export function BackupRestoreScreen({}: ScreenProps) {
testID="choose-backup-row"
icon={FileLock}
trailingIcon={Download}
- label="Choose a backup file"
- sub={RESTORE_IDLE_LINE}
+ label={t("backup.choose")}
+ sub={restoreIdleLine()}
subLines={2}
- accessibilityHint="Opens the file picker"
+ accessibilityHint={t("backup.choose.hint")}
disabled={busy !== null}
onPress={onChooseFile}
/>
@@ -324,13 +328,13 @@ export function BackupRestoreScreen({}: ScreenProps) {
icon={FileLock}
iconColor={colors.textSecondary}
label={picked.displayName}
- caption={PICKED_NOT_OPENED_CAPTION}
+ caption={pickedNotOpenedCaption()}
testID="picked-file"
/>
<Divider tight />
<View style={styles.pickedField}>
<TextField
- label="Backup password"
+ label={t("backup.restorePassword")}
secure
testID="restore-password"
value={restorePassword}
@@ -340,12 +344,12 @@ export function BackupRestoreScreen({}: ScreenProps) {
error={restoreMessage?.tone === "error" ? restoreMessage.text : undefined}
disabled={busy !== null}
/>
- {restoreMessage?.tone !== "error" && <FieldMessage>{OPEN_FILE_LINE}</FieldMessage>}
+ {restoreMessage?.tone !== "error" && <FieldMessage>{openFileLine()}</FieldMessage>}
</View>
</Card>
<Button
variant="secondary"
- title="Open this file"
+ title={t("backup.open")}
testID="open-backup-btn"
loading={busy === "open"}
disabled={busy !== null || restorePassword.length === 0}
@@ -353,7 +357,7 @@ export function BackupRestoreScreen({}: ScreenProps) {
/>
<Button
variant="ghost"
- title="Choose a different file"
+ title={t("backup.chooseDifferent")}
testID="repick-backup-btn"
onPress={onChooseFile}
/>
@@ -378,7 +382,7 @@ export function BackupRestoreScreen({}: ScreenProps) {
</Card>
<Button
variant="danger"
- title="Replace all data"
+ title={t("backup.replaceAll")}
testID="restore-btn"
loading={busy === "restore"}
disabled={busy !== null}
@@ -386,7 +390,7 @@ export function BackupRestoreScreen({}: ScreenProps) {
/>
<Button
variant="ghost"
- title="Choose a different file"
+ title={t("backup.chooseDifferent")}
testID="repick-backup-btn"
onPress={onChooseFile}
/>
@@ -398,8 +402,8 @@ export function BackupRestoreScreen({}: ScreenProps) {
<LoadingOverlay
visible={busy === "backup" || busy === "open" || busy === "restore"}
- title={busy === "backup" ? "Writing the backup" : busy === "open" ? "Opening the backup" : "Restoring"}
- message={busy === "restore" ? "Keep Colota open until this finishes." : ""}
+ title={busy === "backup" ? t("backup.writing") : busy === "open" ? t("backup.opening") : t("backup.restoring")}
+ message={busy === "restore" ? t("backup.keepOpen") : ""}
/>
</Container>
)
diff --git a/apps/mobile/src/screens/OfflineMapsScreen.tsx b/apps/mobile/src/screens/OfflineMapsScreen.tsx
index 3dee4610..f7d154f6 100644
--- a/apps/mobile/src/screens/OfflineMapsScreen.tsx
+++ b/apps/mobile/src/screens/OfflineMapsScreen.tsx
@@ -59,7 +59,7 @@ import {
duplicateNameError,
progressCaption,
redownloadConfirm,
- ROW_HINT,
+ rowHint,
storageMessage,
type Bounds,
type Estimate,
@@ -74,6 +74,9 @@ import {
WORLD_MAP_ZOOM
} from "../constants"
import type { ScreenProps } from "../types/global"
+import { useTranslation } from "../i18n/useTranslation"
+// Handlers use the non-hook t, so no callback or effect list carries it.
+import { t as translate } from "../i18n/t"
const MAP_VIEWPORT_SHARE = 0.5
const WORLD_CENTER: [number, number] = [0, 20]
@@ -86,11 +89,6 @@ type Fix = { latitude: number; longitude: number; accuracy: number }
type Download = { name: string; bounds: Bounds | null }
type Busy = { kind: "start" | "stop" | "delete" | "redownload"; name: string }
-const NO_CONNECTION = {
- title: "No connection",
- message: "Downloading map tiles needs a network. Saved areas still work."
-} as const
-
function estimateFor(bounds: Bounds): Estimate {
const { ne, sw } = cornersOf(bounds)
return { label: estimateSizeLabel(ne, sw), bytes: estimateSizeBytes(ne, sw), large: willExceedTileLimit(ne, sw) }
@@ -98,6 +96,7 @@ function estimateFor(bounds: Bounds): Estimate {
export function OfflineMapsScreen({}: ScreenProps) {
const { colors } = useTheme()
+ const { t } = useTranslation()
const { height: viewportHeight } = useWindowDimensions()
const mapHeight = Math.round(viewportHeight * MAP_VIEWPORT_SHARE)
const coords = useCoords()
@@ -315,7 +314,7 @@ export function OfflineMapsScreen({}: ScreenProps) {
logger.error("[OfflineMapsScreen] Failed to start download:", err)
activePackNameRef.current = null
setDownload(null)
- showAlert("Could not start the download", "Nothing was downloaded. Try again.", "error")
+ showAlert(translate("offline.startFailed.title"), translate("offline.startFailed.message"), "error")
return
}
createPendingRef.current = false
@@ -345,7 +344,7 @@ export function OfflineMapsScreen({}: ScreenProps) {
setBusy({ kind: "start", name: trimmed })
try {
if (!(await NativeLocationService.isNetworkAvailable())) {
- showAlert(NO_CONNECTION.title, NO_CONNECTION.message, "warning")
+ showAlert(translate("offline.noConnection.title"), translate("offline.noConnection.message"), "warning")
return
}
const fresh = await loadOfflineAreas()
@@ -353,14 +352,14 @@ export function OfflineMapsScreen({}: ScreenProps) {
if (fresh.some((a) => a.name === trimmed)) return
const availableMB = await NativeLocationService.getAvailableStorageMB()
if (availableMB > 0 && estimate.bytes / BYTES_PER_MB > availableMB * STORAGE_HEADROOM) {
- showAlert("Not enough storage", storageMessage(estimate, availableMB), "warning")
+ showAlert(translate("offline.noStorage"), storageMessage(estimate, availableMB), "warning")
return
}
const metered = !(await NativeLocationService.isUnmeteredConnection())
if (!(await showConfirm({ ...downloadConfirm(trimmed, estimate, metered), destructive: false }))) return
} catch (err) {
logger.error("[OfflineMapsScreen] Failed to start download:", err)
- showAlert("Could not start the download", "Nothing was downloaded. Try again.", "error")
+ showAlert(translate("offline.startFailed.title"), translate("offline.startFailed.message"), "error")
return
} finally {
busyRef.current = false
@@ -385,7 +384,7 @@ export function OfflineMapsScreen({}: ScreenProps) {
await removeOfflineAreaBounds(packName)
} catch (err) {
logger.error("[OfflineMapsScreen] Failed to stop the download:", err)
- showAlert("Could not stop the download", "The download may still be running. Try again.", "error")
+ showAlert(translate("offline.stopFailed.title"), translate("offline.stopFailed.message"), "error")
} finally {
busyRef.current = false
setBusy(null)
@@ -405,7 +404,7 @@ export function OfflineMapsScreen({}: ScreenProps) {
await removeOfflineAreaBounds(area.name)
} catch (err) {
logger.error("[OfflineMapsScreen] Failed to stop the download:", err)
- showAlert("Could not stop the download", "The download may still be running. Try again.", "error")
+ showAlert(translate("offline.stopFailed.title"), translate("offline.stopFailed.message"), "error")
} finally {
busyRef.current = false
setBusy(null)
@@ -424,14 +423,14 @@ export function OfflineMapsScreen({}: ScreenProps) {
try {
if (!area.bounds) {
showAlert(
- "Cannot download again",
- "This area's extent could not be read. Delete it and download it again.",
+ translate("offline.cannotRedownload.title"),
+ translate("offline.cannotRedownload.message"),
"warning"
)
return
}
if (!(await NativeLocationService.isNetworkAvailable())) {
- showAlert(NO_CONNECTION.title, NO_CONNECTION.message, "warning")
+ showAlert(translate("offline.noConnection.title"), translate("offline.noConnection.message"), "warning")
return
}
const metered = !(await NativeLocationService.isUnmeteredConnection())
@@ -441,11 +440,7 @@ export function OfflineMapsScreen({}: ScreenProps) {
go = true
} catch (err) {
logger.error("[OfflineMapsScreen] Failed to download again:", err)
- showAlert(
- "Could not download again",
- "The old tiles could not be removed, so nothing was downloaded. Try again.",
- "error"
- )
+ showAlert(translate("offline.redownloadFailed.title"), translate("offline.redownloadFailed.message"), "error")
} finally {
busyRef.current = false
setBusy(null)
@@ -469,7 +464,7 @@ export function OfflineMapsScreen({}: ScreenProps) {
await removeOfflineAreaBounds(area.name)
} catch (err) {
logger.error("[OfflineMapsScreen] Failed to delete area:", err)
- showAlert("Could not delete the area", "Its tiles are still on the device. Try again.", "error")
+ showAlert(translate("offline.deleteFailed.title"), translate("offline.deleteFailed.message"), "error")
} finally {
busyRef.current = false
setBusy(null)
@@ -530,12 +525,12 @@ export function OfflineMapsScreen({}: ScreenProps) {
<ScrollView contentContainerStyle={styles.content} keyboardShouldPersistTaps="handled">
<View style={styles.section}>
- <SectionTitle>New area</SectionTitle>
+ <SectionTitle>{t("offline.section.new")}</SectionTitle>
<Card>
<TextField
testID="area-name-input"
- label="Name"
- placeholder="Home area, Trail…"
+ label={t("offline.name")}
+ placeholder={t("offline.name.placeholder")}
value={name}
onChangeText={setName}
error={nameError}
@@ -546,7 +541,7 @@ export function OfflineMapsScreen({}: ScreenProps) {
<View>
<Button
testID="download-btn"
- title="Download area"
+ title={t("offline.downloadArea")}
loading={busy?.kind === "start"}
disabled={downloadDisabled}
onPress={handleDownload}
@@ -568,7 +563,7 @@ export function OfflineMapsScreen({}: ScreenProps) {
testID="download-progress"
accessible
accessibilityRole="progressbar"
- accessibilityLabel={`Downloading ${download.name}`}
+ accessibilityLabel={t("offline.downloadingName", { name: download.name })}
accessibilityValue={{ min: 0, max: 100, now: Math.round(pct) }}
style={[styles.progressTrack, { backgroundColor: colors.well }]}
>
@@ -581,7 +576,7 @@ export function OfflineMapsScreen({}: ScreenProps) {
variant="ghost"
color={colors.error}
icon={X}
- title="Cancel download"
+ title={t("offline.cancel")}
loading={busy?.kind === "stop"}
disabled={busy !== null}
onPress={handleCancelDownload}
@@ -592,7 +587,7 @@ export function OfflineMapsScreen({}: ScreenProps) {
{areas !== null && listAreas.length > 0 && (
<View style={styles.section}>
- <SectionTitle>Saved areas</SectionTitle>
+ <SectionTitle>{t("offline.section.saved")}</SectionTitle>
<Card rows>
{listAreas.map((area, i) => {
const row = describeArea(area, entryFor(area.name), currentStyleUrl)
@@ -607,14 +602,14 @@ export function OfflineMapsScreen({}: ScreenProps) {
label={area.name}
sub={row.sub}
subLines={2}
- accessibilityHint={ROW_HINT}
+ accessibilityHint={rowHint()}
onPress={() => area.bounds && fitToArea(area.bounds)}
trailing={
area.isActive ? (
<IconButton
icon={X}
tone="danger"
- accessibilityLabel={`Stop downloading ${area.name}`}
+ accessibilityLabel={t("offline.stopName", { name: area.name })}
loading={mine("stop")}
disabled={busy !== null}
onPress={() => handleCancelArea(area)}
@@ -625,7 +620,7 @@ export function OfflineMapsScreen({}: ScreenProps) {
<IconButton
icon={RefreshCw}
tone="primary"
- accessibilityLabel={`Download ${area.name} again`}
+ accessibilityLabel={t("offline.againName", { name: area.name })}
loading={mine("redownload")}
disabled={download !== null || busy !== null}
onPress={() => handleRedownload(area)}
@@ -634,7 +629,7 @@ export function OfflineMapsScreen({}: ScreenProps) {
<IconButton
icon={Trash2}
tone="danger"
- accessibilityLabel={`Delete ${area.name}`}
+ accessibilityLabel={t("offline.deleteName", { name: area.name })}
loading={mine("delete")}
disabled={busy !== null}
onPress={() => handleDelete(area)}
@@ -652,11 +647,7 @@ export function OfflineMapsScreen({}: ScreenProps) {
)}
{areas !== null && listAreas.length === 0 && download === null && (
- <EmptyState
- title="No saved areas yet"
- hint="Download map tiles to browse your tracks offline while hiking or camping"
- style={styles.empty}
- />
+ <EmptyState title={t("offline.empty.title")} hint={t("offline.empty.hint")} style={styles.empty} />
)}
</ScrollView>
</Container>
diff --git a/apps/mobile/src/utils/__tests__/backupState.test.ts b/apps/mobile/src/utils/__tests__/backupState.test.ts
index 8d4a3d98..0a322d39 100644
--- a/apps/mobile/src/utils/__tests__/backupState.test.ts
+++ b/apps/mobile/src/utils/__tests__/backupState.test.ts
@@ -196,6 +196,17 @@ describe("restoreOutcome", () => {
})
describe("restoreErrorMessage", () => {
+ // An unknown code still has to end on the reassurance, with or without native's own sentence.
+ it("falls back to native's sentence, or a generic one when native says nothing", () => {
+ expect(restoreErrorMessage(undefined)).toBe("The backup could not be restored. Nothing on this device was changed.")
+ expect(restoreErrorMessage("E_OTHER", "")).toBe(
+ "The backup could not be restored. Nothing on this device was changed."
+ )
+ expect(restoreErrorMessage("E_OTHER", "Disk read failed.")).toBe(
+ "Disk read failed. Nothing on this device was changed."
+ )
+ })
+
// Every pre-swap failure is provably one where nothing was replaced, so every one says so.
it("ends every pre-swap failure with the same promise", () => {
for (const code of [
diff --git a/apps/mobile/src/utils/backupState.ts b/apps/mobile/src/utils/backupState.ts
index 3d361ca6..a703bbf2 100644
--- a/apps/mobile/src/utils/backupState.ts
+++ b/apps/mobile/src/utils/backupState.ts
@@ -6,6 +6,7 @@
import type { BackupManifest, PasswordStrengthResult } from "../services/BackupService"
import { formatDateWithYear } from "./geo"
import { formatBytes } from "./format"
+import { t } from "../i18n/t"
/**
* What a backup holds and what restoring one replaces, in the words the screen prints.
@@ -20,7 +21,7 @@ import { formatBytes } from "./format"
* make any claim that one exists a lie.
*/
-const plural = (n: number, noun: string) => `${n.toLocaleString()} ${noun}${n === 1 ? "" : "s"}`
+const locations = (n: number) => t("backup.locations", { count: n, n: n.toLocaleString() })
const whenBackedUp = (ms: number | null): string | null =>
ms && ms > 0 ? formatDateWithYear(Math.floor(ms / 1000)) : null
@@ -36,17 +37,20 @@ export function backupState(
lastBackupAtMs: number | null,
stats: { total: number; databaseSizeMB: number }
): BackupStateLine {
- const caption = `Database: ${plural(stats.total, "location")}, ${formatBytes(stats.databaseSizeMB * 1024 * 1024, { decimals: 0 })}`
+ const caption = t("backup.caption", {
+ locations: locations(stats.total),
+ size: formatBytes(stats.databaseSizeMB * 1024 * 1024, { decimals: 0 })
+ })
const when = whenBackedUp(lastBackupAtMs)
- if (when) return { label: `You last backed up ${when}`, caption, tone: "ok" }
- if (stats.total === 0) return { label: "You have never backed up", caption, tone: "empty" }
- return { label: "You have never backed up", caption, tone: "none" }
+ if (when) return { label: t("backup.last", { when }), caption, tone: "ok" }
+ if (stats.total === 0) return { label: t("backup.never"), caption, tone: "empty" }
+ return { label: t("backup.never"), caption, tone: "none" }
}
/** The Settings hub row. */
export function backupRowSub(lastBackupAtMs: number | null): string {
const when = whenBackedUp(lastBackupAtMs)
- return when ? `Last backed up ${when}` : "Never backed up"
+ return when ? t("backup.row.last", { when }) : t("backup.row.never")
}
/** The line under the password field, from the score native computed rather than a second guess. */
@@ -54,11 +58,14 @@ export function passwordLine(
strength: PasswordStrengthResult,
failed: boolean
): { text: string; variant: "info" | "warning" } {
- if (failed) return { text: "Could not check this password. Try again.", variant: "warning" }
- if (strength.score >= 2) return { text: `${strength.label}.`, variant: "info" }
+ if (failed) return { text: t("backup.password.checkFailed"), variant: "warning" }
+ if (strength.score >= 2) return { text: t("backup.password.label", { label: strength.label }), variant: "info" }
// Native's own label, so the reason can never disagree with the gate and no length lives in JS.
- const advice = strength.score === 0 ? "Make it longer." : "Make it longer or less predictable."
- return { text: strength.label ? `${strength.label}. ${advice}` : advice, variant: "warning" }
+ const advice = strength.score === 0 ? t("backup.password.longer") : t("backup.password.longerOrLess")
+ return {
+ text: strength.label ? t("backup.password.labelAdvice", { label: strength.label, advice }) : advice,
+ variant: "warning"
+ }
}
/** Why Create backup is disabled, in the words of the rule that blocks it. */
@@ -67,16 +74,16 @@ export function submitBlockedReason(
confirm: string,
strength: PasswordStrengthResult
): string | null {
- if (password.length === 0) return "Choose a password first."
- if (strength.score < 2) return "This password is too easy to guess."
- if (confirm.length === 0) return "Type the password a second time."
- if (password !== confirm) return "The two passwords do not match."
+ if (password.length === 0) return t("backup.blocked.choose")
+ if (strength.score < 2) return t("backup.blocked.weak")
+ if (confirm.length === 0) return t("backup.blocked.confirm")
+ if (password !== confirm) return t("backup.blocked.mismatch")
return null
}
/** What a new archive would contain, stated at the top of the backup form. */
export function backupScopeLine(total: number): string {
- return `Writes ${plural(total, "location")}, your geofences, profiles, settings and your stored server credentials to a file you pick.`
+ return t("backup.scope", { count: total, n: total.toLocaleString() })
}
/**
@@ -85,34 +92,37 @@ export function backupScopeLine(total: number): string {
*/
export function backupExcludesLine(hasClientCert: boolean): string | null {
if (!hasClientCert) return null
- return "Your client certificate is not included. Its private key cannot leave this device's keystore."
+ return t("backup.excludesCert")
}
/** The archive is encrypted and there is no reset, which is the one thing worth saying twice. */
-export const NO_RECOVERY_LINE = "Nobody can open this file without the password, and there is no way to reset it."
+export const noRecoveryLine = () => t("backup.noRecovery")
-export const BACKUP_WRITTEN_LINE = "Backup written. Keep it somewhere you can reach without this phone."
+export const backupWrittenLine = () => t("backup.written")
-export const RESTORE_IDLE_LINE = "Replaces everything on this device. Nothing is merged."
+export const restoreIdleLine = () => t("backup.restoreIdle")
-export const PICKED_NOT_OPENED_CAPTION = "Not opened yet."
+export const pickedNotOpenedCaption = () => t("backup.pickedNotOpened")
-export const OPEN_FILE_LINE = "Checks the password and reads what the file holds. Nothing on this device changes."
+export const openFileLine = () => t("backup.openFile")
+
+const madeOn = (manifest: BackupManifest) => {
+ const seconds = Date.parse(manifest.createdAt) / 1000
+ return Number.isFinite(seconds) ? formatDateWithYear(Math.floor(seconds)) : t("backup.unknownDate")
+}
/** The opened archive, as a state line. */
export function archiveLine(manifest: BackupManifest): { label: string; caption: string } {
- const seconds = Date.parse(manifest.createdAt) / 1000
- const made = Number.isFinite(seconds) ? formatDateWithYear(Math.floor(seconds)) : "an unknown date"
return {
- label: `Backup from ${made}`,
- caption: `Colota ${manifest.appVersion} · opened with your password`
+ label: t("backup.from", { date: madeOn(manifest) }),
+ caption: t("backup.openedWith", { version: manifest.appVersion })
}
}
/** At most one caveat, so restraint is a signature rather than a discipline. */
export function restoreCaveat(certConfigured: boolean): string | null {
if (!certConfigured) return null
- return "Your client certificate stays as it is. A backup carries none, and a restore does not replace it."
+ return t("backup.restoreCaveat")
}
export interface ConfirmCopy {
@@ -123,12 +133,10 @@ export interface ConfirmCopy {
/** Names the count it replaces and the date it replaces them with. */
export function restoreConfirm(total: number, manifest: BackupManifest): ConfirmCopy {
- const seconds = Date.parse(manifest.createdAt) / 1000
- const made = Number.isFinite(seconds) ? formatDateWithYear(Math.floor(seconds)) : "an unknown date"
return {
- title: `Replace all ${plural(total, "location")}?`,
- message: `Replaces everything on this device with the backup from ${made}: locations, geofences, tracking profiles, trip splits, settings, the upload queue and your stored server credentials. Nothing is merged and nothing is kept. Recording stops and stays off until you turn it back on. The file and the password have already been checked, so your data is replaced in one step at the end, and that step cannot be undone.`,
- confirmText: "Replace"
+ title: t("backup.replace.title", { count: total, n: total.toLocaleString() }),
+ message: t("backup.replace.message", { date: madeOn(manifest) }),
+ confirmText: t("backup.replace.confirm")
}
}
@@ -150,30 +158,28 @@ export function restoreOutcome(code: string | undefined, nativeMessage?: string)
case undefined:
return {
kind: "restored",
- title: "Your data is restored",
- message: "Recording is off. Turn it back on when you are ready.",
+ title: t("backup.restored.title"),
+ message: t("backup.restored.message"),
variant: "success"
}
case "E_BACKUP_SECRETS_PARTIAL":
return {
kind: "restored",
- title: "Your data is restored",
- message:
- "Your server credentials could not be applied. Enter them again on Connection. Recording is off until you turn it back on.",
+ title: t("backup.restored.title"),
+ message: t("backup.restored.secrets"),
variant: "warning"
}
case "E_BACKUP_RESTORED_INCOMPLETE":
return {
kind: "restored",
- title: "Your data is restored",
- message:
- "Something failed after the swap, so some settings may not have been applied. Check Connection and Tracking. Recording is off until you turn it back on.",
+ title: t("backup.restored.title"),
+ message: t("backup.restored.incomplete"),
variant: "warning"
}
default:
return {
kind: "failed",
- title: "Restore failed",
+ title: t("backup.restoreFailed"),
message: restoreErrorMessage(code, nativeMessage),
variant: "error"
}
@@ -181,44 +187,44 @@ export function restoreOutcome(code: string | undefined, nativeMessage?: string)
}
/** Every pre-swap failure ends the same way, because on every one of them it is true. */
-const UNCHANGED = "Nothing on this device was changed."
+const unchanged = (sentence: string) => `${sentence} ${t("backup.unchanged")}`
export function restoreErrorMessage(code: string | undefined, nativeMessage?: string): string {
switch (code) {
case "E_BACKUP_WRONG_PASSWORD":
- return `That password did not open this file. ${UNCHANGED}`
+ return unchanged(t("backup.err.wrongPassword"))
case "E_BACKUP_BAD_MAGIC":
case "E_BACKUP_UNSUPPORTED_VERSION":
- return `This is not a Colota backup. ${UNCHANGED}`
+ return unchanged(t("backup.err.notBackup"))
case "E_BACKUP_TRUNCATED":
- return `This file is incomplete, so it was probably never finished being written. ${UNCHANGED}`
+ return unchanged(t("backup.err.truncated"))
case "E_BACKUP_TAMPERED":
case "E_BACKUP_INTEGRITY_FAIL":
- return `This file is damaged and cannot be trusted. ${UNCHANGED}`
+ return unchanged(t("backup.err.tampered"))
case "E_BACKUP_MIGRATION_FAILED":
- return `The file is intact but this version of Colota could not read its database. ${UNCHANGED}`
+ return unchanged(t("backup.err.migration"))
case "E_BACKUP_UNSUPPORTED_SCHEMA":
- return `This backup was made by a newer version of Colota. Update the app first. ${UNCHANGED}`
+ return unchanged(t("backup.err.newer"))
case "E_BACKUP_MISSING_ENTRY":
- return `This file is missing part of a backup. ${UNCHANGED}`
+ return unchanged(t("backup.err.missingEntry"))
case "E_BACKUP_NO_SPACE":
- return `There is not enough free space to unpack this backup. ${UNCHANGED}`
+ return unchanged(t("backup.err.noSpace"))
case "E_BUSY":
- return "Another backup or restore is already running."
+ return t("backup.err.busy")
case "E_PASSWORD_EMPTY":
- return "Type the backup's password first."
+ return t("backup.err.passwordEmpty")
default:
- return nativeMessage ? `${nativeMessage} ${UNCHANGED}` : `The backup could not be restored. ${UNCHANGED}`
+ return unchanged(nativeMessage || t("backup.err.restoreGeneric"))
}
}
export function backupErrorMessage(code: string | undefined, nativeMessage?: string): string {
switch (code) {
case "E_BUSY":
- return "Another backup or restore is already running."
+ return t("backup.err.busy")
case "E_PASSWORD_EMPTY":
- return "Choose a password first."
+ return t("backup.blocked.choose")
default:
- return nativeMessage ?? "The backup could not be written. Try a different location."
+ return nativeMessage ?? t("backup.err.writeGeneric")
}
}
diff --git a/apps/mobile/src/utils/offlineArea.ts b/apps/mobile/src/utils/offlineArea.ts
index b525207f..349c0a6c 100644
--- a/apps/mobile/src/utils/offlineArea.ts
+++ b/apps/mobile/src/utils/offlineArea.ts
@@ -12,6 +12,7 @@ import type {
} from "../components/features/map/OfflinePackManager"
import { formatBytes } from "./format"
import { formatDateWithYear } from "./geo"
+import { t } from "../i18n/t"
/**
* What an offline area holds and what a download takes, in the words the screen prints.
@@ -30,28 +31,32 @@ export interface Estimate {
large: boolean
}
-export const ROW_HINT = "Shows it on the map"
+export const rowHint = () => t("offline.rowHint")
export function duplicateNameError(name: string, taken: readonly string[]): string | undefined {
const trimmed = name.trim()
- return trimmed && taken.includes(trimmed) ? `An area named "${trimmed}" already exists.` : undefined
+ return trimmed && taken.includes(trimmed) ? t("offline.duplicate", { name: trimmed }) : undefined
}
export function estimateSentence(estimate: Estimate): string {
- return estimate.large ? `At least ${estimate.label}.` : `${estimate.label} estimated.`
+ return estimate.large
+ ? t("offline.atLeast", { size: estimate.label })
+ : t("offline.estimated", { size: estimate.label })
}
/** The line under Download area: why it is disabled, or what pressing it takes. */
export function downloadLine(estimate: Estimate | null, name: string): string {
- if (!estimate) return "Waiting for the map."
- const size = estimate.large ? `${estimateSentence(estimate)} Zoom in to download less.` : estimateSentence(estimate)
- return name.trim() ? size : `${size} Name the area to download it.`
+ if (!estimate) return t("offline.waiting")
+ const size = estimate.large ? `${estimateSentence(estimate)} ${t("offline.zoomIn")}` : estimateSentence(estimate)
+ return name.trim() ? size : `${size} ${t("offline.nameIt")}`
}
export function progressCaption(status: OfflinePackStatus | null): string {
- if (!status) return "Starting download…"
- const pct = `Downloading · ${Math.round(status.percentage)}%`
- return status.completedResourceSize > 0 ? `${pct} · ${formatBytes(status.completedResourceSize)} so far` : pct
+ if (!status) return t("offline.starting")
+ const pct = t("offline.downloadingPct", { pct: Math.round(status.percentage) })
+ return status.completedResourceSize > 0
+ ? `${pct} · ${t("offline.soFar", { size: formatBytes(status.completedResourceSize) })}`
+ : pct
}
export type RowTone = "active" | "attention" | "plain"
@@ -72,19 +77,19 @@ export function describeArea(
entry: OfflineAreaBounds | undefined,
currentStyleUrl: string | null
): AreaRow {
- if (area.isActive) return { icon: Loader, tone: "active", sub: "Downloading…" }
- if (area.sizeBytes === null) return { icon: CircleAlert, tone: "attention", sub: "Could not read this area" }
+ if (area.isActive) return { icon: Loader, tone: "active", sub: t("offline.downloading") }
+ if (area.sizeBytes === null) return { icon: CircleAlert, tone: "attention", sub: t("offline.unreadable") }
if (!area.isComplete) {
return {
icon: CircleAlert,
tone: "attention",
- sub: area.sizeBytes > 0 ? `Incomplete · ${formatBytes(area.sizeBytes)}` : "Incomplete"
+ sub: area.sizeBytes > 0 ? `${t("offline.incomplete")} · ${formatBytes(area.sizeBytes)}` : t("offline.incomplete")
}
}
const when = entry?.downloadedAt ? ` · ${formatDateWithYear(Math.floor(entry.downloadedAt / 1000))}` : ""
const size = `${formatBytes(area.sizeBytes)}${when}`
const stale = !!entry?.styleUrl && !!currentStyleUrl && entry.styleUrl !== currentStyleUrl
- if (stale) return { icon: TriangleAlert, tone: "attention", sub: `Map style changed · ${size}` }
+ if (stale) return { icon: TriangleAlert, tone: "attention", sub: `${t("offline.styleChanged")} · ${size}` }
return { icon: Map, tone: "plain", sub: size }
}
@@ -94,38 +99,39 @@ export interface ConfirmCopy {
confirmText: string
}
-const CAP_SENTENCE = "The estimate stops counting at 100,000 tiles and the download does not."
-const METERED_SENTENCE = "You are on mobile data, not WiFi."
-
function sizeClause(estimate: Estimate, metered: boolean): string {
- const size = estimate.large ? `${estimateSentence(estimate)} ${CAP_SENTENCE}` : estimateSentence(estimate)
- return metered ? `${size} ${METERED_SENTENCE}` : size
+ const size = estimate.large ? `${estimateSentence(estimate)} ${t("offline.cap")}` : estimateSentence(estimate)
+ return metered ? `${size} ${t("offline.metered")}` : size
}
export function downloadConfirm(name: string, estimate: Estimate, metered: boolean): ConfirmCopy {
- return { title: `Download "${name}"?`, message: sizeClause(estimate, metered), confirmText: "Download" }
+ return {
+ title: t("offline.download.title", { name }),
+ message: sizeClause(estimate, metered),
+ confirmText: t("offline.download.confirm")
+ }
}
export function redownloadConfirm(name: string, estimate: Estimate, metered: boolean): ConfirmCopy {
return {
- title: `Download "${name}" again?`,
- message: `Replaces its tiles with a fresh download. ${sizeClause(estimate, metered)}`,
- confirmText: "Download again"
+ title: t("offline.redownload.title", { name }),
+ message: `${t("offline.redownload.lead")} ${sizeClause(estimate, metered)}`,
+ confirmText: t("offline.redownload.confirm")
}
}
/** Names the bytes, and the ambient tile cache the last delete takes with it. */
export function deleteAreaConfirm(name: string, sizeBytes: number | null, isLast: boolean): ConfirmCopy {
- const what = sizeBytes
- ? `Removes ${formatBytes(sizeBytes)} of map tiles from this device.`
- : "Removes its map tiles from this device."
- const last = isLast ? " It is the last saved area, so the map's online tile cache is cleared too." : ""
- return { title: `Delete "${name}"?`, message: `${what}${last}`, confirmText: "Delete" }
+ const what = sizeBytes ? t("offline.delete.size", { size: formatBytes(sizeBytes) }) : t("offline.delete.noSize")
+ const last = isLast ? ` ${t("offline.delete.last")}` : ""
+ return { title: t("offline.delete.title", { name }), message: `${what}${last}`, confirmText: t("common.delete") }
}
export function storageMessage(estimate: Estimate, availableMB: number): string {
- const needed = estimate.large ? `At least ${estimate.label}` : estimate.label
- return `${needed} is needed and the device has ${availableMB.toFixed(1)} MB free.`
+ const free = availableMB.toFixed(1)
+ return estimate.large
+ ? t("offline.storage.atLeast", { size: estimate.label, free })
+ : t("offline.storage", { size: estimate.label, free })
}
export function cornersOf(bounds: Bounds): { ne: [number, number]; sw: [number, number] } {