Colota - Android GPS Location tracker
refactor(i18n): move Authentication and mTLS into the catalog (#903)
Max Dietrich13b7c9857331
diff --git a/apps/mobile/src/components/features/settings/MtlsSection.tsx b/apps/mobile/src/components/features/settings/MtlsSection.tsxindex 34d15b4e..5e4bd925 100644--- a/apps/mobile/src/components/features/settings/MtlsSection.tsx+++ b/apps/mobile/src/components/features/settings/MtlsSection.tsx@@ -22,31 +22,31 @@ import { ClientCertInfoResult } from "../../../types/global"import { describeCertificate, type CertificateState } from "../../../utils/certificateState"import { logger } from "../../../utils/logger"import { space } from "../../../constants"+import { t } from "../../../i18n/t"+import { useTranslation } from "../../../i18n/useTranslation"+import type { TranslationKey } from "../../../i18n/options"-const CLIENT_CERT_ERR: Record<string, string> = {- E_CERT_PASSWORD: "Incorrect password",- E_CERT_INVALID: "Not a valid PKCS12 file"+const CLIENT_CERT_ERR: Record<string, TranslationKey> = {+ E_CERT_PASSWORD: "mtls.err.password",+ E_CERT_INVALID: "mtls.err.invalid"}-const SERVER_CA_ERR: Record<string, string> = {- E_CA_READ: "Could not read the selected file. Try a smaller file or pick again.",- E_CA_INVALID: "Not a valid X.509 certificate. Make sure you're picking the CA cert (PEM or DER)."+const SERVER_CA_ERR: Record<string, TranslationKey> = {+ E_CA_READ: "mtls.err.caRead",+ E_CA_INVALID: "mtls.err.caInvalid"}-function errMsg(map: Record<string, string>, err: any, fallback: string): string {- return map[err?.code] ?? err?.message ?? fallback+function errMsg(map: Record<string, TranslationKey>, err: any, fallback: TranslationKey): string {+ const key = map[err?.code]+ return key ? t(key) : (err?.message ?? t(fallback))}type ImportState ={ kind: "idle" } | { kind: "picked"; b64: string; password: string; importing: boolean; error: string | null }-const PICK_LINE = "Key stays in the device's credential store, survives a reinstall, never backed up."-const IMPORT_LINE = "Key moves into the Android Keystore and the file password is discarded. Not backed up."-// Android reports an empty picker and a cancelled one the same way, so the line covers both.-const NO_PICK_LINE =- "No certificate was picked. If the list was empty, install one in Android settings under Encryption & credentials first."-export function MtlsSection() {const { colors } = useTheme()+ // Subscribes to language changes; the strings below come from the non-hook t().+ useTranslation()const [certInfo, setCertInfo] = useState<ClientCertInfoResult | null>(null)const [caInfo, setCaInfo] = useState<ClientCertInfoResult | null>(null)const [importState, setImportState] = useState<ImportState>({ kind: "idle" })@@ -82,15 +82,15 @@ export function MtlsSection() {await refresh()} catch (err: any) {logger.error("[MtlsSection] importServerCa failed:", err)- setCaError(errMsg(SERVER_CA_ERR, err, "Could not import the CA"))+ setCaError(errMsg(SERVER_CA_ERR, err, "mtls.err.caImport"))}}, [refresh])const handleClearServerCa = useCallback(async () => {const confirmed = await showConfirm({- title: "Remove trusted CA?",- message: "Connections to a server signed by it will fail until you import it again.",- confirmText: "Remove",+ title: t("mtls.removeCa.title"),+ message: t("mtls.removeCa.message"),+ confirmText: t("common.remove"),destructive: true})if (!confirmed) return@@ -108,13 +108,14 @@ export function MtlsSection() {try {const result = await NativeLocationService.pickKeyChainCert()if (!result) {- setPickNote(NO_PICK_LINE)+ // Android reports an empty picker and a cancelled one the same way, so the line covers both.+ setPickNote(t("mtls.noPick"))return}await refresh()} catch (err: any) {logger.error("[MtlsSection] pickKeyChainCert failed:", err)- setClientPickError(err?.message || "Could not read the selected certificate")+ setClientPickError(err?.message || t("mtls.err.readCert"))}}, [refresh])@@ -127,7 +128,7 @@ export function MtlsSection() {setImportState({ kind: "picked", b64, password: "", importing: false, error: null })} catch (err: any) {logger.error("[MtlsSection] pick failed:", err)- setClientPickError(err?.message || "Could not read the selected file")+ setClientPickError(err?.message || t("mtls.err.readFile"))}}, [])@@ -139,18 +140,18 @@ export function MtlsSection() {setImportState({ kind: "idle" })await refresh()} catch (err: any) {- setImportState({ ...importState, importing: false, error: errMsg(CLIENT_CERT_ERR, err, "Import failed") })+ setImportState({ ...importState, importing: false, error: errMsg(CLIENT_CERT_ERR, err, "mtls.err.importFailed") })}}, [importState, refresh])const handleReplace = useCallback(async () => {const choice = await showChoice({- title: "Replace certificate",- message: "The current certificate is replaced as soon as the new one is read.",+ title: t("mtls.replace.title"),+ message: t("mtls.replace.message"),buttons: [- { text: "Pick from device", style: "primary" },- { text: "Import .p12", style: "secondary" },- { text: "Cancel", style: "secondary" }+ { text: t("mtls.replace.pick"), style: "primary" },+ { text: t("mtls.replace.import"), style: "secondary" },+ { text: t("common.cancel"), style: "secondary" }]})if (choice === 0) handlePickKeyChain()@@ -159,9 +160,9 @@ export function MtlsSection() {const handleRemove = useCallback(async () => {const confirmed = await showConfirm({- title: "Remove client certificate?",- message: "Requests to a server that requires it will fail until you add one again.",- confirmText: "Remove",+ title: t("mtls.remove.title"),+ message: t("mtls.remove.message"),+ confirmText: t("common.remove"),destructive: true})if (!confirmed) return@@ -183,34 +184,35 @@ export function MtlsSection() {return (<>- <SectionTitle>Client certificate</SectionTitle>+ <SectionTitle>{t("mtls.section.client")}</SectionTitle><Card rows>{importState.kind === "picked" ? (<View style={styles.block}><View><TextField- label="File password"+ label={t("mtls.password")}testID="p12-password"value={importState.password}onChangeText={(v) => setImportState({ ...importState, password: v, error: null })}- placeholder="Leave empty if the file has none"+ placeholder={t("mtls.password.placeholder")}autoCapitalize="none"autoCorrect={false}securedisabled={importState.importing}error={importState.error ?? undefined}/>- {!importState.error && (- <FieldMessage>- Used once to unwrap the key, then discarded. Leave empty if the file has none.- </FieldMessage>- )}+ {!importState.error && <FieldMessage>{t("mtls.password.hint")}</FieldMessage>}</View><View style={styles.buttonRow}>- <Button style={styles.flex1} onPress={handleImport} title="Import" loading={importState.importing} />+ <Button+ style={styles.flex1}+ onPress={handleImport}+ title={t("mtls.import")}+ loading={importState.importing}+ /><Buttonvariant="ghost"- title="Cancel"+ title={t("common.cancel")}onPress={() => setImportState({ kind: "idle" })}disabled={importState.importing}/>@@ -230,18 +232,18 @@ export function MtlsSection() {<StateLineicon={ShieldCheck}iconColor={colors.textSecondary}- label="None"- caption="Only for a server that asks for one"+ label={t("mtls.none")}+ caption={t("mtls.client.none.caption")}testID="certificate-state"/><Divider tight /><ListItemtestID="pick-keychain-row"icon={KeyRound}- label="Pick from device certificates"- sub={PICK_LINE}+ label={t("mtls.pick")}+ sub={t("mtls.pick.sub")}subLines={2}- accessibilityHint="Opens the system certificate picker"+ accessibilityHint={t("mtls.pick.hint")}onPress={handlePickKeyChain}/><Divider tight inset />@@ -249,10 +251,10 @@ export function MtlsSection() {testID="import-p12-row"icon={FileKey}trailingIcon={Download}- label="Import .p12 / .pfx"- sub={IMPORT_LINE}+ label={t("mtls.importP12")}+ sub={t("mtls.import.sub")}subLines={2}- accessibilityHint="Opens the file picker"+ accessibilityHint={t("mtls.filePicker.hint")}onPress={handlePickFile}/>{clientPickError ? (@@ -268,24 +270,24 @@ export function MtlsSection() {)}</Card>- <SectionTitle style={styles.groupTop}>Trusted server CA</SectionTitle>+ <SectionTitle style={styles.groupTop}>{t("mtls.section.ca")}</SectionTitle><Card rows>{caInfo.configured ? (<CertificateCard- state={describeCertificate(caInfo, undefined, "server certificate checks will fail")}+ state={describeCertificate(caInfo, undefined, "cert.failure.ca")}subject={caInfo.subject}onReplace={handlePickServerCa}onRemove={handleClearServerCa}removeTestID="remove-ca-btn"- note="Encrypted on this device and included in encrypted backups."+ note={t("mtls.ca.note")}/>) : (<><StateLineicon={ShieldCheck}iconColor={colors.textSecondary}- label="None"- caption="Not needed for a public certificate"+ label={t("mtls.none")}+ caption={t("mtls.ca.none.caption")}testID="ca-state"/><Divider tight />@@ -293,10 +295,10 @@ export function MtlsSection() {testID="import-ca-row"icon={FileKey}trailingIcon={Download}- label="Import CA (.crt / .pem)"- sub="For a private or self-signed CA. CAs you installed in Android settings are not used."+ label={t("mtls.importCa")}+ sub={t("mtls.importCa.sub")}subLines={2}- accessibilityHint="Opens the file picker"+ accessibilityHint={t("mtls.filePicker.hint")}onPress={handlePickServerCa}/>{caError ? (@@ -356,12 +358,18 @@ function CertificateCard({/><Divider tight /><View style={styles.details}>- {subject ? <StatRow label="Subject" value={shortenDn(subject)} /> : null}- {issuer ? <StatRow label="Issuer" value={shortenDn(issuer)} /> : null}+ {subject ? <StatRow label={t("mtls.subject")} value={shortenDn(subject)} /> : null}+ {issuer ? <StatRow label={t("mtls.issuer")} value={shortenDn(issuer)} /> : null}{note ? <FieldMessage>{note}</FieldMessage> : null}<View style={styles.buttonRow}>- <Button style={styles.flex1} variant="ghost" title="Replace" onPress={onReplace} />- <Button style={styles.flex1} variant="danger" title="Remove" onPress={onRemove} testID={removeTestID} />+ <Button style={styles.flex1} variant="ghost" title={t("common.replace")} onPress={onReplace} />+ <Button+ style={styles.flex1}+ variant="danger"+ title={t("common.remove")}+ onPress={onRemove}+ testID={removeTestID}+ /></View></View></>diff --git a/apps/mobile/src/components/features/settings/__tests__/MtlsSection.test.tsx b/apps/mobile/src/components/features/settings/__tests__/MtlsSection.test.tsxindex 044b5089..2ca1602e 100644--- a/apps/mobile/src/components/features/settings/__tests__/MtlsSection.test.tsx+++ b/apps/mobile/src/components/features/settings/__tests__/MtlsSection.test.tsx@@ -174,6 +174,29 @@ describe("MtlsSection", () => {expect(getByText("File password")).toBeTruthy()})+ it.each([+ [+ "a known code, which beats the bridge's own sentence",+ { code: "E_CERT_INVALID", message: "raw" },+ "Not a valid PKCS12 file"+ ],+ [+ "the bridge's sentence for an unknown code",+ { code: "E_OTHER", message: "Keystore is locked" },+ "Keystore is locked"+ ],+ ["the fallback when the bridge says nothing", {}, "Import failed"]+ ])("words a failed import with %s", async (_, error, shown) => {+ mockPickClientCertFile.mockResolvedValueOnce("BASE64")+ mockImportClientCert.mockRejectedValueOnce(error)+ const { findByText } = render(<MtlsSection />)++ fireEvent.press(await findByText("Import .p12 / .pfx"))+ fireEvent.press(await findByText("Import"))++ expect(await findByText(shown)).toBeTruthy()+ })+it("Cancel returns to the empty state", async () => {mockPickClientCertFile.mockResolvedValueOnce("BASE64")const { findByText, queryByText } = render(<MtlsSection />)@@ -260,6 +283,20 @@ describe("MtlsSection", () => {expect(await findByText(/^Not a valid X\.509 certificate/)).toBeTruthy()})+ it.each([+ ["a known code", { code: "E_CA_READ" }, "Could not read the selected file. Try a smaller file or pick again."],+ ["the bridge's sentence for an unknown code", { code: "E_OTHER", message: "Disk full" }, "Disk full"],+ ["the fallback when the bridge says nothing", {}, "Could not import the CA"]+ ])("words a failed CA import with %s", async (_, error, shown) => {+ mockPickServerCaFile.mockResolvedValueOnce("BASE64")+ mockImportServerCa.mockRejectedValueOnce(error)+ const { findByText } = render(<MtlsSection />)++ fireEvent.press(await findByText("Import CA (.crt / .pem)"))++ expect(await findByText(shown)).toBeTruthy()+ })+it("reads Valid when loaded and removes only after the confirm", async () => {mockGetServerCaInfo.mockResolvedValue(loaded(900))const { findByTestId, getByText } = render(<MtlsSection />)diff --git a/apps/mobile/src/i18n/locales/en.json b/apps/mobile/src/i18n/locales/en.jsonindex 57516cbc..fd7157bd 100644--- a/apps/mobile/src/i18n/locales/en.json+++ b/apps/mobile/src/i18n/locales/en.json@@ -252,5 +252,79 @@"requestFormat.duplicates": "Duplicate field names: {{names}}. Resolve duplicates to save changes.","requestFormat.copy": "Copy","requestFormat.copied": "Copied!",- "requestFormat.footer": "Changes apply to new location data immediately"+ "requestFormat.footer": "Changes apply to new location data immediately",+ "cert.notSet": "Not set",+ "cert.unreadable": "Cannot be read",+ "cert.missingFields": "Missing certificate fields",+ "cert.expired": "Expired",+ "cert.expiredOn": "Expired {{date}} · {{consequence}}",+ "cert.failure.client": "the server will refuse it",+ "cert.failure.ca": "server certificate checks will fail",+ "cert.until": "Until {{date}}",+ "cert.source.keychain": "device credential store",+ "cert.source.p12": "imported .p12",+ "cert.expiresIn_one": "Expires in {{n}} day",+ "cert.expiresIn_other": "Expires in {{n}} days",+ "cert.valid": "Valid",+ "cert.validUntil": "Valid until {{date}}",+ "auth.section.method": "Method",+ "auth.section.headers": "Custom headers",+ "auth.none.sub": "No Authorization header",+ "auth.basic.sub": "Username and password, only safe over https",+ "auth.bearer.sub": "An API token or JWT",+ "auth.secretSet": "Saved encrypted. Type to replace.",+ "auth.secretUnset": "Not set",+ "auth.removedOnSwitch": "Choosing another method removes these credentials.",+ "auth.headersHint": "Sent with every request, like CF-Access-Client-Id for Cloudflare Access.",+ "auth.duplicateHeader": "Also used above. Only the last value is sent.",+ "auth.username": "Username",+ "auth.password": "Password",+ "auth.token": "Token",+ "auth.token.placeholder": "Paste the token",+ "auth.header.nameLabel": "Header name",+ "auth.header.namePlaceholder": "Name",+ "auth.header.valueLabel": "Header value",+ "auth.header.valuePlaceholder": "Value",+ "auth.header.remove": "Remove header {{name}}",+ "auth.header.removeUnnamed": "Remove header",+ "auth.header.add": "+ Add header",+ "mtls.section.client": "Client certificate",+ "mtls.section.ca": "Trusted server CA",+ "mtls.err.password": "Incorrect password",+ "mtls.err.invalid": "Not a valid PKCS12 file",+ "mtls.err.caRead": "Could not read the selected file. Try a smaller file or pick again.",+ "mtls.err.caInvalid": "Not a valid X.509 certificate. Make sure you're picking the CA cert (PEM or DER).",+ "mtls.err.importFailed": "Import failed",+ "mtls.err.caImport": "Could not import the CA",+ "mtls.err.readCert": "Could not read the selected certificate",+ "mtls.err.readFile": "Could not read the selected file",+ "mtls.pick.sub": "Key stays in the device's credential store, survives a reinstall, never backed up.",+ "mtls.import.sub": "Key moves into the Android Keystore and the file password is discarded. Not backed up.",+ "mtls.noPick": "No certificate was picked. If the list was empty, install one in Android settings under Encryption & credentials first.",+ "mtls.removeCa.title": "Remove trusted CA?",+ "mtls.removeCa.message": "Connections to a server signed by it will fail until you import it again.",+ "mtls.replace.title": "Replace certificate",+ "mtls.replace.message": "The current certificate is replaced as soon as the new one is read.",+ "mtls.replace.pick": "Pick from device",+ "mtls.replace.import": "Import .p12",+ "mtls.remove.title": "Remove client certificate?",+ "mtls.remove.message": "Requests to a server that requires it will fail until you add one again.",+ "common.remove": "Remove",+ "common.replace": "Replace",+ "mtls.password": "File password",+ "mtls.password.placeholder": "Leave empty if the file has none",+ "mtls.password.hint": "Used once to unwrap the key, then discarded. Leave empty if the file has none.",+ "mtls.import": "Import",+ "mtls.none": "None",+ "mtls.client.none.caption": "Only for a server that asks for one",+ "mtls.ca.none.caption": "Not needed for a public certificate",+ "mtls.pick": "Pick from device certificates",+ "mtls.pick.hint": "Opens the system certificate picker",+ "mtls.importP12": "Import .p12 / .pfx",+ "mtls.filePicker.hint": "Opens the file picker",+ "mtls.importCa": "Import CA (.crt / .pem)",+ "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"}diff --git a/apps/mobile/src/screens/AuthSettingsScreen.tsx b/apps/mobile/src/screens/AuthSettingsScreen.tsxindex 2d7ea5af..411953a4 100644--- a/apps/mobile/src/screens/AuthSettingsScreen.tsx+++ b/apps/mobile/src/screens/AuthSettingsScreen.tsx@@ -25,18 +25,15 @@ import {import NativeLocationService from "../services/NativeLocationService"import { logger } from "../utils/logger"import { size, space } from "../constants"+import { useTranslation } from "../i18n/useTranslation"+import type { TranslationKey } from "../i18n/options"-const METHODS: { value: AuthType; label: string; sub: string }[] = [- { value: "none", label: "None", sub: "No Authorization header" },- { value: "basic", label: "Basic auth", sub: "Username and password, only safe over https" },- { value: "bearer", label: "Bearer token", sub: "An API token or JWT" }+const METHODS: { value: AuthType; labelKey: TranslationKey; subKey: TranslationKey }[] = [+ { value: "none", labelKey: "auth.none", subKey: "auth.none.sub" },+ { value: "basic", labelKey: "auth.basic", subKey: "auth.basic.sub" },+ { value: "bearer", labelKey: "auth.bearer", subKey: "auth.bearer.sub" }]-const SECRET_SET = "Saved encrypted. Type to replace."-const SECRET_UNSET = "Not set"-const REMOVED_ON_SWITCH = "Choosing another method removes these credentials."-const HEADERS_HINT = "Sent with every request, like CF-Access-Client-Id for Cloudflare Access."-const DUPLICATE_HEADER = "Also used above. Only the last value is sent."const SENSITIVE_HEADER = /authorization|cookie|token|key|secret/itype LocalHeader = { key: string; value: string; id: number }@@ -54,6 +51,7 @@ export function withMethod(config: AuthConfig, authType: AuthType): AuthConfig {export function AuthSettingsScreen({}: ScreenProps) {const { colors } = useTheme()+ const { t } = useTranslation()const { restartTracking, settings } = useTracking()const [config, setConfig] = useState<AuthConfig>(DEFAULT_AUTH_CONFIG)@@ -163,7 +161,7 @@ export function AuthSettingsScreen({}: ScreenProps) {)}- const secretHint = (stored: string) => (stored !== "" ? SECRET_SET : SECRET_UNSET)+ const secretHint = (stored: string) => (stored !== "" ? t("auth.secretSet") : t("auth.secretUnset"))const holdsCredentials =(config.authType === "basic" && (config.username !== "" || config.password !== "")) ||(config.authType === "bearer" && config.bearerToken !== "")@@ -175,37 +173,37 @@ export function AuthSettingsScreen({}: ScreenProps) {keyboardShouldPersistTaps="handled"showsVerticalScrollIndicator={false}>- <SectionTitle>Method</SectionTitle>+ <SectionTitle>{t("auth.section.method")}</SectionTitle><Card rows><View accessibilityRole="radiogroup" style={styles.group}>- {METHODS.map(({ value, label, sub }) => (+ {METHODS.map(({ value, labelKey, subKey }) => (<React.Fragment key={value}><RadioRowtestID={`auth-${value}`}- label={label}- sub={sub}+ label={t(labelKey)}+ sub={t(subKey)}selected={config.authType === value}onPress={() => handleMethod(value)}/>{value === "basic" && config.authType === "basic" && (<View style={styles.reveal}><TextField- label="Username"+ label={t("auth.username")}testID="basic-username"value={config.username}onChangeText={(v) => saveSoon({ username: v })}- placeholder="Username"+ placeholder={t("auth.username")}autoCapitalize="none"autoCorrect={false}autoComplete="username"/><View><TextField- label="Password"+ label={t("auth.password")}testID="basic-password"value={passwordDraft}onChangeText={(v) => handleSecret("password", v)}- placeholder="Password"+ placeholder={t("auth.password")}autoCapitalize="none"autoCorrect={false}autoComplete="password"@@ -219,12 +217,12 @@ export function AuthSettingsScreen({}: ScreenProps) {<View style={styles.reveal}><View><TextField- label="Token"+ label={t("auth.token")}testID="bearer-token"monovalue={tokenDraft}onChangeText={(v) => handleSecret("bearerToken", v)}- placeholder="Paste the token"+ placeholder={t("auth.token.placeholder")}autoCapitalize="none"autoCorrect={false}autoComplete="off"@@ -242,13 +240,13 @@ export function AuthSettingsScreen({}: ScreenProps) {<><Divider tight /><View style={styles.footer}>- <FieldMessage>{REMOVED_ON_SWITCH}</FieldMessage>+ <FieldMessage>{t("auth.removedOnSwitch")}</FieldMessage></View></>)}</Card>- <SectionTitle style={styles.groupTop}>Custom headers</SectionTitle>+ <SectionTitle style={styles.groupTop}>{t("auth.section.headers")}</SectionTitle><Card rows>{localHeaders.map((header, index) => {const name = header.key.trim()@@ -259,22 +257,22 @@ export function AuthSettingsScreen({}: ScreenProps) {<View style={styles.headerRow}><View style={styles.headerInputs}><TextField- accessibilityLabel="Header name"+ accessibilityLabel={t("auth.header.nameLabel")}testID={`header-key-${header.id}`}mono- error={isDuplicate ? DUPLICATE_HEADER : undefined}+ error={isDuplicate ? t("auth.duplicateHeader") : undefined}value={header.key}onChangeText={(v) => updateHeaderField(header.id, "key", v)}- placeholder="Name"+ placeholder={t("auth.header.namePlaceholder")}autoCapitalize="none"autoCorrect={false}/><TextField- accessibilityLabel="Header value"+ accessibilityLabel={t("auth.header.valueLabel")}testID={`header-value-${header.id}`}value={header.value}onChangeText={(v) => updateHeaderField(header.id, "value", v)}- placeholder="Value"+ placeholder={t("auth.header.valuePlaceholder")}autoCapitalize="none"autoCorrect={false}secure={SENSITIVE_HEADER.test(name)}@@ -284,7 +282,7 @@ export function AuthSettingsScreen({}: ScreenProps) {icon={X}tone="danger"testID={`remove-header-${header.id}`}- accessibilityLabel={name ? `Remove header ${name}` : "Remove header"}+ accessibilityLabel={name ? t("auth.header.remove", { name }) : t("auth.header.removeUnnamed")}onPress={() => removeHeader(header.id)}/></View>@@ -293,8 +291,8 @@ export function AuthSettingsScreen({}: ScreenProps) {})}{localHeaders.length > 0 && <Divider tight />}<View style={[styles.footer, localHeaders.length === 0 && styles.footerFirst]}>- <Button title="+ Add header" onPress={addHeader} variant="secondary" testID="add-header-btn" />- {localHeaders.length === 0 && <FieldMessage>{HEADERS_HINT}</FieldMessage>}+ <Button title={t("auth.header.add")} onPress={addHeader} variant="secondary" testID="add-header-btn" />+ {localHeaders.length === 0 && <FieldMessage>{t("auth.headersHint")}</FieldMessage>}</View></Card></ScrollView>diff --git a/apps/mobile/src/utils/__tests__/certificateState.test.ts b/apps/mobile/src/utils/__tests__/certificateState.test.tsindex 5a8aadd2..28a1eac9 100644--- a/apps/mobile/src/utils/__tests__/certificateState.test.ts+++ b/apps/mobile/src/utils/__tests__/certificateState.test.ts@@ -57,7 +57,7 @@ describe("describeCertificate", () => {const s = describeCertificate(cert(-3), NOW)expect(s.word).toBe("Expired")expect(s.caption).toMatch(/^Expired .* · the server will refuse it$/)- expect(describeCertificate(cert(-3), NOW, "server certificate checks will fail").caption).toMatch(+ expect(describeCertificate(cert(-3), NOW, "cert.failure.ca").caption).toMatch(/server certificate checks will fail$/)})diff --git a/apps/mobile/src/utils/certificateState.ts b/apps/mobile/src/utils/certificateState.tsindex b2215355..f0f76d92 100644--- a/apps/mobile/src/utils/certificateState.ts+++ b/apps/mobile/src/utils/certificateState.ts@@ -6,6 +6,8 @@import { CERT_EXPIRY_WARNING_DAYS } from "../constants"import type { ClientCertInfoResult } from "../types/global"import { formatDateWithYear } from "./geo"+import { t } from "../i18n/t"+import type { TranslationKey } from "../i18n/options"export type CertificateStateKind = "none" | "valid" | "expiring" | "expired" | "unreadable"@@ -22,8 +24,8 @@ export interface CertificateState {const DAY_MS = 24 * 60 * 60 * 1000function source(info: { source?: "keychain" | "p12" }): string {- if (info.source === "keychain") return " · device credential store"- if (info.source === "p12") return " · imported .p12"+ if (info.source === "keychain") return ` · ${t("cert.source.keychain")}`+ if (info.source === "p12") return ` · ${t("cert.source.p12")}`return ""}@@ -31,12 +33,14 @@ function source(info: { source?: "keychain" | "p12" }): string {export function describeCertificate(info: ClientCertInfoResult | null,now: Date = new Date(),- failureCaption = "the server will refuse it"+ failureKey: TranslationKey = "cert.failure.client"): CertificateState {- if (!info || !info.configured) return { state: "none", days: 0, word: "Not set", caption: "", rowSub: "Not set" }+ if (!info || !info.configured) {+ return { state: "none", days: 0, word: t("cert.notSet"), caption: "", rowSub: t("cert.notSet") }+ }if (info.error || !info.notAfter || !info.subject) {- const caption = info.error ?? "Missing certificate fields"- return { state: "unreadable", days: 0, word: "Cannot be read", caption, rowSub: "Cannot be read" }+ const caption = info.error ?? t("cert.missingFields")+ return { state: "unreadable", days: 0, word: t("cert.unreadable"), caption, rowSub: t("cert.unreadable") }}const days = Math.floor((info.notAfter - now.getTime()) / DAY_MS)const until = formatDateWithYear(Math.floor(info.notAfter / 1000))@@ -44,15 +48,15 @@ export function describeCertificate(return {state: "expired",days,- word: "Expired",- caption: `Expired ${until} · ${failureCaption}`,- rowSub: "Expired"+ word: t("cert.expired"),+ caption: t("cert.expiredOn", { date: until, consequence: t(failureKey) }),+ rowSub: t("cert.expired")}}- const caption = `Until ${until}${source(info)}`+ const caption = `${t("cert.until", { date: until })}${source(info)}`if (days < CERT_EXPIRY_WARNING_DAYS) {- const word = `Expires in ${days} ${days === 1 ? "day" : "days"}`+ const word = t("cert.expiresIn", { count: days, n: days })return { state: "expiring", days, word, caption, rowSub: word }}- return { state: "valid", days, word: "Valid", caption, rowSub: `Valid until ${until}` }+ return { state: "valid", days, word: t("cert.valid"), caption, rowSub: t("cert.validUntil", { date: until }) }}