symfony/routing · error · LogicException
Collection " " is missing prefixes for locale(s) " ".
Error message
Collection "%s" is missing prefixes for locale(s) "%s".
What it means
CollectionConfigurator::prefix() supports locale-keyed prefixes. When a parent collection already has locale prefixes, a child prefix array must cover every parent locale. Missing locales are detected via array_diff_key and throw LogicException naming the collection and locales.
Solutions
- Add the missing locale keys to the child ->prefix([...]) call
- Remove the extra locale from the parent collection's prefix
- Make both parent and child prefix arrays use identical locale keys
Example fix
// before
$collection->collection('blog')->prefix(['en' => '/en']); // parent has en+nl
// after
$collection->collection('blog')->prefix(['en' => '/en', 'nl' => '/nl']); Defensive patterns
Strategy: validation
Validate before calling
$missing = array_diff_key($parentPrefixes, $childPrefix); if ($missing) { /* extend child prefix before calling ->prefix() */ } Type guard
function coversParentLocales(array $parent, array $child): bool { return !array_diff_key($parent, $child); } Try / catch
try { $routes = $loader->load($file); } catch (\LogicException $e) { if (str_contains($e->getMessage(), 'missing prefixes')) { /* sync collection prefixes */ } throw $e; } Prevention
- Define the app locale list once and build all prefix arrays from it
- Audit nested ->prefix() calls when adding locales
- CI route-loading smoke test
When it happens
Trigger: $collection->prefix(['en' => '/en']) (or ->prefix(...)) on a nested collection whose parent was prefixed with locales ['en','nl'], but the child prefix omits 'nl'.
Common situations: Localized route groups where a sub-collection adds a new parent locale without updating all children; partially translated route trees; copying a ->prefix() call between collections.
Understand the failure class
Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.
Related errors
- Route to " " is missing paths for locale(s) " ".
- Route to " " with locale " " is missing a corresponding…
- Collection " " with locale " " is missing a corresponding…
- Route " " is missing routes for locale(s) " ".
- Route " " with locale " " is missing a corresponding prefix…
AI-assisted analysis of symfony/routing@83fa223250 (2026-09-14).
Data as JSON: /api/errors/3820ed48681e0a59.
Report an issue: GitHub.
Appendix: source
Thrown at Loader/Configurator/CollectionConfigurator.php:86
return new self($this->collection, $this->name.$name, $this, $this->prefixes);
}
/**
* Sets the prefix to add to the path of all child routes.
*
* @param string|array $prefix the prefix, or the localized prefixes
*
* @return $this
*/
final public function prefix(string|array $prefix, bool $trailingSlashOnRoot = true): static
{
$this->trailingSlashOnRoot = $trailingSlashOnRoot;
if (\is_array($prefix)) {
if (null === $this->parentPrefixes) {
// no-op
} elseif ($missing = array_diff_key($this->parentPrefixes, $prefix)) {
throw new \LogicException(\sprintf('Collection "%s" is missing prefixes for locale(s) "%s".', $this->name, implode('", "', array_keys($missing))));
} else {
foreach ($prefix as $locale => $localePrefix) {
if (!isset($this->parentPrefixes[$locale])) {
throw new \LogicException(\sprintf('Collection "%s" with locale "%s" is missing a corresponding prefix in its parent collection.', $this->name, $locale));
}
$prefix[$locale] = $this->parentPrefixes[$locale].$localePrefix;
}
}
$this->prefixes = $prefix;
$this->route->setPath('/');
} else {
$this->prefixes = null;
$this->route->setPath($prefix);
}
return $this;
}View on GitHub (pinned to 83fa223250)