{"record":{"id":"5cf5af69ded20495","repo":"symfony/routing","slug":"collection-s-with-locale-s-is-missing-a-corresponding-prefix","errorCode":null,"errorMessage":"Collection \"%s\" with locale \"%s\" is missing a corresponding prefix in its parent collection.","messagePattern":"Collection \"(.+?)\" with locale \"(.+?)\" is missing a corresponding prefix in its parent collection\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"Loader/Configurator/CollectionConfigurator.php","lineNumber":90,"sourceCode":"     * Sets the prefix to add to the path of all child routes.\n     *\n     * @param string|array $prefix the prefix, or the localized prefixes\n     *\n     * @return $this\n     */\n    final public function prefix(string|array $prefix, bool $trailingSlashOnRoot = true): static\n    {\n        $this->trailingSlashOnRoot = $trailingSlashOnRoot;\n\n        if (\\is_array($prefix)) {\n            if (null === $this->parentPrefixes) {\n                // no-op\n            } elseif ($missing = array_diff_key($this->parentPrefixes, $prefix)) {\n                throw new \\LogicException(\\sprintf('Collection \"%s\" is missing prefixes for locale(s) \"%s\".', $this->name, implode('\", \"', array_keys($missing))));\n            } else {\n                foreach ($prefix as $locale => $localePrefix) {\n                    if (!isset($this->parentPrefixes[$locale])) {\n                        throw new \\LogicException(\\sprintf('Collection \"%s\" with locale \"%s\" is missing a corresponding prefix in its parent collection.', $this->name, $locale));\n                    }\n\n                    $prefix[$locale] = $this->parentPrefixes[$locale].$localePrefix;\n                }\n            }\n            $this->prefixes = $prefix;\n            $this->route->setPath('/');\n        } else {\n            $this->prefixes = null;\n            $this->route->setPath($prefix);\n        }\n\n        return $this;\n    }\n\n    /**\n     * Sets the host to use for all child routes.\n     *","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/symfony/routing/blob/83fa223250b50f4f018c011e101c330e65ac63cc/Loader/Configurator/CollectionConfigurator.php#L72-L108","documentation":"Inverse of error 38: when a parent collection has locale prefixes, a child prefix array may not introduce locales the parent lacks. prefix() throws LogicException naming the collection, the offending locale, and the parent relationship.","triggerScenarios":"Child ->prefix(['en' => '/en', 'de' => '/de']) while the parent collection prefix only defines ['en' => '/en'] — 'de' has no parent prefix.","commonSituations":"Adding a new locale only to a sub-collection; inconsistent locale sets between parent and child collection prefixes in localized route trees.","solutions":["Add the missing locale to the parent collection's prefix array","Or drop the extra locale from the child prefix","Keep locale key sets synchronized between nested collections"],"exampleFix":"// before\n$root = $collection->collection('app')->prefix(['en' => '/en']);\n$root->prefix(['en' => '/en', 'de' => '/de']);\n// after\n$root->prefix(['en' => '/en', 'de' => '/de']); // parent now has de too\n$root->prefix(['en' => '/en', 'de' => '/de']);","handlingStrategy":"validation","validationCode":"$extra = array_diff_key($childPrefix, $parentPrefixes); if ($extra) { /* add locales to parent prefix first */ }","typeGuard":"function childLocalesSupported(array $parent, array $child): bool { return !array_diff_key($child, $parent); }","tryCatchPattern":"try { $routes = $loader->load($file); } catch (\\LogicException $e) { if (str_contains($e->getMessage(), 'missing a corresponding prefix')) { /* add locale to parent prefix */ } throw $e; }","preventionTips":["Add new locales to the root collection prefix before children","Share locale constants across parent/child prefix builders","CI route-loading smoke test to catch locale drift"],"tags":["routing","i18n","localized-routes"],"backgroundTag":"missing-required-config-field","analyzedSha":"83fa223250b50f4f018c011e101c330e65ac63cc","analyzedAt":"2026-09-14T03:19:46.280Z","contentChangedAt":"2026-09-14T03:19:46.280Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}