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')],
]);
}