fix(persons): localize validation error messages via Paraglide i18n
validatePersonFields now returns a PersonValidationKey instead of a hardcoded German string. resolveValidationMessage() translates the key through Paraglide so English and Spanish locale users no longer see German error text. Adds validation_last_name_required and validation_first_name_required to all three message files. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
import { error, fail, redirect } from '@sveltejs/kit';
|
||||
import { createApiClient } from '$lib/api.server';
|
||||
import { getErrorMessage } from '$lib/errors';
|
||||
import { normalizePersonType, validatePersonFields } from '$lib/person-validation';
|
||||
import {
|
||||
normalizePersonType,
|
||||
validatePersonFields,
|
||||
resolveValidationMessage
|
||||
} from '$lib/person-validation';
|
||||
|
||||
export async function load({ params, fetch, locals }) {
|
||||
const canWrite =
|
||||
@@ -42,9 +46,9 @@ export const actions = {
|
||||
const birthYear = birthYearStr ? parseInt(birthYearStr, 10) : undefined;
|
||||
const deathYear = deathYearStr ? parseInt(deathYearStr, 10) : undefined;
|
||||
|
||||
const validationError = validatePersonFields(personType, firstName, lastName);
|
||||
if (validationError) {
|
||||
return fail(400, { updateError: validationError });
|
||||
const validationKey = validatePersonFields(personType, firstName, lastName);
|
||||
if (validationKey) {
|
||||
return fail(400, { updateError: resolveValidationMessage(validationKey) });
|
||||
}
|
||||
|
||||
const api = createApiClient(fetch);
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { error, fail, redirect } from '@sveltejs/kit';
|
||||
import { createApiClient } from '$lib/api.server';
|
||||
import { getErrorMessage } from '$lib/errors';
|
||||
import { normalizePersonType, validatePersonFields } from '$lib/person-validation';
|
||||
import {
|
||||
normalizePersonType,
|
||||
validatePersonFields,
|
||||
resolveValidationMessage
|
||||
} from '$lib/person-validation';
|
||||
|
||||
export async function load({ locals }: { locals: App.Locals }) {
|
||||
const canWrite =
|
||||
@@ -23,10 +27,10 @@ export const actions = {
|
||||
const deathYearStr = formData.get('deathYear')?.toString().trim();
|
||||
const notes = formData.get('notes')?.toString().trim() || undefined;
|
||||
|
||||
const validationError = validatePersonFields(personType, firstName, lastName);
|
||||
if (validationError) {
|
||||
const validationKey = validatePersonFields(personType, firstName, lastName);
|
||||
if (validationKey) {
|
||||
return fail(400, {
|
||||
error: validationError,
|
||||
error: resolveValidationMessage(validationKey),
|
||||
personType,
|
||||
title,
|
||||
firstName: firstName ?? '',
|
||||
|
||||
Reference in New Issue
Block a user