{"record":{"id":"b4f162710e65dbd8","repo":"symfony/translation","slug":"loading-translations-from-the-yaml-format-requires-the","errorCode":null,"errorMessage":"Loading translations from the YAML format requires the Symfony Yaml component.","messagePattern":"Loading translations from the YAML format requires the Symfony Yaml component\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"Loader/YamlFileLoader.php","lineNumber":33,"sourceCode":"use Symfony\\Component\\Translation\\Exception\\LogicException;\nuse Symfony\\Component\\Yaml\\Exception\\ParseException;\nuse Symfony\\Component\\Yaml\\Parser as YamlParser;\nuse Symfony\\Component\\Yaml\\Yaml;\n\n/**\n * YamlFileLoader loads translations from Yaml files.\n *\n * @author Fabien Potencier <fabien@symfony.com>\n */\nclass YamlFileLoader extends FileLoader\n{\n    private YamlParser $yamlParser;\n\n    protected function loadResource(string $resource): array\n    {\n        if (!isset($this->yamlParser)) {\n            if (!class_exists(YamlParser::class)) {\n                throw new LogicException('Loading translations from the YAML format requires the Symfony Yaml component.');\n            }\n\n            $this->yamlParser = new YamlParser();\n        }\n\n        try {\n            $messages = $this->yamlParser->parseFile($resource, Yaml::PARSE_CONSTANT);\n        } catch (ParseException $e) {\n            throw new InvalidResourceException(\\sprintf('The file \"%s\" does not contain valid YAML: ', $resource).$e->getMessage(), 0, $e);\n        }\n\n        if (null !== $messages && !\\is_array($messages)) {\n            throw new InvalidResourceException(\\sprintf('Unable to load file \"%s\".', $resource));\n        }\n\n        return $messages ?: [];\n    }\n}","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/symfony/translation/blob/ae9e8a51bc29780d63c7f9efd6005d7c875e100b/Loader/YamlFileLoader.php#L15-L51","documentation":"YamlFileLoader relies on symfony/yaml's YamlParser to read translation files. If the Yaml component is not installed, loadResource() throws this LogicException — an optional-dependency guard analogous to the XLIFF loader's Config check.","triggerScenarios":"Loading a .yaml/.yml translation file (via load() or a Translator using the YAML loader) while class_exists(YamlParser::class) fails because symfony/yaml is not installed.","commonSituations":"Projects installing only symfony/translation without symfony/yaml; production builds that prune dev/suggested dependencies; framework editions dropping Yaml by default.","solutions":["Run composer require symfony/yaml to install the component.","Alternatively switch to a format without the dependency (e.g. PHP array translation files).","Confirm vendor/symfony/yaml exists and the autoload includes it."],"exampleFix":"// before\n$loader->load('translations/messages.en.yaml', 'en'); // LogicException\n// after\n// composer require symfony/yaml\n$loader->load('translations/messages.en.yaml', 'en');","handlingStrategy":"try-catch","validationCode":"if (!class_exists(\\Symfony\\Component\\Translation\\Loader\\YamlFileLoader::class) && !class_exists(\\Symfony\\Component\\Yaml\\Parser::class)) {\n    throw new \\LogicException('Install symfony/yaml before loading YAML translations.');\n}","typeGuard":"function canLoadYaml(): bool { return class_exists(\\Symfony\\Component\\Yaml\\Parser::class); }","tryCatchPattern":"try {\n    $catalogue = $loader->load($resource, $locale);\n} catch (\\LogicException $e) {\n    if (str_contains($e->getMessage(), 'requires the Symfony Yaml component')) {\n        // composer require symfony/yaml or switch loader format\n    }\n    throw $e;\n}","preventionTips":["Require symfony/yaml in composer.json when using YAML translations.","Mirror production dependencies in CI (composer install --no-dev still needs it).","Or standardize on PHP array translation files to avoid the dependency."],"tags":["php","missing-dependency","yaml"],"backgroundTag":"missing-dependency","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"}