symfony/translation · error · InvalidArgumentException

The Translator does not support the following options

Error message

The Translator does not support the following options: '%s'.

What it means

Thrown by Symfony Translation's Translator constructor when an option key in $options is not one of the supported option names ('cache_dir', 'debug', 'resource_files', 'scanned_directories', 'cache_vary', etc.). The constructor diffs the provided keys against known defaults and fails fast on unknown keys, usually to catch typos.

Solutions

  1. Check the option key spelling against Translator::options defaults (cache_dir, debug, resource_files, scanned_directories, cache_vary)
  2. Remove the unsupported option if it is not needed
  3. If configuring via framework.yaml, validate translation config keys against your Symfony version's reference
  4. Dump the constructor defaults (`new Translator(...)->getOptions()` pattern or read source) and align your keys

Example fix

// before
new Translator('en', null, $loaderIds, ['cacheDir' => '/tmp/cache']);
// after
new Translator('en', null, $loaderIds, ['cache_dir' => '/tmp/cache']);
Defensive patterns

Strategy: validation

Validate before calling

$supported = ['cache_dir','debug','resource_files','scanned_directories','cache_vary']; $bad = array_diff(array_keys($options), $supported); if ($bad) { throw new \InvalidArgumentException('Unsupported options: '.implode(',', $bad)); }

Type guard

function hasOnlySupportedOptions(array $options, array $supported): bool { return [] === array_diff(array_keys($options), $supported); }

Try / catch

try { $translator = new Translator(..., $options); } catch (InvalidArgumentException $e) { // log unsupported option names and fix config }

Prevention

When it happens

Trigger: Instantiating Translator::construct(..., $options) with any key not present in the class's default $options property, e.g. passing 'cacheDir' or 'resouce_files' instead of the exact snake_case names.

Common situations: Typo in option name when constructing the Translator manually or in TranslatorPass configuration; upgrading Symfony and an option was renamed; copying options from a different component that uses camelCase.

Related errors


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

Appendix: source

Thrown at DependencyInjection/Translator.php:82

     *   * debug:          Whether to enable debugging or not (false by default)
     *   * resource_files: List of translation resources available grouped by locale.
     *   * cache_vary:     An array of data that is serialized to generate the cached catalogue name.
     *
     * @param string[] $enabledLocales
     *
     * @throws InvalidArgumentException
     */
    public function __construct(
        protected ContainerInterface $container,
        MessageFormatterInterface $formatter,
        string $defaultLocale,
        protected array $loaderIds = [],
        array $options = [],
        private array $enabledLocales = [],
    ) {
        // check option names
        if ($diff = array_diff(array_keys($options), array_keys($this->options))) {
            throw new InvalidArgumentException(\sprintf('The Translator does not support the following options: \'%s\'.', implode('\', \'', $diff)));
        }

        $this->options = array_merge($this->options, $options);
        $this->resourceLocales = array_keys($this->options['resource_files']);
        $this->resourceFiles = $this->options['resource_files'];
        $this->scannedDirectories = $this->options['scanned_directories'];

        parent::__construct($defaultLocale, $formatter, $this->options['cache_dir'], $this->options['debug'], $this->options['cache_vary']);
    }

    public function warmUp(string $cacheDir, ?string $buildDir = null): array
    {
        // skip warmUp when translator doesn't use cache
        if (null === $this->options['cache_dir']) {
            return [];
        }

        $localesToWarmUp = $this->enabledLocales ?: array_merge($this->getFallbackLocales(), [$this->getLocale()], $this->resourceLocales);

View on GitHub (pinned to ae9e8a51bc)