Skip to content

4.3.3 - Error messages are ICU MessageFormat patterns (back-port of #1437) - #1687

Merged
ctrlaltca merged 2 commits into
pradosoft:prado-4.3from
belisoful:4.3-icu-messages
Nov 29, 2026
Merged

ctrlaltca merged 2 commits into
pradosoft:prado-4.3from
belisoful:4.3-icu-messages

Conversation

@belisoful

Copy link
Copy Markdown
Member

Back-port of #1437 to 4.3.3, for the bridge to 4.4: error message file entries are ICU MessageFormat patterns, so a message can use plural, select, and number arguments.

cache_items_expired = {0, plural, one{# item} other{# items}} expired in ''{1}''.

TException

  • formatErrorMessage() formats a message defined in a file with \MessageFormatter in the language of the file (getMessageFileLanguage(): the -xx suffix, else en). A code defined in no file, or a pattern ICU cannot parse, still has {0}, {1}, ... replaced. These methods and findErrorMessageFile() match 4.4's.
  • 4.3's file order is unchanged: the files of addMessageFile(), then the framework file of the client language (messages-xx.txt or messages.txt), which has the highest precedence. 4.4's English-only master and the visitor messages of THttpException are not part of this PR.
  • Backward compatibility for a point release: a pattern that quotes a placeholder in single apostrophes, '{0}', the form every message file used before, keeps plain replacement (isPlainMessagePattern()), so an application's or an extension's message file renders as before. 4.4 renders that form as the literal {0}; UPGRADE.md says to double the apostrophes before 4.4.

Message files

  • messages.txt, messages-fr/id/zh.txt, and the ActiveRecord and SqlMap messages.txt are converted to ICU quoting with Error messages are ICU MessageFormat patterns #1437's rules ('{0}' → ''{0}'', literal braces quoted). Every converted entry renders under ICU exactly as the original did under plain replacement. The 490 entries shared with master's converted messages.txt match it.
  • Two ActiveRecord messages with unbalanced quotes take the corrected text from pradosoft/prado-activerecord.

TSqlMapException

  • Takes the constructor of pradosoft/prado-sqlmap: an optional integer error code first, a trailing Throwable as the previous exception, and SimpleXMLElement arguments expanded. It formats through TException, so its messages are ICU too. getErrorCode() returns the message code; it returned the message text.

Tests and docs

  • New TExceptionMessageFilesTest: lookup order, ICU formatting, file language, the plain-pattern fallback, the Data exceptions, and a lint that every entry of the six framework message files parses as ICU and renders each of its arguments.
  • UPGRADE.md, HISTORY.md, and the agents/ docs are updated.

Checked: php-cs-fixer, PHPStan, and the unit suite pass (8626 tests). The message files of the DB extensions (Doctrine, Propel, MongoDB, MySQLi, MSSQL, GraphQL) and prado-rpc parse as ICU, and prado-rpc's tests pass on this branch.

@ctrlaltca
ctrlaltca merged commit d264c87 into pradosoft:prado-4.3 Nov 29, 2026
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants