- Fixes bug that caused an unnecessary extra redirect due to trailing slash in pathname
- Add
cookieOptions
config option for setting customSet-Cookie
attributes
- Remove console warning in
localeDetector
when invalid accept-language header present
- Fixes bug where
noPrefix
did not uselocaleDetector
when no cookie present
- Update
next
dev dependency to 14.2.2
- Add config option
noPrefix
for hiding the locale prefix in the pathname. useCurrentLocale
now checks the document cookie for the current locale prior to checking the pathname.
- Change default of
serverSetCookie
to"always"
. - Add
"never"
option toserverSetCookie
. This is the same asundefined
in previous versions.
- Update dependencies
- Change to cookie redirect behavior: When visiting a pathname that includes a locale, the middleware will now redirect if the
localeCookie
is set. Previously the redirecting based on cookie only occured on pathnames without a locale, but we've decided this is inconsistent behavior. - Add
serverSetCookie
config option
Add forwarding of request headers in i18nRouter
Fixes RangeError thrown by @formatjs/intl-localematcher
when an invalid accept-language header is present on request
Update examples to v5 and update changelog
To encourage best practices, we have removed the 'rewrite'
routing strategy and require use of a dynamic segment.
If you are currently using routingStrategy: 'dynamicSegment'
, no changes are required aside from removing the routingStrategy
option from your config.
routingStrategy
config option removed- Dynamic segment for the path locale now required
- Removed
currentLocale
helper function. This function used a header set in the middleware to get the current locale, but this was undependable due to middleware response caching. Reading headers in server components also disables use of SSG. To get the current locale in server components, you can now just use the page params.
- Fix bug in
localeDetector
when no accept-language header present on request (https://stackoverflow.com/questions/76447732/nextjs-13-i18n-incorrect-locale-information-provided)
- Minor updates to README adding instructions for setup with i18next.
- Fix bug in which rewrites did not have an opening
/
, causing pathnames with more than 2 segments to return 404's
- Adds new option named
routingStrategy
that can be set to"rewrite"
(default) or"dynamicSegment"
.- The
"rewrite"
strategy is the same functionality as v3. - The
"dynamicSegment"
strategy allows for using the current locale as a dynamic segment, enabling usage ofgenerateStaticParams
for static generation of all languages at build time.
- The
i18nRewriter
has been removed as it is no longer needed. 🎉i18nRouter
no longer accepts an existing response as a third argument.
TypeScript optimization:
- Return
undefined
instead ofnull
inuseCurrentLocale
hook - Return
undefined
instead ofnull
incurrentLocale
helper
- Update: Adds optional third argument of type
NextResponse
toi18nRouter
to allow for developers to use a previously generated response (#8) - Fix: The original request's search parameters are now persisted when redirecting to another language (#13)
- Adds
basePath
config option to support using the Next configbasePath
- Adds the
currentLocale
helper function for retrieving the current language in Server Components - Adds the
useCurrentLocale
hook for retrieving the current language in Client Components
- Pathname language prefix for the default language no longer required
- Remove need for
[lang]
dynamic segment by introducing thei18nRewriter
getLocale
option replaced withlocaleDetector
- Cookie detection now independent of
localeDetector
detection - Add config option for
prefixDefault
i18nRouter
is no longer a default import
// v2.0.0
import i18nRouter from 'next-i18n-router';
// v3.0.0
import { i18nRouter } from 'next-i18n-router';
i18nRewriter
must be used to create language paths innext.config.js
getLocale
has been replaced withlocaleDetector
- To continue having the default language's pathname prefixed, the
prefixDefault
option should be set totrue
- Library rewritten in Typescript
- Typings for the
i18nRouter
config now available
- Fix bug causing the locale cookie to not be read
- Add
repository
topackage.json
- Minor README fixes
- Initial Release