-
-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Sync improvements from RSC branch to main (#238)
Syncs various improvements from #149 to the main branch. **Features** - Add domain-based routing for middleware - Add `localePrefix` option for middleware - Add `localeDetection: false` flag for middleware - Set alternate links in middleware (and add opt-out via `alternateLinks: false`) - `NextIntlClientProvider` now accepts `now` as an ISO 8601 date string additionally **Bugfixes** - Handle locale subtags correctly when negotiating a locale in the middleware (e.g. `de-DE` → `de` when only `de` is configured) **Deprecations** - Deprecate `import {createIntlMiddleware} from 'next-intl/server'` in favor of `import createMiddleware from 'next-intl/middleware'` - Deprecate `import {NextIntlClientProvider} from 'next-intl/client'` in favour of `import {NextIntlClientProvider} from 'next-intl'`. As part of this, add a matcher (see the updated docs). **Docs** - Add docs for new features - Middleware should only be applied for localized pages **Internal changes** - Clean up examples - Use latest metadata API from Next.js - Upgrade Next.js - Add sitemap for website - Add docs for new features Closes #237
- Loading branch information
Showing
63 changed files
with
1,910 additions
and
567 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
// Declaring this interface provides type safety for message keys | ||
// Use type safe message keys with `next-intl` | ||
type Messages = typeof import('./messages/en.json'); | ||
declare interface IntlMessages extends Messages {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Use type safe message keys with `next-intl` | ||
type Messages = typeof import('./messages/en.json'); | ||
declare interface IntlMessages extends Messages {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
import {createIntlMiddleware} from 'next-intl/server'; | ||
import createMiddleware from 'next-intl/middleware'; | ||
|
||
export default createIntlMiddleware({ | ||
export default createMiddleware({ | ||
locales: ['en', 'de'], | ||
defaultLocale: 'en' | ||
}); | ||
|
||
export const config = { | ||
// Skip all paths that should not be internationalized | ||
matcher: ['/((?!api|_next|.*\\..*).*)'] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Use type safe message keys with `next-intl` | ||
type Messages = typeof import('./messages/en.json'); | ||
declare interface IntlMessages extends Messages {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
require('eslint-config-molindo/setupPlugins'); | ||
|
||
module.exports = { | ||
extends: ['molindo/typescript', 'molindo/react'] | ||
extends: ['molindo/typescript', 'molindo/react', 'molindo/jest'], | ||
plugins: ['deprecation'], | ||
overrides: [ | ||
{ | ||
files: ['test/**/*.tsx'], | ||
rules: { | ||
'deprecation/deprecation': 'error' | ||
} | ||
} | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {default} from './dist/src/middleware'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,18 @@ | ||
'use client'; | ||
|
||
import {useRouter} from 'next/router'; | ||
import React, {ComponentProps} from 'react'; | ||
import {IntlProvider} from 'use-intl'; | ||
|
||
type Props = Omit<ComponentProps<typeof IntlProvider>, 'locale'> & { | ||
locale?: string; | ||
}; | ||
|
||
export default function NextIntlProvider({locale, ...rest}: Props) { | ||
let router; | ||
try { | ||
// Reading from context is practically ok to do conditionally | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
router = useRouter(); | ||
} catch (error) { | ||
// Calling `useRouter` is not supported in the app folder | ||
} | ||
import NextIntlClientProvider_ from '../shared/NextIntlClientProvider'; | ||
|
||
// The router can be undefined if used in a context outside | ||
// of Next.js (e.g. unit tests, Storybook, ...) | ||
if (!locale && router) { | ||
locale = router.locale; | ||
} | ||
let hasWarned = false; | ||
/** @deprecated Should be imported from `next-intl`, not `next-intl/client`. */ | ||
export default function NextIntlClientProvider( | ||
props: ComponentProps<typeof NextIntlClientProvider_> | ||
) { | ||
if (!hasWarned) { | ||
hasWarned = true; | ||
console.warn(` | ||
Importing \`NextIntlClientProvider\` from \`next-intl/client\` is deprecated. Please update the import: | ||
if (!locale) { | ||
throw new Error( | ||
process.env.NODE_ENV !== 'production' | ||
? "Couldn't determine locale. Please pass an explicit `locale` prop the provider, or if you're using the `pages` folder, use internationalized routing (https://nextjs.org/docs/advanced-features/i18n-routing)." | ||
: undefined | ||
); | ||
import {NextIntlClientProvider} from 'next-intl'; | ||
`); | ||
} | ||
|
||
return <IntlProvider locale={locale} {...rest} />; | ||
return <NextIntlClientProvider_ {...props} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export * from 'use-intl'; | ||
|
||
export {default as NextIntlClientProvider} from './shared/NextIntlClientProvider'; | ||
|
||
// Legacy export for compatibility | ||
export {NextIntlClientProvider as NextIntlProvider} from './client'; | ||
export {default as NextIntlProvider} from './shared/NextIntlClientProvider'; |
Oops, something went wrong.
1d12ba2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
next-intl-docs – ./
next-intl-docs-git-main-amann.vercel.app
next-intl-docs-amann.vercel.app
next-intl-docs.vercel.app