From b1c7bd0a331569fba972367241bd5b43f613c7f6 Mon Sep 17 00:00:00 2001 From: Maurice Date: Sun, 29 Nov 2026 18:29:37 +0100 Subject: [PATCH] fix(ci): the file import's words resolve through t, the unused key count drops The KML skip reasons and the file errors were looked up from plain maps, which lint:i18n-keys cannot follow, so the new map keys counted as unused. Both are switches over t() now; the older file error keys are reached as well, so collection.ts holds 29 unused keys instead of 35. --- client/scripts/i18n-unused-baseline.json | 2 +- .../Collections/ImportCollectionModal.tsx | 26 ++++++++++++------- .../Collections/MapImportPreview.tsx | 18 ++++++++----- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/client/scripts/i18n-unused-baseline.json b/client/scripts/i18n-unused-baseline.json index 97acab438..9b6e0a024 100644 --- a/client/scripts/i18n-unused-baseline.json +++ b/client/scripts/i18n-unused-baseline.json @@ -5,7 +5,7 @@ "budget.ts": 35, "categories.ts": 1, "collab.ts": 9, - "collection.ts": 35, + "collection.ts": 29, "common.ts": 7, "dashboard.ts": 64, "dawarich.ts": 15, diff --git a/client/src/components/Collections/ImportCollectionModal.tsx b/client/src/components/Collections/ImportCollectionModal.tsx index 2fa14b82f..f88ecfa6e 100644 --- a/client/src/components/Collections/ImportCollectionModal.tsx +++ b/client/src/components/Collections/ImportCollectionModal.tsx @@ -35,14 +35,22 @@ interface ImportCollectionModalProps { t: TranslationFn } -/** Keyed by the error type, so a new way for a file to fail does not build without its words. */ -const ERROR_KEYS: Record = { - 'too-large': 'collections.file.errorTooLarge', - unreadable: 'collections.file.errorUnreadable', - 'not-a-collection': 'collections.file.errorNotACollection', - 'not-gpx': 'collections.file.errorNotGpx', - 'not-map': 'collections.file.errorNotMap', - 'too-many-places': 'collections.file.errorTooManyPlaces', +/** The words for each way a file can fail; a switch, so a new way does not build without its words. */ +function errorText(error: CollectionFileError, t: TranslationFn, count: number): string { + switch (error) { + case 'too-large': + return t('collections.file.errorTooLarge') + case 'unreadable': + return t('collections.file.errorUnreadable') + case 'not-a-collection': + return t('collections.file.errorNotACollection') + case 'not-gpx': + return t('collections.file.errorNotGpx') + case 'not-map': + return t('collections.file.errorNotMap') + case 'too-many-places': + return t('collections.file.errorTooManyPlaces', { count }) + } } /** @@ -270,7 +278,7 @@ export default function ImportCollectionModal({ const errorText = error === 'failed' ? (failedMessage ?? t('common.error')) - : error ? t(ERROR_KEYS[error], { count: MAX_COLLECTION_FILE_PLACES }) : null + : error ? errorText(error, t, MAX_COLLECTION_FILE_PLACES) : null // A GPX of nothing but a track would make an empty list, which is never what was meant. const nothingToImport = (!!leftovers || !!map) && !!file && (map ? picked.size === 0 : file.places.length === 0) diff --git a/client/src/components/Collections/MapImportPreview.tsx b/client/src/components/Collections/MapImportPreview.tsx index 56aa9dfa7..dcdcb2665 100644 --- a/client/src/components/Collections/MapImportPreview.tsx +++ b/client/src/components/Collections/MapImportPreview.tsx @@ -4,11 +4,17 @@ import React, { useState } from 'react'; import type { TranslationFn } from '../../types'; import { fs } from '../shared/DialogShell'; -const SKIP_KEYS: Record = { - line: 'collections.file.mapSkipLine', - no_point: 'collections.file.mapSkipNoPoint', - invalid: 'collections.file.mapSkipInvalid', -}; +/** Why a placemark was left out, in words; a switch, so a new reason does not build without them. */ +function skipText(reason: CollectionMapSkipReason, t: TranslationFn): string { + switch (reason) { + case 'line': + return t('collections.file.mapSkipLine'); + case 'no_point': + return t('collections.file.mapSkipNoPoint'); + case 'invalid': + return t('collections.file.mapSkipInvalid'); + } +} /** What a list file holds for a place; the file schema leaves its places to the server to check. */ type MapPlace = { name?: string; address?: string | null }; @@ -112,7 +118,7 @@ export default function MapImportPreview({
    {map.skipped.map((entry, i) => (
  • - {entry.name || t('collections.file.mapUnnamed')}: {t(SKIP_KEYS[entry.reason])} + {entry.name || t('collections.file.mapUnnamed')}: {skipText(entry.reason, t)}
  • ))}