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
- Check the option key spelling against Translator::options defaults (cache_dir, debug, resource_files, scanned_directories, cache_vary)
- Remove the unsupported option if it is not needed
- If configuring via framework.yaml, validate translation config keys against your Symfony version's reference
- 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
- Copy option keys directly from the Translator class defaults, never retype them
- Use named constants or a config factory that validates keys against a whitelist
- Grep config for snake_case/camelCase mixing when upgrading Symfony
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
- The file dumper needs a path option.
- Unable to create directory
- No support implemented for dumping XLIFF version
- Dumping translations in the YAML format requires the…
- The " " file does not exist.
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)