ICU MessageFormat examples

These ICU MessageFormat snippets show real-world plural rules, select branches, selectordinal rankings, number skeletons, and date/time fields you can drop into JavaScript Intl.MessageFormat, JSON translation files, or other i18n pipelines.

Paste any example into the ICU Playground or ICU syntax Validator to try different locales and variable values. Explore cardinal plural categories, browse plural rules by locale, generate target-language ICU templates, or convert syntax with the i18next / Android / ARB converters. About ICU Playground lists all tools.

ICU syntax examples by category

Cardinal plural

ICU MessageFormat plural syntax branches on a numeric count using locale-aware categories such as one, few, many, and other—essential for correct plural agreement in translated apps.

{count, plural,
    one{# item}
    other{# items}
}

Select (keyword choice)

The ICU select formatter picks a branch from a keyword value (for example gender, role, or UI variant) so your localized copy can agree grammatically without duplicating entire screens.

{gender, select,
    male{He}
    female{She}
    other{They}
} joined.

Nested plural and select

Combine select and plural in one ICU message when both a keyword and a count matter—common in sentences like “He has N apples” versus “They have N apples” across languages.

{gender, select,
    male{He has {count, plural,
            one{# apple}
            other{# apples}
        }}
    female{She has {count, plural,
            one{# apple}
            other{# apples}
        }}
    other{They have {count, plural,
            one{# apple}
            other{# apples}
        }}
}

Selectordinal (ordinals)

ICU selectordinal formats ranking and order (1st, 2nd, 3rd) using ordinal plural rules, which differ by locale—use it for leaderboards, steps, and list positions.

{position, selectordinal,
    one{You finished #st}
    two{You finished #nd}
    few{You finished #rd}
    other{You finished #th}
}

Number style (compact currency)

ICU number skeletons format values with compact notation and currency—for example short currency suitable for dashboards and mobile summaries.

You have {value, number, :: currency/compact-short}

Date and time patterns

ICU date and time formatters render locale-appropriate calendars and clocks from the same message template, keeping meeting and event copy consistent worldwide.

Meeting is on {start, date, medium} at {start, time, short}.