refactor(catalog): replace hardcoded validation messages with translatable strings

This commit is contained in:
2026-08-07 12:07:40 -03:00
parent 6318a99328
commit ed4502425a
3 changed files with 39 additions and 13 deletions

View File

@@ -50,7 +50,7 @@ class CatalogService
if ($hasEventDateVariants && ! in_array('event_date', $attributeCodes, true)) {
throw ValidationException::withMessages([
'attribute_codes' => [
'The event_date attribute is required for event date variants.',
__('api.catalog.event_date_attribute_required'),
],
]);
}
@@ -60,7 +60,7 @@ class CatalogService
if (array_diff($multiSelectAttributeCodes, $attributeCodes) !== []) {
throw ValidationException::withMessages([
'multi_select_attribute_codes' => [
'Multi-select attributes must also be present in attribute_codes.',
__('api.catalog.multi_select_attribute_not_on_item'),
],
]);
}
@@ -532,8 +532,8 @@ class CatalogService
throw ValidationException::withMessages([
"variants.{$index}.event_date_ids" => [
$eventDateItemAttribute->allow_multi_select
? 'At least one event date must be selected.'
: 'Exactly one event date must be selected.',
? __('api.catalog.event_date_selection_required')
: __('api.catalog.single_event_date_required'),
],
]);
}
@@ -546,7 +546,7 @@ class CatalogService
if ($validEventDateCount !== $eventDateIds->count()) {
throw ValidationException::withMessages([
"variants.{$index}.event_date_ids" => [
'Every event date must belong to the catalog item tenant.',
__('api.catalog.event_date_wrong_tenant'),
],
]);
}
@@ -595,7 +595,7 @@ class CatalogService
if (! in_array($eventProductType, EventProductType::values(), true)) {
throw ValidationException::withMessages([
'event_product_type' => ['The event product type is invalid.'],
'event_product_type' => [__('api.catalog.invalid_event_product_type')],
]);
}
}
@@ -637,7 +637,7 @@ class CatalogService
$key = implode('|', $combination);
if (isset($seen[$key])) {
throw ValidationException::withMessages([
"variants.{$index}" => ['The variant combination must be unique.'],
"variants.{$index}" => [__('api.catalog.duplicate_variant_combination')],
]);
}
@@ -657,15 +657,15 @@ class CatalogService
throw ValidationException::withMessages([
$validationKey => [
$itemAttribute->allow_multi_select
? 'At least one value must be selected.'
: 'Exactly one value must be selected.',
? __('api.catalog.multi_value_required')
: __('api.catalog.single_value_required'),
],
]);
}
if (collect($values)->contains(fn ($item): bool => ! is_string($item) || trim($item) === '')) {
throw ValidationException::withMessages([
$validationKey => ['Every selected value must be a non-empty string.'],
$validationKey => [__('api.catalog.selected_values_non_empty')],
]);
}
@@ -674,7 +674,7 @@ class CatalogService
if ($normalizedValues->unique()->count() !== count($values)) {
throw ValidationException::withMessages([
$validationKey => ['Selected values must be distinct.'],
$validationKey => [__('api.catalog.selected_values_distinct')],
]);
}
@@ -686,7 +686,7 @@ class CatalogService
$resolvedOptions = $normalizedValues->map(fn (string $normalizedValue) => $optionsByNormalizedValue->get($normalizedValue));
if ($resolvedOptions->contains(null)) {
throw ValidationException::withMessages([
$validationKey => ['One or more selected values are not valid attribute options.'],
$validationKey => [__('api.catalog.invalid_attribute_options')],
]);
}
@@ -696,7 +696,7 @@ class CatalogService
->unique();
if ($validityTimeIds->count() > 1) {
throw ValidationException::withMessages([
$validationKey => ['Selected values cannot have different validity windows.'],
$validationKey => [__('api.catalog.incompatible_validity_windows')],
]);
}

View File

@@ -92,6 +92,19 @@ return [
'variants_required' => 'An item with attribute_codes must have variants.',
'variants_forbidden' => 'An item without attribute_codes cannot have variants.',
'direct_inventory_forbidden' => 'An item with variants cannot have direct inventory.',
'event_date_attribute_required' => 'The event_date attribute is required for event date variants.',
'multi_select_attribute_not_on_item' => 'Multi-select attributes must also be present in attribute_codes.',
'event_date_selection_required' => 'At least one event date must be selected.',
'single_event_date_required' => 'Exactly one event date must be selected.',
'event_date_wrong_tenant' => 'Every event date must belong to the catalog item tenant.',
'invalid_event_product_type' => 'The event product type is invalid.',
'duplicate_variant_combination' => 'The variant combination must be unique.',
'multi_value_required' => 'At least one value must be selected.',
'single_value_required' => 'Exactly one value must be selected.',
'selected_values_non_empty' => 'Every selected value must be a non-empty string.',
'selected_values_distinct' => 'Selected values must be distinct.',
'invalid_attribute_options' => 'One or more selected values are not valid attribute options.',
'incompatible_validity_windows' => 'Selected values cannot have different validity windows.',
],
'menu' => [
'schema_required' => 'The schema is required for static menus.',

View File

@@ -92,6 +92,19 @@ return [
'variants_required' => 'Un ítem con attribute_codes debe tener variantes.',
'variants_forbidden' => 'Un ítem sin attribute_codes no puede tener variantes.',
'direct_inventory_forbidden' => 'Un ítem con variantes no puede tener inventario directo.',
'event_date_attribute_required' => 'El atributo event_date es obligatorio para las variantes con fecha de evento.',
'multi_select_attribute_not_on_item' => 'Los atributos multiselección también deben estar incluidos en attribute_codes.',
'event_date_selection_required' => 'Debe seleccionar al menos una fecha de evento.',
'single_event_date_required' => 'Debe seleccionar exactamente una fecha de evento.',
'event_date_wrong_tenant' => 'Todas las fechas del evento deben pertenecer al tenant del ítem de catálogo.',
'invalid_event_product_type' => 'El tipo de producto de evento no es válido.',
'duplicate_variant_combination' => 'La combinación de la variante debe ser única.',
'multi_value_required' => 'Debe seleccionar al menos un valor.',
'single_value_required' => 'Debe seleccionar exactamente un valor.',
'selected_values_non_empty' => 'Cada valor seleccionado debe ser un texto no vacío.',
'selected_values_distinct' => 'Los valores seleccionados no pueden repetirse.',
'invalid_attribute_options' => 'Uno o más valores seleccionados no son opciones válidas del atributo.',
'incompatible_validity_windows' => 'Los valores seleccionados no pueden tener ventanas de validez diferentes.',
],
'menu' => [
'schema_required' => 'El schema es obligatorio para los menús estáticos.',