{"record":{"id":"6bd391bfdd28039a","repo":"symfony/translation","slug":"the-s-method-cannot-be-called-as-the-wrapped-translator","errorCode":null,"errorMessage":"The \"%s()\" method cannot be called as the wrapped translator class \"%s\" does not implement the \"%s\".","messagePattern":"The \"(.+?)\\(\\)\" method cannot be called as the wrapped translator class \"(.+?)\" does not implement the \"(.+?)\"\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"PseudoLocalizationTranslator.php","lineNumber":122,"sourceCode":"            $this->addAccents($trans, $text);\n        }\n\n        $this->expand($trans, $visibleText);\n\n        $this->addBrackets($trans);\n\n        return $trans;\n    }\n\n    public function getLocale(): string\n    {\n        return $this->translator->getLocale();\n    }\n\n    public function getCatalogue(?string $locale = null): MessageCatalogueInterface\n    {\n        if (!$this->translator instanceof TranslatorBagInterface) {\n            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));\n        }\n\n        return $this->translator->getCatalogue($locale);\n    }\n\n    public function getCatalogues(): array\n    {\n        if (!$this->translator instanceof TranslatorBagInterface) {\n            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));\n        }\n\n        return $this->translator->getCatalogues();\n    }\n\n    private function getParts(string $originalTrans): array\n    {\n        if (!$this->parseHTML) {\n            return [[true, true, $originalTrans]];","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/symfony/translation/blob/ae9e8a51bc29780d63c7f9efd6005d7c875e100b/PseudoLocalizationTranslator.php#L104-L140","documentation":"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.","triggerScenarios":"Calling getCatalogue() on a PseudoLocalizationTranslator whose wrapped translator class lacks TranslatorBagInterface.","commonSituations":"Wrapping a custom or partial translator implementation instead of Symfony's Translator, or decorating only TranslatorInterface in a service alias.","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"],"exampleFix":"// before\n$pseudo = new PseudoLocalizationTranslator($someTranslatorWithoutBag);\n$pseudo->getCatalogue();\n// after\n$pseudo = new PseudoLocalizationTranslator(new \\Symfony\\Component\\Translation\\Translator('en'));\n$pseudo->getCatalogue();","handlingStrategy":"type-guard","validationCode":"if (!$inner instanceof TranslatorBagInterface) {\n    throw new \\LogicException('Wrapped translator must implement TranslatorBagInterface to access catalogues.');\n}","typeGuard":"$bag = $inner instanceof TranslatorBagInterface ? $inner : null;","tryCatchPattern":"try {\n    $catalogue = $pseudo->getCatalogue($locale);\n} catch (LogicException $e) {\n    $catalogue = $this->translatorBag->getCatalogue($locale);\n}","preventionTips":["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"],"tags":["php","symfony","translation","decorator"],"backgroundTag":"incompatible-source-type","analyzedSha":"ae9e8a51bc29780d63c7f9efd6005d7c875e100b","analyzedAt":"2026-09-15T22:29:15.305Z","contentChangedAt":"2026-09-15T22:29:15.305Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}