Skip to content

Colota - Android GPS Location tracker

refactor(i18n): move Authentication and mTLS into the catalog (#904)

Max Dietrich5136ebbeccac
diff --git a/apps/mobile/src/components/features/settings/SyncStrategySettings.tsx b/apps/mobile/src/components/features/settings/SyncStrategySettings.tsx
index ad0ece50..18027ce3 100644
--- a/apps/mobile/src/components/features/settings/SyncStrategySettings.tsx
+++ b/apps/mobile/src/components/features/settings/SyncStrategySettings.tsx
@@ -32,7 +32,7 @@ import { useTheme } from "../../../hooks/useTheme"
import { useTimeout } from "../../../hooks/useTimeout"
import { shortDistanceUnit, inputToMeters, metersToInput } from "../../../utils/geo"
import { syncSummary, trackingSummary } from "../../../utils/dashboardState"
-import { recordingClause } from "../../../utils/profileRow"
+import { recordingPhrase } from "../../../utils/profileRow"
import { parseWholeNumber, wholeNumberError } from "../../../utils/settingsValidation"
import { isOverlandFormat } from "../../../utils/apiPayload"
import NativeLocationService from "../../../services/NativeLocationService"
@@ -59,8 +59,6 @@ const SYNC_CONDITION_OPTIONS: { value: SyncCondition; labelKey: TranslationKey;
{ value: "vpn", labelKey: "trackingSync.condition.vpn", subKey: "trackingSync.condition.vpn.sub" }
]
-const lowerFirst = (text: string) => text.charAt(0).toLowerCase() + text.slice(1)
-
export function SyncStrategySettings({
settings,
onSettingsChange,
@@ -232,7 +230,7 @@ export function SyncStrategySettings({
icon={UserRoundPen}
iconColor={colors.textSecondary}
label={t("trackingSync.profileActive", { name: activeProfile.name })}
- caption={t("trackingSync.inForce", { clause: lowerFirst(recordingClause(activeProfile)) })}
+ caption={t("trackingSync.inForce", { clause: recordingPhrase(activeProfile) })}
testID="profile-override-recording"
/>
<Divider tight />
diff --git a/apps/mobile/src/constants/index.ts b/apps/mobile/src/constants/index.ts
index a80fd2aa..d2de5715 100644
--- a/apps/mobile/src/constants/index.ts
+++ b/apps/mobile/src/constants/index.ts
@@ -85,50 +85,31 @@ export const LOADING_INDICATOR_DELAY_MS = 200
// Doze batches motion sensors past this; longer Stationary intervals risk missed trip starts.
export const STATIONARY_MAX_INTERVAL_SECONDS = 60
-/** `label` names the condition, `listLabel` opens a row's sentence, `description` says what watching it costs. */
export const PROFILE_CONDITIONS: {
type: ProfileConditionType
- label: string
- listLabel: string
+ labelKey: TranslationKey
+ /** Opens a row or the rule sentence: "When charging". */
+ listKey: TranslationKey
+ /** The same clause inside a sentence, where the case may differ: "when charging". */
+ clauseKey: TranslationKey
icon: typeof Zap
- description: string
-}[] = [
- {
- type: "charging",
- label: "Charging",
- listLabel: "When charging",
- icon: Zap,
- description: "Phone is plugged in"
- },
- {
- type: "android_auto",
- label: "Android Auto",
- listLabel: "On Android Auto",
- icon: Car,
- description: "Android Auto is connected"
- },
- {
- type: "speed_above",
- label: "Speed above",
- listLabel: "Speed above",
- icon: ArrowUp,
- description: "Average speed is above the speed you set"
- },
- {
- type: "speed_below",
- label: "Speed below",
- listLabel: "Speed below",
- icon: ArrowDown,
- description: "Average speed is below the speed you set"
- },
- {
- type: "stationary",
- label: "Stationary",
- listLabel: "When stationary",
- icon: Pause,
- description: "Phone stays still for the activation delay"
- }
-]
+ descriptionKey: TranslationKey
+}[] = (
+ [
+ ["charging", Zap],
+ ["android_auto", Car],
+ ["speed_above", ArrowUp],
+ ["speed_below", ArrowDown],
+ ["stationary", Pause]
+ ] as const
+).map(([type, icon]) => ({
+ type,
+ labelKey: `condition.${type}`,
+ listKey: `condition.${type}.list`,
+ clauseKey: `condition.${type}.clause`,
+ icon,
+ descriptionKey: `condition.${type}.description`
+}))
export function defaultProfileDelays(conditionType: ProfileConditionType): {
activationDelay: number
diff --git a/apps/mobile/src/i18n/locales/en.json b/apps/mobile/src/i18n/locales/en.json
index fd7157bd..336b1fe7 100644
--- a/apps/mobile/src/i18n/locales/en.json
+++ b/apps/mobile/src/i18n/locales/en.json
@@ -326,5 +326,78 @@
"mtls.importCa.sub": "For a private or self-signed CA. CAs you installed in Android settings are not used.",
"mtls.ca.note": "Encrypted on this device and included in encrypted backups.",
"mtls.subject": "Subject",
- "mtls.issuer": "Issuer"
+ "mtls.issuer": "Issuer",
+ "condition.charging": "Charging",
+ "condition.charging.list": "When charging",
+ "condition.charging.clause": "when charging",
+ "condition.charging.description": "Phone is plugged in",
+ "condition.android_auto": "Android Auto",
+ "condition.android_auto.list": "On Android Auto",
+ "condition.android_auto.clause": "on Android Auto",
+ "condition.android_auto.description": "Android Auto is connected",
+ "condition.speed_above": "Speed above",
+ "condition.speed_above.list": "Speed above {{speed}}",
+ "condition.speed_above.clause": "speed above {{speed}}",
+ "condition.speed_above.description": "Average speed is above the speed you set",
+ "condition.speed_below": "Speed below",
+ "condition.speed_below.list": "Speed below {{speed}}",
+ "condition.speed_below.clause": "speed below {{speed}}",
+ "condition.speed_below.description": "Average speed is below the speed you set",
+ "condition.stationary": "Stationary",
+ "condition.stationary.list": "When stationary",
+ "condition.stationary.clause": "when stationary",
+ "condition.stationary.description": "Phone stays still for the activation delay",
+ "common.delete": "Delete",
+ "tracking.recording.whileStill": "Every {{duration}} while still",
+ "tracking.phrase.anyMovement": "every {{duration}}, any movement",
+ "tracking.phrase.after": "every {{duration}} after {{distance}}",
+ "tracking.phrase.whileStill": "every {{duration}} while still",
+ "tracking.syncVerb.eachFix": "sync each fix",
+ "tracking.syncVerb.every": "sync every {{duration}}",
+ "profile.row.active": "Active · {{condition}}",
+ "profile.when.faster": "When faster than {{speed}}",
+ "profile.when.slower": "When slower than {{speed}}",
+ "profile.sentence": "{{when}}, track {{recording}} and {{sync}}.",
+ "profile.sentence.offline": "{{when}}, track {{recording}}.",
+ "profile.noneActive": "No profile active",
+ "profile.state.notTracking": "Profiles apply while tracking runs",
+ "profile.state.settingsApply": "Tracking & sync applies: {{summary}}",
+ "profiles.updateFailed": "Failed to update profile.",
+ "profiles.shareFailed": "Failed to share profiles.",
+ "profiles.share": "Share all profiles",
+ "profiles.intro": "Checked top to bottom while tracking runs. The first profile whose condition holds replaces the Tracking & sync values.",
+ "profiles.use": "Use {{name}}",
+ "profiles.empty.title": "No profiles yet",
+ "profiles.empty.hint": "A profile changes how you track while a condition holds, such as charging or driving",
+ "profileEditor.titleEdit": "Edit profile",
+ "profileEditor.titleNew": "New profile",
+ "profileEditor.loadFailed": "Failed to load profile data.",
+ "profileEditor.deleteFailed": "Failed to delete profile.",
+ "profileEditor.saveFailed": "Failed to save profile.",
+ "profileEditor.delete.title": "Delete profile",
+ "profileEditor.delete.message": "Delete \"{{name}}\"?",
+ "profileEditor.section.condition": "Condition",
+ "profileEditor.section.profile": "Profile",
+ "profileEditor.section.tracking": "Tracking while active",
+ "profileEditor.section.switching": "Switching",
+ "profileEditor.speed": "Speed",
+ "profileEditor.speed.hintAbove": "At least 1 {{unit}}. Applies while your average speed is above it.",
+ "profileEditor.speed.hintBelow": "At least 1 {{unit}}. Applies while your average speed is below it.",
+ "profileEditor.name": "Name",
+ "profileEditor.name.hint": "Shown on the Dashboard while active. Blank uses the condition's name.",
+ "profileEditor.priority": "Priority",
+ "profileEditor.priority.hint": "Higher wins when two profiles match at once. Equal numbers go to the older profile.",
+ "profileEditor.interval": "Tracking interval",
+ "profileEditor.interval.hint": "At least 1 s. Replaces the {{duration}} from Tracking & sync while this profile is active. Shorter keeps the GPS awake more of the time and records more points.",
+ "profileEditor.stationaryLong": "Longer than {{max}} s may leave the first {{duration}} of a trip unrecorded",
+ "profileEditor.distance.stationary": "Not used while still · a point is recorded every interval",
+ "profileEditor.distance.hint": "At least 0 {{unit}}. Replaces the {{distance}} from Tracking & sync. 0 records any movement, larger skips small drift.",
+ "profileEditor.sync.hint": "Replaces the {{interval}} from Tracking & sync while this profile is active · shorter means more wake-ups",
+ "profileEditor.activation": "Activation delay",
+ "profileEditor.activation.hintStationary": "How long every fix must read as still; 0 switches at the first still fix. Moving again ends the profile at once.",
+ "profileEditor.activation.hint": "How long the condition must hold first. 0 switches at once, longer ignores a brief plug or unplug.",
+ "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"
}
diff --git a/apps/mobile/src/screens/ProfileEditorScreen.tsx b/apps/mobile/src/screens/ProfileEditorScreen.tsx
index ae0c43c4..59c49f63 100644
--- a/apps/mobile/src/screens/ProfileEditorScreen.tsx
+++ b/apps/mobile/src/screens/ProfileEditorScreen.tsx
@@ -40,6 +40,7 @@ import {
space
} from "../constants"
import type { RootScreenProps } from "../types/navigation"
+import { useTranslation } from "../i18n/useTranslation"
type Draft = Omit<TrackingProfile, "id" | "createdAt">
type NumericKey = "interval" | "distance" | "activationDelay" | "deactivationDelay" | "speed"
@@ -51,6 +52,7 @@ const isSpeedType = (type: ProfileConditionType) => type === "speed_above" || ty
export function ProfileEditorScreen({ navigation, route }: RootScreenProps<"Profile Editor">) {
const { colors } = useTheme()
+ const { t } = useTranslation()
const { settings } = useTracking()
const profileId = route?.params?.profileId as number | undefined
const isEditing = !!profileId
@@ -80,8 +82,8 @@ export function ProfileEditorScreen({ navigation, route }: RootScreenProps<"Prof
const noteTimer = useTimeout()
useLayoutEffect(() => {
- navigation.setOptions({ headerTitle: isEditing ? "Edit profile" : "New profile" })
- }, [navigation, isEditing])
+ navigation.setOptions({ headerTitle: isEditing ? t("profileEditor.titleEdit") : t("profileEditor.titleNew") })
+ }, [navigation, isEditing, t])
useEffect(() => {
if (!profileId) return
@@ -113,15 +115,15 @@ export function ProfileEditorScreen({ navigation, route }: RootScreenProps<"Prof
})
.catch((err) => {
logger.error("[ProfileEditor] Failed to load profile:", err)
- showAlert("Error", "Failed to load profile data.", "error")
+ showAlert(t("common.error"), t("profileEditor.loadFailed"), "error")
navigation.goBack()
})
- }, [profileId, navigation])
+ }, [profileId, navigation, t])
const type = profile.condition.type
const isSpeed = isSpeedType(type)
const isStationary = type === "stationary"
- const conditionLabel = conditionOf(profile).label
+ const conditionLabel = t(conditionOf(profile).labelKey)
const store = useCallback((key: NumericKey, value: number) => {
setProfile((prev) => {
@@ -132,7 +134,7 @@ export function ProfileEditorScreen({ navigation, route }: RootScreenProps<"Prof
}, [])
const minOf = (key: NumericKey) => (key === "interval" || key === "speed" ? 1 : 0)
- const unitOf = (key: NumericKey) => (key === "distance" ? distanceUnit : key === "speed" ? speedUnit : "s")
+ const unitOf = (key: NumericKey) => (key === "distance" ? distanceUnit : key === "speed" ? speedUnit : t("unit.s"))
const handleNumeric = (key: NumericKey, value: string) => {
setText((prev) => ({ ...prev, [key]: value }))
@@ -147,7 +149,7 @@ export function ProfileEditorScreen({ navigation, route }: RootScreenProps<"Prof
const num = parseWholeNumber(text[key])
if (num !== null && num >= min) return
setText((prev) => ({ ...prev, [key]: String(min) }))
- setNote({ key, text: `Set to ${min} ${unitOf(key)}` })
+ setNote({ key, text: t("validation.setTo", { value: min, unit: unitOf(key) }) })
noteTimer.set(() => setNote(null), SAVE_SUCCESS_DISPLAY_MS)
store(key, min)
}
@@ -155,7 +157,8 @@ export function ProfileEditorScreen({ navigation, route }: RootScreenProps<"Prof
const errorOf = (key: NumericKey) => wholeNumberError(text[key], minOf(key), unitOf(key))
const noteOf = (key: NumericKey) => (note?.key === key ? note.text : undefined)
- const priorityError = text.priority !== "" && parseWholeNumber(text.priority) === null ? "A whole number" : undefined
+ const priorityError =
+ text.priority !== "" && parseWholeNumber(text.priority) === null ? t("validation.wholeNumber") : undefined
const handlePriority = (value: string) => {
setText((prev) => ({ ...prev, priority: value }))
const num = parseWholeNumber(value)
@@ -197,9 +200,9 @@ export function ProfileEditorScreen({ navigation, route }: RootScreenProps<"Prof
const handleDelete = useCallback(async () => {
if (!profileId) return
const confirmed = await showConfirm({
- title: "Delete profile",
- message: `Delete "${profile.name || conditionLabel}"?`,
- confirmText: "Delete",
+ title: t("profileEditor.delete.title"),
+ message: t("profileEditor.delete.message", { name: profile.name || conditionLabel }),
+ confirmText: t("common.delete"),
destructive: true
})
if (!confirmed) return
@@ -208,9 +211,9 @@ export function ProfileEditorScreen({ navigation, route }: RootScreenProps<"Prof
navigation.goBack()
} catch (err) {
logger.error("[ProfileEditor] Delete failed:", err)
- showAlert("Error", "Failed to delete profile.", "error")
+ showAlert(t("common.error"), t("profileEditor.deleteFailed"), "error")
}
- }, [profileId, profile.name, conditionLabel, navigation])
+ }, [profileId, profile.name, conditionLabel, navigation, t])
const hasFieldError =
!!priorityError ||
@@ -232,11 +235,11 @@ export function ProfileEditorScreen({ navigation, route }: RootScreenProps<"Prof
navigation.goBack()
} catch (err) {
logger.error("[ProfileEditor] Save failed:", err)
- showAlert("Error", "Failed to save profile.", "error")
+ showAlert(t("common.error"), t("profileEditor.saveFailed"), "error")
} finally {
setSaving(false)
}
- }, [profile, conditionLabel, isEditing, profileId, navigation])
+ }, [profile, conditionLabel, isEditing, profileId, navigation, t])
const syncDefault = syncIntervalLabel(settings.syncInterval)
@@ -251,7 +254,7 @@ export function ProfileEditorScreen({ navigation, route }: RootScreenProps<"Prof
{profileSentence(profile, settings.isOfflineMode)}
</Text>
- <SectionTitle>Condition</SectionTitle>
+ <SectionTitle>{t("profileEditor.section.condition")}</SectionTitle>
<Card rows>
<View accessibilityRole="radiogroup" style={styles.group}>
{PROFILE_CONDITIONS.map((opt) => (
@@ -259,22 +262,25 @@ export function ProfileEditorScreen({ navigation, route }: RootScreenProps<"Prof
<RadioRow
testID={`condition-${opt.type}`}
icon={opt.icon}
- label={opt.label}
- sub={opt.description}
+ label={t(opt.labelKey)}
+ sub={t(opt.descriptionKey)}
selected={type === opt.type}
onPress={() => setConditionType(opt.type)}
/>
{isSpeedType(opt.type) && type === opt.type && (
<View style={styles.reveal}>
<NumericInput
- label="Speed"
+ label={t("profileEditor.speed")}
testID="speed-input"
value={text.speed}
onChange={(v) => handleNumeric("speed", v)}
onBlur={() => handleBlur("speed")}
unit={speedUnit}
placeholder={String(DEFAULT_SPEED_INPUT)}
- hint={`At least 1 ${speedUnit}. Applies while your average speed is ${opt.type === "speed_above" ? "above" : "below"} it.`}
+ hint={t(
+ opt.type === "speed_above" ? "profileEditor.speed.hintAbove" : "profileEditor.speed.hintBelow",
+ { unit: speedUnit }
+ )}
error={errorOf("speed")}
message={noteOf("speed")}
/>
@@ -285,25 +291,22 @@ export function ProfileEditorScreen({ navigation, route }: RootScreenProps<"Prof
</View>
</Card>
- <SectionTitle style={styles.groupTop}>Profile</SectionTitle>
+ <SectionTitle style={styles.groupTop}>{t("profileEditor.section.profile")}</SectionTitle>
<Card rows style={styles.cardTop}>
<View style={styles.field}>
<TextField
testID="name-input"
- label="Name"
+ label={t("profileEditor.name")}
placeholder={conditionLabel}
value={profile.name}
onChangeText={(val) => setProfile((prev) => ({ ...prev, name: val }))}
/>
- <FieldMessage>Shown on the Dashboard while active. Blank uses the condition&apos;s name.</FieldMessage>
+ <FieldMessage>{t("profileEditor.name.hint")}</FieldMessage>
</View>
<Divider tight />
- <SettingRow
- label="Priority"
- hint="Higher wins when two profiles match at once. Equal numbers go to the older profile."
- >
+ <SettingRow label={t("profileEditor.priority")} hint={t("profileEditor.priority.hint")}>
<TextField
- accessibilityLabel="Priority"
+ accessibilityLabel={t("profileEditor.priority")}
testID="priority-input"
figure
style={styles.numInput}
@@ -317,44 +320,45 @@ export function ProfileEditorScreen({ navigation, route }: RootScreenProps<"Prof
</SettingRow>
</Card>
- <SectionTitle style={styles.groupTop}>Tracking while active</SectionTitle>
+ <SectionTitle style={styles.groupTop}>{t("profileEditor.section.tracking")}</SectionTitle>
<Card rows style={styles.cardTop}>
<NumericInput
- label="Tracking interval"
+ label={t("profileEditor.interval")}
testID="interval-input"
value={text.interval}
onChange={(v) => handleNumeric("interval", v)}
onBlur={() => handleBlur("interval")}
- unit="s"
+ unit={t("unit.s")}
placeholder={String(settings.interval)}
- hint={`At least 1 s. Replaces the ${formatDuration(settings.interval)} from Tracking & sync while this profile is active. Shorter keeps the GPS awake more of the time and records more points.`}
+ hint={t("profileEditor.interval.hint", { duration: formatDuration(settings.interval) })}
error={errorOf("interval")}
message={noteOf("interval")}
/>
{isStationary && profile.interval > STATIONARY_MAX_INTERVAL_SECONDS && (
<FieldMessage variant="warning" style={styles.warning}>
- Longer than {STATIONARY_MAX_INTERVAL_SECONDS} s may leave the first {formatDuration(profile.interval)} of
- a trip unrecorded
+ {t("profileEditor.stationaryLong", {
+ max: STATIONARY_MAX_INTERVAL_SECONDS,
+ duration: formatDuration(profile.interval)
+ })}
</FieldMessage>
)}
{isStationary ? (
- <SettingRow
- disabled
- label="Movement threshold"
- hint="Not used while still · a point is recorded every interval"
- >
+ <SettingRow disabled label={t("trackingSync.distance")} hint={t("profileEditor.distance.stationary")}>
<Text style={[styles.figure, { color: colors.textDisabled }]}>0 {distanceUnit}</Text>
</SettingRow>
) : (
<NumericInput
- label="Movement threshold"
+ label={t("trackingSync.distance")}
testID="distance-input"
value={text.distance}
onChange={(v) => handleNumeric("distance", v)}
onBlur={() => handleBlur("distance")}
unit={distanceUnit}
placeholder={String(metersToInput(settings.distance))}
- hint={`At least 0 ${distanceUnit}. Replaces the ${metersToInput(settings.distance)} ${distanceUnit} from Tracking & sync. 0 records any movement, larger skips small drift.`}
+ hint={t("profileEditor.distance.hint", {
+ unit: distanceUnit,
+ distance: `${metersToInput(settings.distance)} ${distanceUnit}`
+ })}
error={errorOf("distance")}
message={noteOf("distance")}
/>
@@ -364,8 +368,8 @@ export function ProfileEditorScreen({ navigation, route }: RootScreenProps<"Prof
<Divider tight />
<View style={styles.pickerTop}>
<SyncIntervalPicker
- label="Sync interval"
- hint={`Replaces the ${syncDefault} from Tracking & sync while this profile is active · shorter means more wake-ups`}
+ label={t("syncInterval.field")}
+ hint={t("profileEditor.sync.hint", { interval: syncDefault })}
value={profile.syncInterval}
min={0}
pullUp={false}
@@ -378,34 +382,30 @@ export function ProfileEditorScreen({ navigation, route }: RootScreenProps<"Prof
)}
</Card>
- <SectionTitle style={styles.groupTop}>Switching</SectionTitle>
+ <SectionTitle style={styles.groupTop}>{t("profileEditor.section.switching")}</SectionTitle>
<Card rows style={styles.cardTop}>
<NumericInput
- label="Activation delay"
+ label={t("profileEditor.activation")}
testID="activation-delay-input"
value={text.activationDelay}
onChange={(v) => handleNumeric("activationDelay", v)}
onBlur={() => handleBlur("activationDelay")}
- unit="s"
+ unit={t("unit.s")}
placeholder={String(defaultProfileDelays(type).activationDelay)}
- hint={
- isStationary
- ? "How long every fix must read as still; 0 switches at the first still fix. Moving again ends the profile at once."
- : "How long the condition must hold first. 0 switches at once, longer ignores a brief plug or unplug."
- }
+ hint={isStationary ? t("profileEditor.activation.hintStationary") : t("profileEditor.activation.hint")}
error={errorOf("activationDelay")}
message={noteOf("activationDelay")}
/>
{!isStationary && (
<NumericInput
- label="Deactivation delay"
+ label={t("profileEditor.deactivation")}
testID="deactivation-delay-input"
value={text.deactivationDelay}
onChange={(v) => handleNumeric("deactivationDelay", v)}
onBlur={() => handleBlur("deactivationDelay")}
- unit="s"
+ unit={t("unit.s")}
placeholder={String(defaultProfileDelays(type).deactivationDelay)}
- hint="How long the profile stays on after its condition ends. Longer rides out a brief gap."
+ hint={t("profileEditor.deactivation.hint")}
error={errorOf("deactivationDelay")}
message={noteOf("deactivationDelay")}
/>
@@ -414,7 +414,7 @@ export function ProfileEditorScreen({ navigation, route }: RootScreenProps<"Prof
<Button
testID="save-profile-btn"
- title={isEditing ? "Save changes" : "Create profile"}
+ title={isEditing ? t("profileEditor.save") : t("profileEditor.create")}
icon={Check}
loading={saving}
disabled={hasFieldError}
@@ -424,7 +424,7 @@ export function ProfileEditorScreen({ navigation, route }: RootScreenProps<"Prof
{isEditing && (
<Button
testID="delete-profile-btn"
- title="Delete profile"
+ title={t("profileEditor.delete.title")}
icon={Trash2}
variant="danger"
onPress={handleDelete}
diff --git a/apps/mobile/src/screens/TrackingProfilesScreen.tsx b/apps/mobile/src/screens/TrackingProfilesScreen.tsx
index b28630ba..15814e7a 100644
--- a/apps/mobile/src/screens/TrackingProfilesScreen.tsx
+++ b/apps/mobile/src/screens/TrackingProfilesScreen.tsx
@@ -18,9 +18,11 @@ import { logger } from "../utils/logger"
import { buildProfilesLink } from "../utils/setupLink"
import { conditionOf, describeProfileState, profileRowSub } from "../utils/profileRow"
import { space } from "../constants"
+import { useTranslation } from "../i18n/useTranslation"
export function TrackingProfilesScreen({ navigation }: ScreenProps) {
const { colors } = useTheme()
+ const { t } = useTranslation()
const { settings, activeProfileId, tracking } = useTracking()
const activeProfile = useActiveProfile(activeProfileId)
const [profiles, setProfiles] = useState<SavedTrackingProfile[]>([])
@@ -45,10 +47,10 @@ export function TrackingProfilesScreen({ navigation }: ScreenProps) {
await ProfileService.updateProfile({ id, enabled })
await loadProfiles()
} catch {
- showAlert("Error", "Failed to update profile.", "error")
+ showAlert(t("common.error"), t("profiles.updateFailed"), "error")
}
},
- [loadProfiles]
+ [loadProfiles, t]
)
const handleShareProfiles = useCallback(async () => {
@@ -57,9 +59,9 @@ export function TrackingProfilesScreen({ navigation }: ScreenProps) {
await Share.share({ message: buildProfilesLink(profiles) })
} catch (err) {
logger.error("[TrackingProfilesScreen] Failed to share profiles:", err)
- showAlert("Error", "Failed to share profiles.", "error")
+ showAlert(t("common.error"), t("profiles.shareFailed"), "error")
}
- }, [profiles])
+ }, [profiles, t])
const openEditor = useCallback(
(profileId?: number) => navigation.navigate("Profile Editor", profileId === undefined ? {} : { profileId }),
@@ -73,15 +75,20 @@ export function TrackingProfilesScreen({ navigation }: ScreenProps) {
{hasProfiles && (
<HeaderAction
icon={Share2}
- label="Share all profiles"
+ label={t("profiles.share")}
onPress={handleShareProfiles}
testID="share-profiles-btn"
/>
)}
- <HeaderAction icon={Plus} label="Create profile" onPress={() => openEditor()} testID="add-profile-btn" />
+ <HeaderAction
+ icon={Plus}
+ label={t("profileEditor.create")}
+ onPress={() => openEditor()}
+ testID="add-profile-btn"
+ />
</View>
),
- [hasProfiles, handleShareProfiles, openEditor]
+ [hasProfiles, handleShareProfiles, openEditor, t]
)
useLayoutEffect(() => {
navigation.setOptions({ headerRight: renderHeaderActions })
@@ -94,10 +101,7 @@ export function TrackingProfilesScreen({ navigation }: ScreenProps) {
<ScrollView contentContainerStyle={styles.scrollContent} keyboardShouldPersistTaps="handled">
{hasProfiles ? (
<>
- <Text style={[styles.intro, { color: colors.textSecondary }]}>
- Checked top to bottom while tracking runs. The first profile whose condition holds replaces the Tracking &
- sync values.
- </Text>
+ <Text style={[styles.intro, { color: colors.textSecondary }]}>{t("profiles.intro")}</Text>
<Card rows>
<StateLine
icon={state.icon}
@@ -122,7 +126,7 @@ export function TrackingProfilesScreen({ navigation }: ScreenProps) {
onPress={() => openEditor(profile.id)}
trailing={
<Toggle
- accessibilityLabel={`Use ${profile.name}`}
+ accessibilityLabel={t("profiles.use", { name: profile.name })}
testID={`profile-toggle-${profile.id}`}
value={profile.enabled}
onValueChange={(enabled) => toggleEnabled(profile.id, enabled)}
@@ -137,9 +141,9 @@ export function TrackingProfilesScreen({ navigation }: ScreenProps) {
) : (
<EmptyState
icon={UserRoundPen}
- title="No profiles yet"
- hint="A profile changes how you track while a condition holds, such as charging or driving"
- action={{ label: "Create profile", onPress: () => openEditor() }}
+ title={t("profiles.empty.title")}
+ hint={t("profiles.empty.hint")}
+ action={{ label: t("profileEditor.create"), onPress: () => openEditor() }}
style={styles.empty}
/>
)}
diff --git a/apps/mobile/src/utils/__tests__/dashboardState.test.ts b/apps/mobile/src/utils/__tests__/dashboardState.test.ts
index 3c47f2a6..045e3ec4 100644
--- a/apps/mobile/src/utils/__tests__/dashboardState.test.ts
+++ b/apps/mobile/src/utils/__tests__/dashboardState.test.ts
@@ -5,6 +5,7 @@ import {
formatLastFix,
intervalText,
pickBannerCondition,
+ recordingPhrase,
recordingSummary,
syncIntervalLabel,
syncSummary,
@@ -250,6 +251,8 @@ describe("trackingSummary", () => {
it("exposes the two halves so a caption can carry one of them", () => {
expect(recordingSummary(5, 20)).toBe("Every 5 s after 20 m")
+ expect(recordingPhrase(5, 20)).toBe("every 5 s after 20 m")
+ expect(recordingPhrase(30, 0)).toBe("every 30 s, any movement")
expect(syncSummary(0)).toBe("syncs each fix")
expect(syncSummary(900)).toBe("syncs every 15 min")
expect(formatDuration(90)).toBe("90 s")
diff --git a/apps/mobile/src/utils/__tests__/profileRow.test.ts b/apps/mobile/src/utils/__tests__/profileRow.test.ts
index 890ba719..683a34e0 100644
--- a/apps/mobile/src/utils/__tests__/profileRow.test.ts
+++ b/apps/mobile/src/utils/__tests__/profileRow.test.ts
@@ -6,6 +6,7 @@ import {
profileStateLabel,
recordingClause
} from "../profileRow"
+import i18next from "i18next"
import { loadDisplayPreferences } from "../geo"
import type { SavedTrackingProfile } from "../../types/global"
@@ -78,6 +79,22 @@ describe("profileRowSub", () => {
)
})
+ it("takes the in-sentence form from its own key, so a language that capitalises nouns keeps them", async () => {
+ i18next.addResourceBundle("xx", "translation", {
+ "condition.charging.list": "Ladevorgang läuft",
+ "condition.charging.clause": "Ladevorgang läuft",
+ "profile.row.active": "Aktiv · {{condition}}"
+ })
+ await i18next.changeLanguage("xx")
+ try {
+ // Lower-casing the opener would give "ladevorgang läuft", which German does not allow.
+ expect(profileRowSub(commute, true, true)).toMatch(/^Aktiv · Ladevorgang läuft · /)
+ } finally {
+ await i18next.changeLanguage("en")
+ i18next.removeResourceBundle("xx", "translation")
+ }
+ })
+
it("says while still for a stationary profile, since its distance is forced to 0", () => {
expect(profileRowSub(resting, false, false)).toBe("When stationary · Every 1 min while still · syncs every 5 min")
expect(recordingClause(resting)).toBe("Every 1 min while still")
diff --git a/apps/mobile/src/utils/dashboardState.ts b/apps/mobile/src/utils/dashboardState.ts
index 6671a220..2571c7ab 100644
--- a/apps/mobile/src/utils/dashboardState.ts
+++ b/apps/mobile/src/utils/dashboardState.ts
@@ -128,6 +128,16 @@ export function recordingSummary(intervalSeconds: number, distanceMeters: number
})
}
+/** "every 30 s after 2 m": the recording clause inside a sentence, where it does not open it. */
+export function recordingPhrase(intervalSeconds: number, distanceMeters: number): string {
+ const duration = formatDuration(intervalSeconds)
+ if (distanceMeters === 0) return t("tracking.phrase.anyMovement", { duration })
+ return t("tracking.phrase.after", {
+ duration,
+ distance: `${metersToInput(distanceMeters)} ${shortDistanceUnit()}`
+ })
+}
+
/** "syncs each fix" or "syncs every 5 min", lower case so a caption can carry it. */
export function syncSummary(syncIntervalSeconds: number): string {
return syncIntervalSeconds === 0
diff --git a/apps/mobile/src/utils/profileRow.ts b/apps/mobile/src/utils/profileRow.ts
index 8ff7065e..84112d9d 100644
--- a/apps/mobile/src/utils/profileRow.ts
+++ b/apps/mobile/src/utils/profileRow.ts
@@ -6,58 +6,76 @@
import { UserRoundPen, type LucideIcon } from "lucide-react-native"
import { PROFILE_CONDITIONS } from "../constants"
import type { SavedTrackingProfile, Settings, TrackingProfile } from "../types/global"
-import { formatInterval, recordingSummary, syncSummary, trackingSummary } from "./dashboardState"
+import {
+ formatDuration,
+ recordingPhrase as settingsRecordingPhrase,
+ recordingSummary,
+ syncSummary
+} from "./dashboardState"
+import { t } from "../i18n/t"
import { getSpeedUnit, speedToInput } from "./geo"
type ProfileLike = Pick<TrackingProfile, "condition" | "interval" | "distance" | "syncInterval">
-const lowerFirst = (text: string) => text.charAt(0).toLowerCase() + text.slice(1)
-
export function conditionOf(profile: Pick<TrackingProfile, "condition">) {
return PROFILE_CONDITIONS.find((c) => c.type === profile.condition.type) ?? PROFILE_CONDITIONS[0]
}
+const speedOf = (profile: Pick<TrackingProfile, "condition">) =>
+ `${speedToInput(profile.condition.speedThreshold ?? 0)} ${getSpeedUnit().unit}`
+
/** "When charging", "Speed above 50 km/h": the clause a row and the editor's sentence open with. */
export function conditionText(profile: Pick<TrackingProfile, "condition">): string {
- const { type, speedThreshold } = profile.condition
- if (type === "speed_above" || type === "speed_below") {
- return `${conditionOf(profile).listLabel} ${speedToInput(speedThreshold ?? 0)} ${getSpeedUnit().unit}`
- }
- return conditionOf(profile).listLabel
+ return t(conditionOf(profile).listKey, { speed: speedOf(profile) })
}
/** The recording half; a stationary profile forces the distance to 0, so "any movement" would mislead. */
export function recordingClause(profile: ProfileLike): string {
- if (profile.condition.type === "stationary") return `${formatInterval(profile.interval)} while still`
+ if (profile.condition.type === "stationary") {
+ return t("tracking.recording.whileStill", { duration: formatDuration(profile.interval) })
+ }
return recordingSummary(profile.interval, profile.distance)
}
+/** `recordingClause` inside a sentence: "every 5 s while still". */
+export function recordingPhrase(profile: ProfileLike): string {
+ if (profile.condition.type === "stationary") {
+ return t("tracking.phrase.whileStill", { duration: formatDuration(profile.interval) })
+ }
+ return settingsRecordingPhrase(profile.interval, profile.distance)
+}
+
/** The one line under a profile's name: [Active · ]condition · recording · sync. */
export function profileRowSub(profile: ProfileLike, inForce: boolean, isOfflineMode: boolean): string {
- const condition = conditionText(profile)
- const parts = [inForce ? `Active · ${lowerFirst(condition)}` : condition, recordingClause(profile)]
+ const condition = inForce
+ ? t("profile.row.active", { condition: t(conditionOf(profile).clauseKey, { speed: speedOf(profile) }) })
+ : conditionText(profile)
+ const parts = [condition, recordingClause(profile)]
if (!isOfflineMode) parts.push(syncSummary(profile.syncInterval))
return parts.join(" · ")
}
/** The rule as one sentence, the editor's caption: "When charging, track every 5 s, any movement and sync each fix." */
export function profileSentence(profile: ProfileLike, isOfflineMode: boolean): string {
- const { type, speedThreshold } = profile.condition
- const unit = getSpeedUnit().unit
+ const { type } = profile.condition
const when =
type === "speed_above"
- ? `When faster than ${speedToInput(speedThreshold ?? 0)} ${unit}`
+ ? t("profile.when.faster", { speed: speedOf(profile) })
: type === "speed_below"
- ? `When slower than ${speedToInput(speedThreshold ?? 0)} ${unit}`
+ ? t("profile.when.slower", { speed: speedOf(profile) })
: conditionText(profile)
- const track = `track ${lowerFirst(recordingClause(profile))}`
- if (isOfflineMode) return `${when}, ${track}.`
- return `${when}, ${track} and ${syncSummary(profile.syncInterval).replace(/^syncs/, "sync")}.`
+ const recording = recordingPhrase(profile)
+ if (isOfflineMode) return t("profile.sentence.offline", { when, recording })
+ const sync =
+ profile.syncInterval === 0
+ ? t("tracking.syncVerb.eachFix")
+ : t("tracking.syncVerb.every", { duration: formatDuration(profile.syncInterval) })
+ return t("profile.sentence", { when, recording, sync })
}
/** "Charging is active" or "No profile active": the Profiles state line and the Settings row print one string. */
export function profileStateLabel(activeName: string | null | undefined, tracking: boolean): string {
- return tracking && activeName ? `${activeName} is active` : "No profile active"
+ return tracking && activeName ? t("trackingSync.profileActive", { name: activeName }) : t("profile.noneActive")
}
export interface ProfileState {
@@ -78,7 +96,7 @@ export function describeProfileState(
icon: UserRoundPen,
tone: "secondary",
label: profileStateLabel(null, false),
- caption: "Profiles apply while tracking runs"
+ caption: t("profile.state.notTracking")
}
}
if (activeProfile) {
@@ -87,13 +105,16 @@ export function describeProfileState(
icon: conditionOf(activeProfile).icon,
tone: "success",
label: profileStateLabel(activeProfile.name, true),
- caption: `In force: ${lowerFirst(recordingClause(activeProfile))}${sync}`
+ caption: t("trackingSync.inForce", { clause: `${recordingPhrase(activeProfile)}${sync}` })
}
}
+ const sync = settings.isOfflineMode ? "" : ` · ${syncSummary(settings.syncInterval)}`
return {
icon: UserRoundPen,
tone: "secondary",
label: profileStateLabel(null, true),
- caption: `Tracking & sync applies: ${lowerFirst(trackingSummary(settings.interval, settings.distance, settings.syncInterval, settings.isOfflineMode))}`
+ caption: t("profile.state.settingsApply", {
+ summary: `${settingsRecordingPhrase(settings.interval, settings.distance)}${sync}`
+ })
}
}