Skip to content

[Intl/MessageFormatter] Add support for quoting with apostrophes - #723

Merged
nicolas-grekas merged 1 commit into
1.xfrom
intl-messageformatter-apostrophes
Oct 28, 2026
Merged

nicolas-grekas merged 1 commit into
1.xfrom
intl-messageformatter-apostrophes

Conversation

@nicolas-grekas

Copy link
Copy Markdown
Member
Q A
Branch? 1.x
Bug fix? yes
New feature? no
Deprecations? no
Issues -
License MIT

The polyfill ignored the apostrophe quoting of ICU, so messages rendered differently without the intl extension. It''s stayed It''s, '{name}' was replaced by the value, and '#' was replaced by the number in plural messages.

This PR implements the default "double optional" mode of intl. '' is an apostrophe. A single ' starts quoted text only before { or }, and before # in plural and selectordinal messages.

The new tokenizer also fixes #{{{{{}}}}{, which made the constructor loop until it ran out of memory. And like intl, it reads an unmatched } as literal text.

I compared the polyfill with intl on about 900k random patterns that intl accepts, using the features the polyfill supports. The only remaining differences come from a selector used twice in the same argument. The polyfill picks the last one, intl picks the first one.

Spotted while reviewing symfony/symfony#67555.

@stof

stof commented Oct 27, 2026

Copy link
Copy Markdown
Member

The only remaining differences come from a selector used twice in the same argument. The polyfill picks the last one, intl picks the first one.

Will you send another PR to fix this ?

@nicolas-grekas

Copy link
Copy Markdown
Member Author

I should be able to :)

nicolas-grekas added a commit that referenced this pull request Oct 28, 2026
… (nicolas-grekas)

This PR was merged into the 1.x branch.

Discussion
----------

[Intl/Icu] Sync currencies metadata with symfony/intl data

| Q             | A
| ------------- | ---
| Branch?       | 1.x
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

symfony/intl moved to ICU 79.1 in symfony/symfony#67509, which removed CNX and changed the fraction digits of MRU and PKR. `CurrenciesTest` compares this file with that data, so every new build on 1.x fails since then (see #723).

Commits
-------

2fe44d0 [Intl/Icu] Sync currencies metadata with symfony/intl data
@nicolas-grekas
nicolas-grekas force-pushed the intl-messageformatter-apostrophes branch from c3c1919 to 8c23dec Compare October 28, 2026 09:16
@nicolas-grekas
nicolas-grekas merged commit bf7440b into 1.x Oct 28, 2026
40 checks passed
@nicolas-grekas
nicolas-grekas deleted the intl-messageformatter-apostrophes branch October 28, 2026 09:32
nicolas-grekas added a commit that referenced this pull request Oct 28, 2026
…ke intl (nicolas-grekas)

This PR was merged into the 1.x branch.

Discussion
----------

[Intl/MessageFormatter] Pick the first matching selector, like intl

| Q             | A
| ------------- | ---
| Branch?       | 1.x
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

Follow up to #723, as asked by `@stof`.

When a `select`, `plural` or `selectordinal` argument uses the same selector twice, the polyfill now picks the first matching one, like intl does. It used to pick the last one.

Commits
-------

b2188b9 [Intl/MessageFormatter] Pick the first matching selector, like intl
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