Apostrophes in ICU MessageFormat: why '{name}' prints literally
Your French build says Supprimer l'{item} ? instead of Supprimer l'image ?. Nothing is wrong with the value; the apostrophe is. In ICU MessageFormat the apostrophe is the quoting character, and one placed directly before a brace turns everything up to the next apostrophe into literal text, placeholder included.
Check your messages or translation files
The rule ICU follows
ICU4J and ICU4C use this rule by default (ICU calls it DOUBLE_OPTIONAL mode), and FormatJS (react-intl) follows it too:
- Two apostrophes
''always mean one literal apostrophe. - A single apostrophe directly before
{or}, or before#inside a plural option, starts quoted text. The quote runs to the next single apostrophe, or to the end of the message if there is none. - Any other single apostrophe, as in
I'morit's, is just an apostrophe.
That last rule is why most messages with apostrophes work, and why the bug only appears when an apostrophe happens to touch a placeholder. Elision in French (l', d', qu') and Italian (dell', un'), and English text that puts a value in quotes, are where it shows up.
| Message | Prints (item = "image") |
|---|---|
Supprimer l'{item} ? | Supprimer l{item} ? (the quote runs to the end) |
Supprimer l''{item} ? | Supprimer l'image ? |
Supprimer l’{item} ? | Supprimer l’image ? (typographic apostrophe) |
Rename '{item}' | Rename {item} |
Rename ''{item}'' | Rename 'image' |
Use '{' and '}' for braces | Use { and } for braces (quoting used on purpose) |
{n, plural, other {'#' is #}} with n = 3 | # is 3 |
Each row is pinned as a test in the checker's source, so the table says what the code does.
Three fixes
- Use the typographic apostrophe
’(U+2019). It is what French and Italian typography prefer anyway, and ICU never treats it as syntax. Many teams adopt it for all translations to make the problem impossible. - Double the ASCII apostrophe wherever it touches a brace:
l''{item}. Doubling every apostrophe in a message is also safe, since''always means one. - Check files before release. Translators working in a CAT tool rarely see the ICU syntax, so the bug comes back with each new string. The checker and its CLI flag any quote that swallows a placeholder, with the column.
Flutter: only with escaping turned on
Flutter's gen_l10n treats apostrophes as plain text unless use-escaping: true is set in l10n.yaml. With escaping off, l'{item} works and there is no way to print a literal brace; with it on, the rule above applies.
Java's MessageFormat is stricter
The JDK's own java.text.MessageFormat (not ICU4J's) treats every single apostrophe as a quote, so It's {0} already breaks there and every apostrophe must be doubled. If your messages go through the JDK class, double them all; the checker follows ICU's rule, not the JDK's.