-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved support for loading pages with non-existent locales
- Loading branch information
1 parent
9e64e14
commit ce86604
Showing
6 changed files
with
52 additions
and
20 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,15 +1,34 @@ | ||
// | ||
// Fichier de configuration de la bibliothèque « next-intl ». | ||
// Options de configuration de Next Intl. | ||
// Source : https://next-intl-docs.vercel.app/docs/getting-started/app-router-server-components | ||
// | ||
import deepmerge from "deepmerge"; | ||
import { notFound } from "next/navigation"; | ||
import { getRequestConfig } from "next-intl/server"; | ||
import type { AbstractIntlMessages } from "next-intl"; | ||
|
||
export default getRequestConfig( async ( { locale } ) => ( { | ||
timeZone: process.env.NEXT_PUBLIC_TIMEZONE, | ||
messages: deepmerge( | ||
( await import( "../public/locales/en.json" ) ).default, | ||
( await import( `../public/locales/${ locale }.json` ) ).default | ||
) as unknown as AbstractIntlMessages | ||
} ) ); | ||
export function getLanguages() | ||
{ | ||
// Liste des langues disponibles. | ||
return [ "en", "fr" ]; | ||
} | ||
|
||
export default getRequestConfig( async ( { locale } ) => | ||
{ | ||
// Vérification de la langue demandée par l'utilisateur. | ||
if ( !getLanguages().includes( locale ) ) | ||
{ | ||
notFound(); | ||
} | ||
|
||
// Récupération des traductions dans le système de fichiers. | ||
// Note : les traductions manquantes sont fusionnées avec celles de | ||
// la langue par défaut. | ||
return { | ||
timeZone: process.env.NEXT_PUBLIC_TIMEZONE, | ||
messages: deepmerge( | ||
( await import( "../public/locales/en.json" ) ).default, | ||
( await import( `../public/locales/${ locale }.json` ) ).default | ||
) as unknown as AbstractIntlMessages | ||
}; | ||
} ); |
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