{"record":{"id":"12455b0cf2084c01","repo":"symfony/translation","slug":"invalid-message-format-error-d","errorCode":null,"errorMessage":"Invalid message format (error #%d): ","messagePattern":"Invalid message format \\(error #(.+?)\\): ","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"Formatter/IntlFormatter.php","lineNumber":40,"sourceCode":"{\n    private bool $hasMessageFormatter;\n    private array $cache = [];\n\n    public function formatIntl(string $message, string $locale, array $parameters = []): string\n    {\n        // MessageFormatter constructor throws an exception if the message is empty\n        if ('' === $message) {\n            return '';\n        }\n\n        if (!$formatter = $this->cache[$locale][$message] ?? null) {\n            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":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/symfony/translation/blob/ae9e8a51bc29780d63c7f9efd6005d7c875e100b/Formatter/IntlFormatter.php#L22-L58","documentation":"Thrown by IntlFormatter::formatIntl when `new \\MessageFormatter($locale, $message)` throws IntlException, i.e. the ICU message pattern itself is syntactically invalid for the given locale. The error code/message from intl_get_error_* are embedded in the exception text.","triggerScenarios":"Formatting a translation message with malformed ICU syntax — unbalanced braces, invalid selector/argument syntax, bad plural rules — via $translator->trans() on an intl-formatted message.","commonSituations":"Hand-written translation files with ICU syntax mistakes (missing closing '}', stray quotes); translation files edited by non-developers or machine-generated; copy-pasting ICU patterns between formats.","solutions":["Read the appended intl error message to locate the syntax problem in the message string","Fix the ICU pattern (balance braces, correct `{arg, type, format}` syntax)","Validate messages with `msgfmt_format_message()` or an ICU message linter before deploying","Isolate the offending message by formatting it directly with new \\MessageFormatter($locale, $message)"],"exampleFix":"// before\n'items.count': 'You have {count, plural, one {# item} other' // missing closing brace\n// after\n'items.count': 'You have {count, plural, one {# item} other {# items}}'","handlingStrategy":"try-catch","validationCode":"$mf = msgfmt_create($locale, $message); if ($mf === false) { $err = intl_get_error_message(); // reject the message before runtime formatting }","typeGuard":"function isValidIcuPattern(string $locale, string $message): bool { return false !== msgfmt_format_message($locale, $message, []); }","tryCatchPattern":"try { $msg = $translator->trans($id, $params, $domain, $locale); } catch (InvalidArgumentException $e) { $this->logger->error('Bad ICU message '.$id.': '.$e->getMessage()); $msg = $id; }","preventionTips":["Validate ICU messages in CI with msgfmt or a lint script over translation files","Follow strict `{arg, type, format}` syntax; watch for unbalanced braces and quotes","Have translators test plural/select patterns with sample data before merging"],"tags":["symfony","translation","icu","message-format","invalid-pattern"],"backgroundTag":"invalid-argument-format","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"}