Formatting, Validation, and Types
Pack:
next-intlParent skill: Next Intl Messages and Formatting Source:next-intl/next-intl-messages-and-formatting/references/formatting-validation-and-types.md
Read this when
Section titled “Read this when”- formatting numbers, dates, ranges, lists, or relative time
- defining reusable named formats
- adding typed message arguments or validating locale catalogs
- evaluating
useExtracted
Formatter surface
Section titled “Formatter surface”Use useFormatter() for values that are not naturally embedded in a sentence.
format.dateTime(...)format.dateTimeRange(...)format.relativeTime(...)format.number(...)format.list(...)
Shared formats
Section titled “Shared formats”- Define named formats in request config or
NextIntlClientProvider. - Reuse the same named formats in formatter calls and ICU messages.
- Centralize
timeZoneandnowwhen formatting must be deterministic across server and client. - Keep formatter names stable because they become part of the typed contract when
Formatsis augmented.
Typed arguments
Section titled “Typed arguments”- Prefer TypeScript augmentation plus
createMessagesDeclarationfor strict message-key and ICU-argument typing. - Typed ICU args are especially valuable for
t.rich(...)callbacks and formatter names. - If the project uses
useExtracted, prefer that workflow’s built-in typing and avoid duplicating a messages declaration pipeline.
Validation workflow
Section titled “Validation workflow”- Use
@lingual/i18n-checkto catch missing translations and inconsistent ICU arguments. - Add
--unusedwhen you want unused-message detection too. - Treat validation failures as content-contract failures, not translator-only issues.
useExtracted
Section titled “useExtracted”useExtractedcan extract inline strings into catalogs duringnext devandnext build.getExtracted()is the async counterpart for Server Components and similar server-only surfaces.- Treat it as experimental.
- Avoid teaching it as the only workflow for a project.
- Prefer PO or similarly metadata-rich formats if translator context matters.
Source map
Section titled “Source map”https://next-intl.dev/docs/usage/dates-timeshttps://next-intl.dev/docs/usage/listshttps://next-intl.dev/docs/usage/configurationhttps://next-intl.dev/docs/usage/pluginhttps://next-intl.dev/docs/usage/extractionhttps://next-intl.dev/docs/workflows/messageshttps://next-intl.dev/blog/next-intl-4-0