{"record":{"id":"6a67d386f16bee2f","repo":"symfony/translation","slug":"unable-to-format-message-error-s","errorCode":null,"errorMessage":"Unable to format message (error #%s): ","messagePattern":"Unable to format message \\(error #(.+?)\\): ","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"Formatter/IntlFormatter.php","lineNumber":52,"sourceCode":"            if (!$this->hasMessageFormatter ??= class_exists(\\MessageFormatter::class)) {\n                throw new LogicException('Cannot parse message translation: please install the \"intl\" PHP extension or the \"symfony/polyfill-intl-messageformatter\" package.');\n            }\n            try {\n                $this->cache[$locale][$message] = $formatter = new \\MessageFormatter($locale, $message);\n            } catch (\\IntlException $e) {\n                throw new InvalidArgumentException(\\sprintf('Invalid message format (error #%d): ', intl_get_error_code()).intl_get_error_message(), 0, $e);\n            }\n        }\n\n        foreach ($parameters as $key => $value) {\n            if (\\in_array($key[0] ?? null, ['%', '{'], true)) {\n                unset($parameters[$key]);\n                $parameters[trim($key, '%{ }')] = $value;\n            }\n        }\n\n        if (false === $message = $formatter->format($parameters)) {\n            throw new InvalidArgumentException(\\sprintf('Unable to format message (error #%s): ', $formatter->getErrorCode()).$formatter->getErrorMessage());\n        }\n\n        return $message;\n    }\n}\n","sourceCodeStart":34,"sourceCodeEnd":58,"githubUrl":"https://github.com/symfony/translation/blob/ae9e8a51bc29780d63c7f9efd6005d7c875e100b/Formatter/IntlFormatter.php#L34-L58","documentation":"Thrown by IntlFormatter::formatIntl when MessageFormatter::format() returns false, meaning ICU failed to format an otherwise-parsable pattern — typically because arguments passed don't match the pattern's expected types, or the locale/args combination is invalid at format time.","triggerScenarios":"Calling trans() with parameters whose types don't satisfy the ICU pattern (e.g. passing a string where a number is required for a plural/select argument), or missing required arguments.","commonSituations":"Passing string numbers ('5') into {count, number}-style args; forgetting to pass the plural/select argument; parameters keyed with '%key'/'{key}' conventions being stripped and remapped leaving required args absent.","solutions":["Read the appended $formatter->getErrorMessage() to see the specific ICU failure","Pass correctly-typed arguments (int/float for number and plural args) to trans()","Ensure every argument referenced by the ICU pattern is supplied","Normalize your parameter keys (strip % / {} wrappers) before calling trans()"],"exampleFix":"// before\n$translator->trans('apples.count', ['%count%' => '5'], 'messages', 'en');\n// after\n$translator->trans('apples.count', ['%count%' => 5], 'messages', 'en');","handlingStrategy":"try-catch","validationCode":"foreach ($patternArgs as $arg) { if (!array_key_exists($arg, $params)) { throw new \\InvalidArgumentException(\"Missing ICU argument: {$arg}\"); } }","typeGuard":"function areIcuArgsWellTyped(array $params): bool { foreach ($params as $k => $v) { if (is_string($v) && is_numeric($v)) { return false; } } return true; }","tryCatchPattern":"try { $msg = $translator->trans($id, $params, $domain, $locale); } catch (InvalidArgumentException $e) { $this->logger->error('ICU format failure for '.$id.': '.$e->getMessage()); $msg = $this->simpleFallback($id, $params); }","preventionTips":["Pass native int/float values for numeric ICU arguments, never numeric strings","Always supply every argument referenced by plural/select patterns","Document the parameter contract per translation key so callers pass correct types"],"tags":["symfony","translation","icu","message-format","argument-type"],"backgroundTag":"invalid-argument-value","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"}