refactor(person): one author-name fallback, localized
joinNameOrUnknown()/unknownPersonName() in personFormat.ts replace the three hand-rolled '[Unbekannt]' literals (geschichte/utils, GeschichtenCard, personOption) — the fallback is now the i18n key person_unknown (de/en/es), and formatAuthorDisplayName localizes the server-side literal on the pass-through path. Review round 3: Felix, Markus, Leonie (7). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { formatDate } from '$lib/shared/utils/date';
|
||||
import { m } from '$lib/paraglide/messages.js';
|
||||
|
||||
type Person = { firstName?: string | null; lastName: string; displayName: string };
|
||||
type DocForMeta = {
|
||||
@@ -17,6 +18,19 @@ function djb2(str: string): number {
|
||||
return Math.abs(hash);
|
||||
}
|
||||
|
||||
/** Localized fallback when a person has no name parts. */
|
||||
export function unknownPersonName(): string {
|
||||
return m.person_unknown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Single source for the join-names-or-fallback rule. Mirrors the server-side
|
||||
* fallback in GeschichteService.toView (which emits the literal '[Unbekannt]').
|
||||
*/
|
||||
export function joinNameOrUnknown(firstName?: string | null, lastName?: string | null): string {
|
||||
return [firstName, lastName].filter(Boolean).join(' ').trim() || unknownPersonName();
|
||||
}
|
||||
|
||||
export function getInitials(name: string): string {
|
||||
const words = name.trim().split(/\s+/).filter(Boolean);
|
||||
if (words.length === 0) return '';
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { components } from '$lib/generated/api';
|
||||
import { joinNameOrUnknown } from './personFormat';
|
||||
|
||||
type Person = components['schemas']['Person'];
|
||||
|
||||
@@ -21,6 +22,6 @@ export function toPersonOption(p: {
|
||||
}): PersonOption {
|
||||
return {
|
||||
id: p.id,
|
||||
displayName: [p.firstName, p.lastName].filter(Boolean).join(' ') || '[Unbekannt]'
|
||||
displayName: joinNameOrUnknown(p.firstName, p.lastName)
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user