Plugin, Types, and Message Loading
Pack:
next-intlParent skill: Next Intl Workflows and Tooling Source:next-intl/next-intl-workflows-and-tooling/references/plugin-types-and-loading.md
Read this when
Section titled “Read this when”- setting up
next-intlin a new app - moving
i18n/request.ts - adding strict typing for locales, messages, or formats
- deciding how messages should be loaded
Plugin baseline
Section titled “Plugin baseline”import createNextIntlPlugin from 'next-intl/plugin';
const withNextIntl = createNextIntlPlugin();export default withNextIntl({});- Keep the plugin enabled for App Router setups.
- By default, request config is discovered from
src/i18n/request.tsori18n/request.tswith standard JS or TS extensions. - Override the request-config path only when the default discovery path is not correct.
- Reach for plugin flags like
createMessagesDeclaration,extract, orprecompileonly when the workflow truly needs them.
TypeScript augmentation
Section titled “TypeScript augmentation”Use AppConfig augmentation for strict locale, message, and format typing.
import {routing} from '@/i18n/routing';import {formats} from '@/i18n/request';import en from '@/messages/en.json';
declare module 'next-intl' { interface AppConfig { Locale: (typeof routing.locales)[number]; Messages: typeof en; Formats: typeof formats; }}createMessagesDeclarationpairs with this setup and usually points at the same representative locale file used forMessages.- The generated declaration commonly uses a
*.d.json.tsfilename, so TypeScript needsallowArbitraryExtensions.
Message loading strategies
Section titled “Message loading strategies”- default: repo-local message files loaded from
getRequestConfig(...) - valid alternative: async loading from a CMS or backend when operationally justified
- keep the loading strategy explicit and centralized
Experimental loader options
Section titled “Experimental loader options”createMessagesDeclaration: generate strict message-key and argument types from a sample locale fileextract: enableuseExtractedandgetExtractedmessages: declare message path, locales, and file format for extraction and precompilationsrcPath: define where extracted messages are discovered, including multiple paths when neededprecompile: precompile imported catalogs for smaller bundles and faster runtime formatting
If precompile is enabled, avoid t.raw(...).
Custom formats
Section titled “Custom formats”- JSON is the default editing format.
- PO is often a better fit when translator comments, file references, and richer context matter.
- Custom codecs can be implemented with
defineCodec(...)fromnext-intl/extractor.
Missing-message policy
Section titled “Missing-message policy”- Use
onErrorfor reporting. - Use
getMessageFallbackfor a deliberate fallback policy. - Avoid silent failures that hide content drift.
Source map
Section titled “Source map”https://next-intl.dev/docs/usage/pluginhttps://next-intl.dev/docs/usage/configurationhttps://next-intl.dev/docs/workflows/typescripthttps://next-intl.dev/blog/next-intl-4-0