Messages
Authoring translatable text, templates, plurals, ordinals, select, and descriptors
Almost everything you write is one of:
- a
say`...`tagged template - a
say.plural(...),say.ordinal(...), orsay.select(...)call - a
say.number(...),say.date(...), orsay.time(...)fragment inside one of those - a
<Say>...</Say>JSX element (with<Say.Plural>,<Say.Ordinal>,<Say.Select>,<Say.Number>,<Say.Date>,<Say.Time>)
These are macros: a SayKit plugin rewrites them during the build, and everything in them is extracted for translation.
Macros need a SayKit plugin (unplugin-saykit or babel-plugin-saykit). Without one they throw
at runtime.
Basic messages
say`Hello, world!`;
say`Hello, ${name}!`;
say`Your order of ${quantity} ${item} is ready!`;Extracted as ICU MessageFormat:
Hello, world!
Hello, {name}!
Your order of {quantity} {item} is ready!Each message gets a 6-character id hashed from its text and context, and its file and line are recorded for translators. The call site becomes say.call({ id, _name: name }): each value sits behind an underscore so it cannot collide with the descriptor's own keys.
SayKit transforms anything called say: the one from useSay(), interaction.say, store.say.
Placeholder names
A bare identifier names its placeholder. Anything else is numbered:
const name = user.profile.name ?? 'Anonymous';
say`Signed in as ${name}`; // → "Signed in as {name}"
say`Signed in as ${user.profile.name ?? 'Anonymous'}`; // → "Signed in as {0}"A number tells a translator nothing, so lift the value into a local, or name it with a single-key object:
say`Your total is ${{ cartTotal: getCartTotal() }}`; // → "Your total is {cartTotal}"Only the value survives the build. Name it after what it is to the sentence (cartTotal, dueDate), since that and the words around it are all a translator sees. The name must be a valid identifier. Naming works in selectors and in <Say> too:
say.plural({ items: cart.length }, { one: 'one item', other: 'several items' });
<Say>Signed in as {{ who: user.profile.name }}</Say>;Only an inline object with exactly one plain key is read as a name. A variable holding an object, or an object with two keys, a spread or a computed key, stays a value.
The same value written twice is one placeholder, evaluated once:
say`${name} invited ${name}`; // → "{name} invited {name}"
say`${guesses.length} x ${guesses.length}`; // → "{0} x {0}"Two different values under one name fail the build, such as ${{ n: items.length }} beside $ {{ n: users.length }}. Give each its own name.
Plurals
Branch on a count using CLDR plural categories:
say.plural(quantity, {
one: 'You have 1 item',
other: `You have ${quantity} items`,
});{quantity, plural,
one {You have 1 item}
other {You have # items}
}Interpolating the selector in a branch extracts as ICU's #, the number the message branched on. Anything else interpolated stays a named placeholder, and a # you type yourself is escaped as text.
All six categories work (zero, one, two, few, many, other), alongside exact numbers:
say.plural(count, {
0: 'No items',
1: 'One item',
other: `${count} items`,
});Write the categories your source language needs (English uses one and other); translators add the ones theirs needs.
Offset
offset is subtracted before # is written, which is how "You and 2 others" branches on three but shows two:
say.plural(likes, {
offset: 1,
0: 'Nobody has liked this yet',
one: `You and ${likes} other liked this`,
other: `You and ${likes} others liked this`,
});{likes, plural, offset:1
=0 {Nobody has liked this yet}
one {You and # other liked this}
other {You and # others liked this}
}It must be a whole number literal. It works on say.ordinal too; on say.select it is just a branch named offset.
Ordinals
"1st", "2nd", "3rd". Use categories rather than exact numbers: 1: matches only 1 and leaves "21th", while one covers 1, 21 and 31.
say.ordinal(position, {
one: `${position}st`,
two: `${position}nd`,
few: `${position}rd`,
other: `${position}th`,
});Select
Branch on a string:
say.select(gender, {
male: 'He is online',
female: 'She is online',
other: 'They are online',
});{gender, select,
male {He is online}
female {She is online}
other {They are online}
}A branch key is an ICU key, with no punctuation or whitespace, so 'sold-out' fails the build. Numeric keys match as strings.
Rename the discriminant, not just the branch: a soldOut branch never matches a value that is
still 'sold-out', and the message falls through to other.
Reserved characters
ICU reserves {, }, ', and # inside a plural. SayKit escapes them on the way into the catalogue, so the reader sees what you typed:
say`Wrap it in {braces}`; // → "Wrap it in '{'braces'}'"
say`It's here`; // → "It''s here"
say.plural(n, { other: `Issue #1, ${n} times` }); // → "Issue '#'1, # times"Numbers, dates, and times
say.number, say.date and say.time format a value for the active locale. Inside a message, the format lands in the catalogue, so a locale can move or restyle the value:
say`You have ${say.number(items.length)} items`;
say`Battery at ${say.number(level, { style: 'percent' })}`;
say`Published ${say.date(post.publishedAt, { style: 'long' })}`;
say`Total: ${say.number({ cartTotal: getTotal() }, { style: '::currency/EUR' })}`;You have {0, number} items
Battery at {0, number, percent}
Published {0, date, long}
Total: {cartTotal, number, ::currency/EUR}On their own they format for the view's locale and are not extracted, since there is nothing to translate:
say.number(1234.5); // → "1,234.5" in en, "1 234,5" in fr
say.date(post.publishedAt, { style: 'long' }); // → "13 September 2026"
say.time(opensAt, { style: 'short' }); // → "19:30"<td>
<Say.Number _={row.total} style="::currency/EUR" />
</td>style is optional. An unrecognised one fails the build.
| Macro | Styles |
|---|---|
say.number | integer, percent, a skeleton, or a literal pattern like #,##0.00 |
say.date | short, medium, long, full, or a skeleton |
say.time | short, medium, long, full, or a skeleton |
Skeletons
A skeleton, prefixed ::, names the parts of a format and leaves their arrangement to the locale:
say`Total ${say.number(total, { style: '::currency/EUR' })}`; // → "Total €1,234.50"
say`${say.number(views, { style: '::compact-short' })} views`; // → "12K views"
say`Since ${say.date(joined, { style: '::yMMMM' })}`; // → "Since January 2020"
say`Doors at ${say.time(opensAt, { style: '::Hm' })}`; // → "Doors at 19:30"A skeleton is resolved to Intl options at build time, so one Intl cannot show, such as ::qqqq (a quarter), fails the build with a file and line.
- There is no
currencystyle; use the skeleton::currency/EUR. ::percentdoes not scale (0.25→0.25%); thepercentstyle does.spellout, rule-basedordinalandchoiceare unsupported. A hand-written one writes the bare value.
Descriptors
An object passed to say before the template carries metadata for extraction.
Custom ids
Ids are content hashes by default. Give your own when translators work from readable keys, or an id must survive its text changing:
say({ id: 'greeting.hello' })`Hello!`;
say({ id: 'button.submit' })`Submit`;Context
Identical strings can mean different things. A context gives each its own id and catalogue entry, and shows translators which is which:
say({ context: 'direction' })`Right`;
say({ context: 'correctness' })`Right`;Translator comments
A // TRANSLATORS: comment above a message is attached to its catalogue entry:
// TRANSLATORS: This appears on the login button
say`Sign in`;#. This appears on the login button
msgid "Sign in"
msgstr "Sign in"The comment belongs to the statement the message is in, so it can sit above a declaration, a return or an object property. One above a function does not reach the messages inside it. In JSX, write it as a child:
<div>
{/* TRANSLATORS: Button text, keep under 20 characters */}
<Say>Continue</Say>
</div>Use them for anything a translator cannot infer: tone, length limits, what a placeholder holds.
JSX
<Say>Hello, {name}!</Say>
<Say>
{items} items · total <strong>{total}</strong>
</Say>Elements become numbered tags:
{items} items · total <0>{total}</0>Translators can move <0>...</0>, and SayKit puts the original element back at runtime. Name a tag with say-tag, see naming tags.
Every macro has a JSX counterpart. The selector is the _ prop, and branches, offset and style are props. A branch that shows the number must be a fragment:
<Say.Plural _={count} one={<>{count} item</>} other={<>{count} items</>} />
<Say.Ordinal _={position} _1="1st" _2="2nd" _3="3rd" other={<>{position}th</>} />
<Say.Select _={gender} male="He liked it" female="She liked it" other="They liked it" />
<Say>
You have <Say.Number _={items.length} /> items, last updated on{' '}
<Say.Date _={{ updatedAt }} style="long" />
</Say>Exact-number branches are _1, _2, since a prop cannot start with a digit. A message extracts as the text JSX renders: line breaks and indentation are dropped, and {' '} or {'—'} extract as the text they render.
See React integration for the full setup.
Best practices
Disambiguate reused words
When the same string means different things, add context so translators can pick the right wording.
say({ context: 'noun' })`Post`;
say({ context: 'verb' })`Post`;Leave notes for translators
Add comments when meaning, tone, or UI constraints would surprise a translator.
// TRANSLATORS: Button text, keep under 20 characters
say`Continue`;Prepare values first
Lift values into local variables so placeholders stay readable.
const name = user.profile.name ?? 'Anonymous';
say`Hello, ${name}`;Keep messages whole
Don't split messages across string concatenation, translators need full sentences.
say`Hello, ${name}`; // ✓
say`Hello, ` + name; // ✗Next
- Runtime: catalogues, views, and formatting
- Extraction: the CLI, watch mode, source-only writes
- React:
<Say>in detail