symfony/translation · error · LogicException

Dumping translations in the YAML format requires the…

Error message

Dumping translations in the YAML format requires the Symfony Yaml component.

What it means

Thrown by YamlFileDumper::formatCatalogue when the symfony/yaml component (Yaml class) is not installed. The dumper cannot serialize translations to YAML without it, since symfony/translation does not hard-require symfony/yaml.

Solutions

  1. Install the Yaml component: `composer require symfony/yaml`
  2. Or dump to a different format (e.g. xliff, php) that does not need YAML
  3. If in a custom build, ensure symfony/yaml is a direct require, not assumed transitively

Example fix

// before
composer remove symfony/yaml
// after
composer require symfony/yaml
Defensive patterns

Strategy: fallback

Validate before calling

if (!class_exists(\Symfony\Component\Yaml\Yaml::class)) { // choose a non-YAML format or require symfony/yaml }

Type guard

function yamlDumperAvailable(): bool { return class_exists(\Symfony\Component\Yaml\Yaml::class); }

Try / catch

try { $dumper->dump($catalogue, $options); } catch (LogicException $e) { if (str_contains($e->getMessage(), 'Yaml component')) { $xliffDumper->dump($catalogue, $options); } else { throw $e; } }

Prevention

When it happens

Trigger: Running translation dump commands or programmatic dumping to YAML format in a project where symfony/yaml was never installed or was removed from composer dependencies.

Common situations: Slim composer installs (framework without yaml — unusual in full Symfony, common in minimal setups using only symfony/translation); CI images with stripped dependencies; after removing symfony/yaml in a dependency cleanup.

Understand the failure class

Background: "X is not installed. Please install it with pip install Y": missing optional dependency errors — ImportError/ValueError raised when a library's optional extra was never installed — this error's family across 22 libraries.

Related errors


AI-assisted analysis of symfony/translation@ae9e8a51bc (2026-09-15). Data as JSON: /api/errors/ab637d129863898a. Report an issue: GitHub.

Appendix: source

Thrown at Dumper/YamlFileDumper.php:34

use Symfony\Component\Translation\Util\ArrayConverter;
use Symfony\Component\Yaml\Yaml;

/**
 * YamlFileDumper generates yaml files from a message catalogue.
 *
 * @author Michel Salib <michelsalib@hotmail.com>
 */
class YamlFileDumper extends FileDumper
{
    public function __construct(
        private string $extension = 'yml',
    ) {
    }

    public function formatCatalogue(MessageCatalogue $messages, string $domain, array $options = []): string
    {
        if (!class_exists(Yaml::class)) {
            throw new LogicException('Dumping translations in the YAML format requires the Symfony Yaml component.');
        }

        $data = $messages->all($domain);

        if (isset($options['as_tree']) && $options['as_tree']) {
            $data = ArrayConverter::expandToTree($data);
        }

        if (isset($options['inline']) && ($inline = (int) $options['inline']) > 0) {
            return Yaml::dump($data, $inline);
        }

        return Yaml::dump($data);
    }

    protected function getExtension(): string
    {
        return $this->extension;

View on GitHub (pinned to ae9e8a51bc)