symfony/translation · error · LogicException
The " ()" method cannot be called as the wrapped translator…
Error message
The "%s()" method cannot be called as the wrapped translator class "%s" does not implement the "%s".
What it means
Thrown by PseudoLocalizationTranslator::getCatalogue() as a LogicException when the decorated translator does not implement TranslatorBagInterface. PseudoLocalizationTranslator is a decorator that only supports locale translation; catalogue access requires the wrapped object to expose the catalogue bag API.
Solutions
- Ensure the wrapped translator implements TranslatorBagInterface (use Symfony\Component\Translation\Translator)
- Access the catalogue from the underlying bag service instead of the decorator
- If you only need pseudo-localized messages, use trans()/getLocale() instead of catalogue methods
Example fix
// before
$pseudo = new PseudoLocalizationTranslator($someTranslatorWithoutBag);
$pseudo->getCatalogue();
// after
$pseudo = new PseudoLocalizationTranslator(new \Symfony\Component\Translation\Translator('en'));
$pseudo->getCatalogue(); Defensive patterns
Strategy: type-guard
Validate before calling
if (!$inner instanceof TranslatorBagInterface) {
throw new \LogicException('Wrapped translator must implement TranslatorBagInterface to access catalogues.');
} Type guard
$bag = $inner instanceof TranslatorBagInterface ? $inner : null;
Try / catch
try {
$catalogue = $pseudo->getCatalogue($locale);
} catch (LogicException $e) {
$catalogue = $this->translatorBag->getCatalogue($locale);
} Prevention
- Always wrap Symfony\Component\Translation\Translator (it implements the bag interface)
- Do not use pseudo-localization decorators around minimal test doubles in production code
- Read the decorator's docblock: catalogue methods require TranslatorBagInterface
When it happens
Trigger: Calling getCatalogue() on a PseudoLocalizationTranslator whose wrapped translator class lacks TranslatorBagInterface.
Common situations: Wrapping a custom or partial translator implementation instead of Symfony's Translator, or decorating only TranslatorInterface in a service alias.
Understand the failure class
Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.
Related errors
- The scheme "null" is not supported by this provider.
- Provider " " not found. Available: " ".
- The scheme is not supported by any provider.
- No loader is registered for the
- No loader is registered for the
AI-assisted analysis of symfony/translation@ae9e8a51bc (2026-09-15).
Data as JSON: /api/errors/6bd391bfdd28039a.
Report an issue: GitHub.
Appendix: source
Thrown at PseudoLocalizationTranslator.php:122
$this->addAccents($trans, $text);
}
$this->expand($trans, $visibleText);
$this->addBrackets($trans);
return $trans;
}
public function getLocale(): string
{
return $this->translator->getLocale();
}
public function getCatalogue(?string $locale = null): MessageCatalogueInterface
{
if (!$this->translator instanceof TranslatorBagInterface) {
throw new LogicException(\sprintf('The "%s()" method cannot be called as the wrapped translator class "%s" does not implement the "%s".', __METHOD__, $this->translator::class, TranslatorBagInterface::class));
}
return $this->translator->getCatalogue($locale);
}
public function getCatalogues(): array
{
if (!$this->translator instanceof TranslatorBagInterface) {
throw new LogicException(\sprintf('The "%s()" method cannot be called as the wrapped translator class "%s" does not implement the "%s".', __METHOD__, $this->translator::class, TranslatorBagInterface::class));
}
return $this->translator->getCatalogues();
}
private function getParts(string $originalTrans): array
{
if (!$this->parseHTML) {
return [[true, true, $originalTrans]];View on GitHub (pinned to ae9e8a51bc)